1

I have a application that will be processing hundreds of thousands (500,000+) of JMS requests per day. The application is responsible for routing the message to a new destination based on the information received in the request.

When processing the request, I also need the ability to modify some of the JMS attributes. For example, I need to set the persistence, time to live and priority of the messages. So, my listener picks up the messages, interrogates the request message, determines the destination, and then sets those properties on the JMS template.

My question is in regards to concurrency and the setting of these properties. Let's say I am processing 2 concurrent requests. Request A set the persistence to be persistent and request B sets the persistence to non-persistence. Is there any danger her that request A would be set to non-persistent? Can the setting of these properties at the template level cause issues?

Here is some sample code that is setting these properties:

    jmsTemplate.setExplicitQosEnabled(true);
    jmsTemplate.setDeliveryPersistent(isPersistent);
    jmsTemplate.setTimeToLive(timeToLive);
    jmsTemplate.setPriority(priority);

    jmsTemplate.send(createQueue(encoding));

Thanks in advance for you help!

Dan DaLuga
  • 85
  • 2
  • 10

1 Answers1

1

Yes; it will cause issues; Spring Integration uses a DynamicJmsTemplate for this exact reason (storing properties in ThreadLocals).

It doesn't support all the properties you need but you could use it as a model.

Here's the code and here is how it is used.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179