ActiveMQ - Sending a message to a temporary queue specified using a string (NMS in C#)

StackOverflow https://stackoverflow.com/questions/4722022

  •  12-10-2019
  •  | 
  •  

Question

I have a synchronous message transaction within my system, and the process broadly follows this flow:

  1. "Point A" creates a temporary queue ("destination 2") on the message broker;
  2. Message sent from point A to destination 1 (a normal queue on the message broker), with the ReplyTo address set as destination 2;
  3. point A blocks waiting for response on destination 2;
  4. point B receives message from destination 1;
  5. point B creates a work object - a property of which is the name of destination 2 (derived using .ToString()". This work object is serialized and stored in the DB;

...

  1. Object retrieved from DB when certain parameters are met, changes ocurr, and a response is sent to destination 2 - using SessionUtil to derive a new IDestination object from the replyto address stored as a string property of the work object;
  2. "Point A" recieves message from destination 2 and continues on.

This process can take anything from a split second to several seconds to accomplish.

I need to use the name of the return destination (destination 2), rather than the full IDestination object, as I have to serialize the object and store in the DB.

If I use a permanent queue or a topic as destination 2, the process works fine. However, it always fails when attempting to create it using the string name of the temporary queue.

There are no errors, the message just fails to arrive

Any ideas why?

Example code for sending return message shown:

IDestination myDestination = SessionUtil.GetDestination(stateSession, instance.ReplyTo, DestinationType.Queue);

stateConnection.Start();

using (IMessageProducer myProducer = stateSession.CreateProducer(myDestination))
{
myProducer.DeliveryMode = MsgDeliveryMode.NonPersistent;
var response = myProducer.CreateTextMessage();

response.NMSCorrelationID = instance.CorrelationID;
response.Properties["RoutingDestination"] = instance.RoutingOriginator;
response.Text = "Test Response";

try
{
    myProducerBroadcast.Send(response);
    myProducer.Send(response);

    Log.InfoFormat("Sent response {0} to {1}", instance.UniqueId, instance.ReplyTo);
}
catch (Exception ex)
{
    Log.Error("Unable to send execution update onwards", ex);
}                
}

("instance" is the work object - which contains the ReplyTo address and other information)

Was it helpful?

Solution

A temporary destination is just that, temporary. Once the Connection object that created the Temporary Destination closes, the destination is automatically removed from the broker. Storing the temp destination for later use is not a good idea for this reason. Also, only the Connection that created the temp destination is allowed to consume on it.

OTHER TIPS

I did notice temp queues don't work if the broker is configured to not use "advisorySupport"

Reenabling that got the queues to work for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top