johan, thanks for the response.
 
As you can see from my code snippet, a message is created and posted, and there is a 5 second pause between publishing the message, and then attempting to receive it.
 
In my experiments with a Queue, the message was available to a QueueReceiver almost straight away. Is there some difference between Queue and Topic based messaging where Topic messages take much longer to become available?
 
regards,
greg.
----- Original Message -----
Sent: Wednesday, July 25, 2001 5:20 PM
Subject: Re: JMS TopicSubscriber blocks on receive()

It is quite obvious it is waiting for a message.
 
So my advice is that you write a client / jsp page / whatever with a TopicBrowser(?) to make sure your message really is there.
 
Johan 
----- Original Message -----
Sent: Wednesday, July 25, 2001 2:49 AM
Subject: JMS TopicSubscriber blocks on receive()

 
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.
 

Reply via email to