【问题标题】:Why do I get java.lang.AbstractMethodError when I try to call org.apache.activemq.ActiveMQSession.createDurableConsumer当我尝试调用 org.apache.activemq.ActiveMQSession.createDurableConsumer 时,为什么会出现 java.lang.AbstractMethodError
【发布时间】:2014-08-31 18:53:37
【问题描述】:

由于某种原因,我无法创建一个持久的消费者来从 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...");
}

错误:

线程“主”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>

【问题讨论】:

  • 您可能在编译时和运行时使用了不同的 jar。尝试从出现错误的代码中打印类路径,您可能会遇到一些令人惊讶的事情。

标签: java jms activemq


【解决方案1】:

在尝试将 CompletionListener 接口用于 onCompletion 方法时,我也遇到了同样的问题 (java.lang.AbstractMethodError)。我使用 JMS 2.0 Jar 和 JDK7 特定的 qpid 客户端 Jar 来在 qpid 代理上放置消息。

为了解决我的问题,我观察到使用 JMS2.0 Jars,我不得不切换到 JDK 8 特定的 Qpid Jars,使用 JDK 8 来执行我的代码。

【讨论】:

    【解决方案2】:

    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。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 2013-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多