出于某种原因,我无法创建持久的使用者来接收来自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...");
}

错误:
线程“main”java.lang.AbstractMethodError中出现异常:org.apache.activemq.activemqsession.createDurableCuster(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客户机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.AbstractMethod错误。

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

10-12 22:11