0

Good day all,

I am trying to config a message driven bean to subscribe to an external topic. I and my coworker has together successfully listen to the topic with JSE client which looks something like this.


    public static void main(String[] args) {
        TopicSession    sess     =  null;
        TopicConnection conn     = null;
        TopicSubscriber consumer = null;

        Properties props = new Properties();
        p.put("java.naming.provider.url",         "remote://#server-name#:#server-port(4747)#");
        p.put("java.naming.factory.initial",      "org.jboss.naming.remote.client.InitialContextFactory");
        p.put("java.naming.security.principal",   "#username#");
        p.put("java.naming.security.credentials", "#password#");

        InitialContext context = new InitialContext(props);

        TopicConnectionFactory factory = (TopicConnectionFactory)context.lookup("jms/RemoteConnectionFactory");
        conn = factory.createTopicConnection("#username#", "#password#");
        conn.setClientID("#client-id#");

        sess = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

        Topic topic = (Topic)context.lookup("jms/topic/#topic-name#");
        consumer = sess.createSubscriber(topic);
        consumer.setMessageListener(new MyTopicListener());

        try {
            conn.start();
            // ... loop until done.
        } finally {
            consumer.close();
            sess.close();
            conn.close();
        }
    }

How can I move this to an MDB?

For what I know, we can set the destinationType, connectionFactoryJndiName, destinationJndiName, initialContextFactory with activationConfig of MessageDriven annotation. But how about remote URL, username and password?

FYI, I am using JBoss AS 7.1.1 and this is for MDB 3.0.

Thanks a lot in advance for any answer and comments.

NawaMan
  • 25,129
  • 10
  • 51
  • 77

2 Answers2

1

HornetQ has an inbound and outbound resource adapter. The inbound JCA RA is used to consuming messages by a message driven bean (MDB). The resource adapter can be configured with activation config properties of the MDB, as shown in the following example:

@MessageDriven(name = "ExampleMDB", activationConfig = {
   @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
   @ActivationConfigProperty(propertyName = "destination", propertyValue = "testQueue"),
   @ActivationConfigProperty(propertyName = "connectorClassName", propertyValue ="org.hornetq.core.remoting.impl.netty.NettyConnectorFactory"),
   @ActivationConfigProperty(propertyName = "connectionParameters", propertyValue = "host=172.168.1.137;port=5445")})
public class ExampleMDB implements MessageListener {
   public void onMessage(Message recvMsg) {
   ... 
   }
}

Refer to the HornetQ documentation for a complete list of configuration properties: http://docs.jboss.org/hornetq/

Heinz
  • 114
  • 2
1

you coul also check the new hornetrq http://www.packtpub.com/hornetq-messaging-developers-guide/book

user730712
  • 106
  • 1
  • 6