Hello

I believe I may have uncovered a possible concurrency issue with the way
the Java Broker and/or Client works.  It appears if a message consumer
is awaiting a message in receive() before its connection is started, it
is never able to pull from its queue.

I have attached a sample bit of code that hopefully displays this.  In
it, I create a temp queue and consumer from a session.  Then I create a
sub-thread that creates a producer, sends a message, then tries to
manually have the consumer pull from that queue using cons.receive().

I start the thread, sleep for 2s, and then start the connection.  The
consumer hangs while trying to receive the message.  According to JMX,
the temp queue I create has both a consumer and a message before I start
the sub-thread.

This is against the M4 versions of the Java Broker and client; I have
also tried the first 0.5 release candidate.

Thanks

WS
        public static void main( final String[] args )
                throws Exception
        {
                final AMQConnectionFactory factory = new AMQConnectionFactory( 
conUrl );
                final Connection con = factory.createConnection();
                
                final Session session = con.createSession( false, 
Session.AUTO_ACKNOWLEDGE );
                final Destination dest = session.createTemporaryQueue();
                final MessageConsumer cons = session.createConsumer( dest );

                final Thread t = new Thread( "ProducerTest" ){
                        public void run() {
                                MessageProducer pro;
                                try {
                                        pro = session.createProducer( dest );
                                        final TextMessage msg = 
session.createTextMessage();
                                        msg.setText( "help" );
                                        pro.send( msg );
                                        
                                        System.err.println( "Waiting to 
receive" );
                                        final Message message = cons.receive();
                                        System.err.println( "Got Message : " + 
message );
                                }
                                catch ( JMSException e ) {
                                        e.printStackTrace();
                                }
                        }
                };
                
                t.start();
                Thread.sleep( 2000l );
                con.start();
                //ProducerTest thread should hang.
        }
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscr...@qpid.apache.org

Reply via email to