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.