1
votes

I'm trying to create a durable consumer using ActiveMQ 5.x, so i have the following:

private static void consumeFromTopic() throws JMSException, NamingException {
    javax.naming.Context ctx = new InitialContext();

    ConnectionFactory factory = (ConnectionFactory) ctx.lookup("ConnectionFactory");
    Connection connection = factory.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Topic topic = session.createTopic("topic-queue");
    MessageConsumer consumer = session.createDurableConsumer(topic, "lanhellas-durable-consumer");
    consumer.setMessageListener(new MyListener());

    connection.start();
}

When i try to start my consumer i got the following:

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

This is my pom.xml:

<dependency>
    <groupId>javax.jms</groupId>
    <artifactId>javax.jms-api</artifactId>
    <version>2.0.1</version>
</dependency>

<dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>activemq-core</artifactId>
    <version>5.7.0</version>
</dependency>

So, reading more about ActiveMQ 5.x i discovered that only support JMS 1.x and this method is not supported in this version, so i will need to change to Apache Artemis that support JMS 2.0, but i have some doubts about it:

  1. What is the correct javax.jms-api version to work with ACtiveMQ 5.x library ?
  2. Why ActiveMQ 5.x broker (console management) have support to durable consumer if this is not supported in JMS 1.x ?
  3. What is the correct versions and dependencies to work with Apache Artemis ?
1

1 Answers

2
votes

JMS 1.1 does support durable subscriptions, you simply need to look at the API docs to find out how, here's one method that would create a durable Topic subscriber.

I've answered the what is the right JMS dependency before on SO, see here.