Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get java.lang.AbstractMethodError when I try to call org.apache.activemq.ActiveMQSession.createDurableConsumer

For some reason I am unable to create a durable consumer, to ingest messages from activemq. I have researched here and here, but using the latest versions (along with Java 1.7) hasn't solved the problem. I must be using a wrong version/implementation of something, but I haven't been able to root it out. Here is the code:

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...");
}

The error:

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

My dependencies:

<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>
like image 660
Ted Avatar asked Feb 07 '26 14:02

Ted


1 Answers

The activemq-client v. 5.10 uses jms 1.1.x. Maven transitively loads:

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

Creating durable consumers is new as of jms 2.0. So, calling javax.jms.Session.createDurableSubscriber(Topic topic, String name); throws a java.lang.AbstractMethodError.

like image 178
Ted Avatar answered Feb 09 '26 08:02

Ted



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!