3

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>
Community
  • 1
  • 1
Ted
  • 1,641
  • 7
  • 30
  • 52
  • You are probably using different jars at compile time and at runtime. Try to print the classpath from your code where you get the error, you are likely to have something surprising. – StephaneM Jul 10 '14 at 12:27

2 Answers2

2

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.

Ted
  • 1,641
  • 7
  • 30
  • 52
0

I was also getting same sort of issue (java.lang.AbstractMethodError) while trying to use CompletionListener interface for onCompletion method. I was using JMS 2.0 Jar along with JDK7 specific qpid client Jars for placing a message on qpid broker.

To resolve my problem, what I observed For working with JMS2.0 Jars, I had to switch to JDK 8 specific Qpid Jars, Use JDK 8 to execute my code.