This content has been marked as final.
Show 3 replies
-
1. Re: Best architecture practice for jboss messaging.
timfox Aug 16, 2008 11:16 AM (in response to jadtn)I would use a topic.
Each user can create a subscription when they join.
If you want users to see chat messages sent while they were not connected, they can use a durable subscription. -
2. Re: Best architecture practice for jboss messaging.
jadtn Sep 8, 2008 7:20 AM (in response to jadtn)Thanks.
-
3. Re: Best architecture practice for jboss messaging.
francis17101970 Sep 9, 2008 9:15 AM (in response to jadtn)This is a barebone JMS client sampe.
import java.util.Properties; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageListener; import javax.jms.Topic; import javax.jms.TopicConnection; import javax.jms.TopicConnectionFactory; import javax.jms.TopicPublisher; import javax.jms.TopicSubscriber; import javax.jms.TopicSession; import javax.jms.TextMessage; import javax.naming.InitialContext; import javax.naming.NamingException; import EDU.oswego.cs.dl.util.concurrent.CountDown; public class ChatClient { static CountDown done = new CountDown(1); TopicConnection conn = null; TopicSession session = null; Topic topic = null; public static class ExListener implements MessageListener { public void onMessage(Message msg) { done.release(); TextMessage tm = (TextMessage) msg; try { System.out.println("onMessage, recv text=" + tm.getText()); } catch(Throwable t) { t.printStackTrace(); } } } public void setupPubSub() throws JMSException, NamingException { Properties props = new Properties(); props.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory"); props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces"); props.setProperty("java.naming.provider.url", "jnp://localhost:1099"); InitialContext iniCtx = new InitialContext(props); Object tmp = iniCtx.lookup("ConnectionFactory"); TopicConnectionFactory tcf = (TopicConnectionFactory) tmp; conn = tcf.createTopicConnection(); topic = (Topic) iniCtx.lookup("topic/testTopic"); session = conn.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE); conn.start(); } public void sendRecvAsync(String text) throws JMSException, NamingException { System.out.println("Begin sendRecvAsync"); // Setup the PubSub connection, session setupPubSub(); // Set the async listener TopicSubscriber recv = session.createSubscriber(topic); recv.setMessageListener(new ExListener()); // Send a text msg TopicPublisher send = session.createPublisher(topic); TextMessage tm = session.createTextMessage(text); send.publish(tm); System.out.println("sendRecvAsync, sent text=" + tm.getText()); send.close(); System.out.println("End sendRecvAsync"); } public void stop() throws JMSException { conn.stop(); session.close(); conn.close(); } public static void main(String args[]) throws Exception { System.out.println("Begin TopicSendRecvClient, now=" + System.currentTimeMillis()); ChatClient client = new ChatClient (); client.sendRecvAsync("A text msg, now="+System.currentTimeMillis()); client.done.acquire(); client.stop(); System.out.println("End TopicSendRecvClient"); System.exit(0); } }
You could expand it adding Selectors which allow you to filter messages.// Set the Message Selector message.setStringProperty("CHATROOM",chatRoom); topicPublisher.publish(message);
good chatting
regards