Hi Tim,
Thanks for the suggestion I might have a play with the farm service in the
future.
If anyone is interested, for now I use something like the following, it seems
to do what I need;
public void addTopicMessageListener(String jndiName, MessageListener
messageListener) throws NamingException, JMSException, Exception {
|
| String topicName = jndiName.substring(jndiName.lastIndexOf('/')+1);
|
| try{
| //CHECK IF THE TOPIC IS DEPLOYED LOCALLY
| Topic topic = (Topic)haInitialContext.lookup(jndiName);
| log("OK Topic " + jndiName+ " exists");
|
| //I think this will throw an exception if the Topic is on a
remote machine
| MessageConsumer subscriber =
localJMSSession.createConsumer(topic);
| subscriber.setMessageListener(messageListener);
| log("Lstener "+messageListener+" add to topic " + topicName);
| }catch(Exception e){
| log("NO TOPIC, OR TOPIC WAS ON A REMOTE ONLY WHEN ADDING
MessageListener TO topic "+topicName+". "+e.getMessage());
|
| //DEPLOY THE TOPIC ON THIS MACHINE
| MBeanServerConnection mBeanServer =
MBeanServerLocator.locateJBoss();
| ServerPeerMBean serverPeerMBean = (ServerPeerMBean)
MBeanServerInvocationHandler.newProxyInstance(mBeanServer, new
ObjectName("jboss.messaging:service=ServerPeer"), ServerPeerMBean.class, false);
| serverPeerMBean.deployTopic(topicName, jndiName);
|
| //MAKE IT CLUSTERED
| ObjectName on = new
ObjectName("jboss.messaging.destination:service=Topic,name="+topicName);
| MBeanInfo mbeanInfo =
MBeanServerLocator.locateJBoss().getMBeanInfo(on);
| MBeanServerLocator.locateJBoss().invoke(on, "stop", null, null);
| MBeanServerLocator.locateJBoss().setAttribute(on, new
Attribute("Clustered", true));
| MBeanServerLocator.locateJBoss().invoke(on, "start", null,
null);
|
| //TRY TO ADD THE messageListenerAgain
| Topic topic = localJMSSession.createTopic(topicName);
| MessageConsumer subscriber =
localJMSSession.createConsumer(topic);
| subscriber.setMessageListener(messageListener);
| log("Successfully added listener "+messageListener+" to
distributed topic " + topicName);
| }
|
| }
cheers
James
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4094631#4094631
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4094631
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user