-
1. Re: JMS PubSub Design Pattern Question
fawce Dec 8, 2002 12:29 AM (in response to pat.ryan)I think you want to set the nolocal flag to true on your topic session. you can see an example in the jboss testsuite distributed with the source, you want to look at the Class: org.jboss.test.jbossmq.test.JBossMQUnitTestCase
the relevent method is named: testTopicNoLocal.
for your convenience here is the snippet:
/**
* Test to seeif the NoLocal feature of topics works.
* Messages published from the same connection should not
* be received by Subscribers on the same connection.
*/
public void testTopicNoLocal() throws Exception
{
getLog().debug("Starting TopicNoLocal test");
connect();
TopicConnectionFactory topicFactory = (TopicConnectionFactory)context.lookup(TOPIC_FACTORY);
TopicConnection topicConnection1 = topicFactory.createTopicConnection();
topicConnection1.start();
TopicConnection topicConnection2 = topicFactory.createTopicConnection();
topicConnection2.start();
// We don't want local messages on this topic.
TopicSession session1 = topicConnection1.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = (Topic)context.lookup(TEST_TOPIC);
TopicSubscriber subscriber1 = session1.createSubscriber(topic, null, true);
TopicPublisher sender1 = session1.createPublisher(topic);
//Now a sender
TopicSession session2 = topicConnection2.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
TopicPublisher sender2 = session2.createPublisher(topic);
drainMessagesForTopic(subscriber1);
//send some messages
sender1.publish(session1.createTextMessage("Local Message"));
sender2.publish(session2.createTextMessage("Remote Message"));
// Get the messages, we should get the remote message
// but not the local message
TextMessage msg1 = (TextMessage)subscriber1.receive(2000);
if( msg1 == null )
{
fail("Did not get any messages");
} else
{
getLog().debug("Got message: "+msg1);
if(msg1.getText().equals("Local Message"))
{
fail("Got a local message");
}
TextMessage msg2 = (TextMessage)subscriber1.receive(2000);
if( msg2 != null )
{
getLog().debug("Got message: "+msg2);
fail("Got an extra message. msg1:"+msg1+", msg2:"+msg2);
}
}
topicConnection1.stop();
topicConnection1.close();
topicConnection2.stop();
topicConnection2.close();
disconnect();
getLog().debug("TopicNoLocal test passed");
} -
2. Re: JMS PubSub Design Pattern Question
pat.ryan Dec 8, 2002 1:35 PM (in response to pat.ryan)Thank you! I should have seen that one. I really hate when someone has to read the spec to me. Thanks again.
-
3. Re: JMS PubSub Design Pattern Question
fawce Dec 8, 2002 3:35 PM (in response to pat.ryan)np. I have been spending alot of time with the testsuite lately...