You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by davidi <da...@relegen.com> on 2011/07/08 04:41:34 UTC
No response being received - consumer.Receive always timeout
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.
Re: No response being received - consumer.Receive always timeout
Posted by davidi <da...@relegen.com>.
I have found the problem. Simple typo...
The line "session.CreateConsumer(destination))" was assigning the wrong
destination, it should have been the temporary queue which was created
earlier.
--
View this message in context: http://activemq.2283324.n4.nabble.com/No-response-being-received-consumer-Receive-always-timeout-tp3653090p3653259.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.
Re: No response being received - consumer.Receive always timeout
Posted by davidi <da...@relegen.com>.
Thanks for the quick reply.
You are correct, I didn't have a connection.Start(). I assumed it starts
automatically because the Producer.Send() worked ?? Anyway, I have added
"connection.Start();" immediately after the creation of "connection". It
didn't work, same problem. The consumer.Receive just returns a null every
time.
--
View this message in context: http://activemq.2283324.n4.nabble.com/No-response-being-received-consumer-Receive-always-timeout-tp3653090p3653129.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.
Re: No response being received - consumer.Receive always timeout
Posted by Timothy Bish <ta...@gmail.com>.
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.bish@fusesource.com
Web: http://fusesource.com
Twitter: tabish121
Blog: http://timbish.blogspot.com/