gpt4 book ai didi

java - 当我尝试调用 org.apache.activemq.ActiveMQSession.createDurableConsumer 时,为什么会出现 java.lang.AbstractMethodError

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:03:54 27 4
gpt4 key购买 nike

出于某种原因,我无法创建持久消费者来从 activemq 摄取消息。我研究过herehere ,但使用最新版本(连同 Java 1.7)并没有解决问题。我一定是使用了错误的版本/某些东西的实现,但我一直无法根除它。这是代码:

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;
import org.apache.activemq.ActiveMQConnectionFactory;

ConnectionFactory cf = new ActiveMQConnectionFactory("bob", "bobsPword", "tcp://localhost:61616");
Connection connection = cf.createConnection();
connection.start();
Session session = connection.createSession(false, QueueSession.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic("TEST.QUEUE.FOO");
MessageConsumer consumer = session.createDurableConsumer(topic, "clientId");
Message message = consumer.receiveNoWait();
if (message instanceof TextMessage) {
System.out.println("message: " + ((TextMessage) message).getText());
}else{
System.out.println("unexpected message...");
}

错误:

Exception in thread "main" java.lang.AbstractMethodError: org.apache.activemq.ActiveMQSession.createDurableConsumer(Ljavax/jms/Topic;Ljava/lang/String;)Ljavax/jms/MessageConsumer;

我的依赖项:

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.jms</groupId>
<artifactId>javax.jms-api</artifactId>
<version>2.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.fusesource.stompjms</groupId>
<artifactId>stompjms-client</artifactId>
<version>1.19</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-client</artifactId>
<version>5.10.0</version>
</dependency>
</dependencies>

最佳答案

activemq-client v. 5.10 使用 jms 1.1.x。 Maven 传递加载:

<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_1.1_spec</artifactId>
<version>1.1.1</version>
</dependency>

创建持久消费者是 jms 2.0 的新功能。因此,调用 javax.jms.Session.createDurableSubscriber(Topic topic, String name); 会引发 java.lang.AbstractMethodError。

关于java - 当我尝试调用 org.apache.activemq.ActiveMQSession.createDurableConsumer 时,为什么会出现 java.lang.AbstractMethodError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24675845/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com