|
dear all,
i've having trouble with a subscriber blocking on a
receive message call.
for the time being i can use a Queue instead of a
Topic but would like
to know if anyone can spot any stupid error i'm
making.
--- code for publisher ----
Topic t = (Topic)ServerUtil.get( "jms/configTopic"
);
TopicConnectionFactory tcf = (TopicConnectionFactory)ServerUtil.get( "jms/TopicConnectionFactory" ); TopicConnection tc = tcf.createTopicConnection(); TopicSession ts = tc.createTopicSession(false,TopicSession.AUTO_ACKNOWLEDGE); TopicPublisher tp =
ts.createPublisher(t);
Message m = ts.createTextMessage("hello
world");
tp.publish(m);
// create subscriber in a new thread.
new Thread( new
Listener(tc,ts,t)).start();
---- code for subscriber ----
class Listener implements Runnable
{
TopicConnection tc; TopicSession ts; Topic t; Listener(TopicConnection tc, TopicSession ts,
Topic t) throws Exception {
this.tc= tc; this.ts = ts; this.t = t; } public void run() { try { TopicSubscriber sub = ts.createSubscriber(t,null,true); System.out.println("receiving message..." ); tc.start(); synchronized(this) { wait(5000); } System.out.println(sub.receive()); // <==== this line blocks. why? } catch( Exception e ) {
e.printStackTrace();
} System.out.println("end"); } } thanks,
greg.
|
- Re: JMS TopicSubscriber blocks on receive() Greg Matthews
- Re: JMS TopicSubscriber blocks on receive() Johan Fredriksson
- Re: JMS TopicSubscriber blocks on receive() Greg Matthews
- Re[2]: JMS TopicSubscriber blocks on receive() Tim Rickard
- Re[2]: JMS TopicSubscriber blocks on receive() Tim Rickard
