I might have missed it in the code but I don't see a call to
connection.Start().  If you don't start the connection the consumer
won't receive anything.

Regards
Tim.

On Thu, 2011-07-07 at 19:41 -0700, davidi wrote:
> Hi,
> 
> I am new to ActiveMQ and I am trying to write a basic publisher and
> listener.
> 
> I have used several code formats and can always send the initial message to
> the listener without any issue but no matter what I try, I can not get a
> response. The response from the listener does not fail, but it is never
> received  by my publisher. When I check the ActiveMQ queues I can see what
> looks like the temp queue with a pending  message but for some reason my
> comsumer.receive always timesout.
> 
> Any help would be appreciated.
> 
> My pulbisher code is:
> 
>  //Create the Connection 
>             var connectionFactory = new ConnectionFactory(ListenerAddress);
> 
>             using (var connection = connectionFactory.CreateConnection())
>             {
>                 using (var session =
> connection.CreateSession(AcknowledgementMode.ClientAcknowledge))
>                 {
>                     //var queue = session.CreateTemporaryQueue();
>                     //using (var consumer = session.CreateConsumer(queue))
>                     //{
>                         IDestination destination =
> SessionUtil.GetDestination(session, QueueName);
>                         ITemporaryQueue replyTo =
> session.CreateTemporaryQueue();
> 
>                         using (IMessageConsumer consumer =
> session.CreateConsumer(destination))
>                         using (IMessageProducer producer =
> session.CreateProducer(destination))
>                         {
>                             IMessage request =
> session.CreateTextMessage(MessageText);
> 
>                             request.NMSReplyTo = replyTo;
> 
>                             producer.Send(request);
> 
>                             request =
> consumer.Receive(TimeSpan.FromMilliseconds(8000));
> 
>                             using (IMessageProducer responder =
> session.CreateProducer(request.NMSReplyTo))
>                             {
>                                 IMessage response =
> session.CreateTextMessage("RESPONSE");
>                                 responder.Send(response);
>                             }
>                         }
> 
>                         using (IMessageConsumer consumer =
> session.CreateConsumer(replyTo))
>                         {
>                             ITextMessage response =
> consumer.Receive(TimeSpan.FromMilliseconds(3000)) as ITextMessage;
>                         }
> 
>                 }
>             }
>            
> _myExceptionHandler.HandleException(ExceptionLevels.ExceptionLevel.Debug,
> "Message sent successfully");
>             return true;
>         }
> 
> 
> My Listener code is:
> 
>   public void OnMessage(IMessage message)
>         {
>             try
>             {
>                 // Found a new message event
>                 Message = message as ITextMessage;
> 
>                       // Process the received message here
>                     // Forward the message to the Observers
>                     PublishMesssage(Message.Text);
> 
>                 // Lets process the response
>                 using (session = connection.CreateSession())
>                 {
>                     // We are replying to the queue stored in NMSReplyTo
>                     // We will echo the same message back to the sender
>                     IDestination destination = message.NMSReplyTo;
>                     if (destination != null)
>                     {
>                         ITextMessage response =
> session.CreateTextMessage(Message.Text);
>                         response.NMSCorrelationID =
> message.NMSCorrelationID;
>                         using (IMessageProducer responder =
> session.CreateProducer(destination))
>                         {
>                             IMessage response2 =
> session.CreateTextMessage("RESPONSE");
>                             responder.Send(response2);
>                         }
>                     }
>                     Message = null;
> 
>                     Semaphore.Set();
>                 }
>             }
>             catch (Exception ex)
>             {
>                
> _myExceptionHandler.HandleException(ExceptionLevels.ExceptionLevel.Error,
> ex);
>             }
>         }
> 
> thanks
> Dave
> 
> --
> View this message in context: 
> http://activemq.2283324.n4.nabble.com/No-response-being-received-consumer-Receive-always-timeout-tp3653090p3653090.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.

-- 
Tim Bish
------------
FuseSource
Email: tim.b...@fusesource.com
Web: http://fusesource.com
Twitter: tabish121
Blog: http://timbish.blogspot.com/



Reply via email to