JMS Topic subscription Tomee 1.7.1

744 views Asked by At

I was experimenting with Message Driven Beans in order to receive Topic subscription messages from an external ActiveMQ instance.

My tests started first with Queue subscriptions which is working pretty nice.

Then I wanted to try Topic subscriptions but I cannot get it working.

This is what I have:

conf/tomee.xml

<tomee>
    <Resource id="MyJmsResourceAdapter" type="ActiveMQResourceAdapter">
        BrokerXmlConfig  =
        ServerUrl = tcp://192.168.1.176:61616
    </Resource>

    <Resource id="MyJmsConnectionFactory" type="javax.jms.ConnectionFactory">
        ResourceAdapter = MyJmsResourceAdapter
    </Resource>

    <Container id="MyJmsMdbContainer" ctype="MESSAGE">
        ResourceAdapter = MyJmsResourceAdapter
    </Container>

    <Resource id="MyQueue" type="javax.jms.Queue"/>
    <Resource id="MyTopic" type="javax.jms.Topic"/>
</tomee>   

This is the MDB:

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.Message;
import javax.jms.MessageListener;

@MessageDriven(mappedName = "MyTopic", activationConfig = { 
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic") 
    }
)
public class TestMDBTopic implements MessageListener {

    public TestMDBTopic() {
        super();
    }

    public void onMessage(Message message) {
        System.out.println("TOPIC\tMESSAGE: " + message);

    }

}

I do not know why but from the log I can see that TomEE creates a queue instead of a topic:

Nov 19, 2014 11:17:00 PM org.apache.openejb.config.AutoConfig logAutoCreateResource
INFO: Auto-creating a Resource with id 'MyTopic' of type 'javax.jms.Queue for 'TestMDBTopic'.

Another proof for this is that the server will not start when I add duration configuration:

@ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "Durable")

The server then complains that this doesn't fit to the configured type javax.jms.Queue.

I have also tried to make a TopicConsumer ina stupid simple mail method which was working perfectly. Also when I remove the queue configuration (MyQueue) from the entire configuration files this doesn't make a difference.

Anybody any idea what I'm doing wrong?

1

There are 1 answers

0
Kurt Hartmann On

I had exactly the same issue. I fixed the issue by removing the mappedName property in the @MessageDriven annotation. Tomee must be keying off of the mappedName and assuming it represents a queue destination. Anyways, I am now able to send messages to the topic and they are consumed by the listener.