activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ttmdev <joe.fernan...@ttmsolutions.com>
Subject Re: Lost Messages and Embedded Broker
Date Fri, 28 Sep 2007 16:05:51 GMT

Hi Rob, 

Actually, it is pretty straight forward. Here's some code from my test
publisher to illustrate. Note the comment for the first Thread.sleep.

==== code snippet ====
...

Context ctx = new InitialContext();

//  peer1ConnectionFactory maps to 'peer://groupa'  

ConnectionFactory factory = (ConnectionFactory)
  ctx.lookup("peer1ConnectionFactory");            
          
Connection conn = factory.createConnection();
            
Topic myTopic = (Topic) ctx.lookup("dynamicTopics/TOPIC.FOO.BAR");

Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
                                
MessageProducer topicSender = session.createProducer(myTopic);
            
conn.start();
            
// If you comment out this sleep, the messages will get lost 
// (i.e., subscriber will never get them). W/the sleep, 
// the subscriber gets them just fine. 
Thread.sleep(1000);  
                    
// Publish five test messages
for(int i=0; i<5; i++){
    msg = session.createTextMessage();
    String temp = Math.random() + "{}";
    msg.setText("Test Message["  + i + "] " + temp);
    msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
    topicSender.send(msg);                
}

// Pause a bit just for grins             
Thread.sleep(2 * 1000);
            
topicSender.close();
session.close();
conn.close(); 
System.out.println("All done …");             

...
================

Joe






rajdavies wrote:
> 
> joe,
> 
> do you have a test case for this? This sounds like a bug
> 
> 
> cheers,
> 
> Rob
> 
> http://rajdavies.blogspot.com/
> 
> 
> 
> On Sep 28, 2007, at 3:34 PM, ttmdev wrote:
> 
>>
>> If your client is starting an embedded broker via the vm or peer  
>> connectors
>> and sends a message immediately after invoking connection.start(),  
>> that
>> message will most likely fall into a black hole and your client is  
>> never
>> notified of this. This is because the embedded broker has not been  
>> fully
>> activated by the time you send the message. There is a warning on  
>> the web
>> site re this with an accompanying Spring-dependent work-around.  
>> However, I
>> would prefer not to rely on Spring. The connection.isStarted()  
>> method does
>> not help and neither does a transportListener. Other than forcing a  
>> delay
>> after connection.start(), does anyone else know of a more elegant  
>> way to be
>> notified that the embedded broker is ready to rock-n-roll and thus  
>> safe to
>> start sending messages?
>>
>> Joe
>> -- 
>> View this message in context: http://www.nabble.com/Lost-Messages- 
>> and-Embedded-Broker-tf4534900s2354.html#a12941763
>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>>
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Lost-Messages-and-Embedded-Broker-tf4534900s2354.html#a12943513
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Mime
View raw message