I am looking for a little guidance on the best way to handle this:

Network thingys come and register with us.
We create a queue for them and we start accepting events from them which we place on that queue.
The events are ordered so must follow one-by-one.
The event consumer is independent of the queue-adder so both run at the same time.
There may be 20 or 30 or more network thingys.


My current solution is:

Code:
    <bean id="jmsDestinationResolver" class="org.springframework.jms.support.destination.DynamicDestinationResolver"/>

    <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
        <property name="connectionFactory" ref="jmsConnectionFactory"/>
        <property name="destinationResolver" ref="jmsDestinationResolver"/>
        <property name="pubSubDomain" value="false"/>
        <property name="receiveTimeout" value="5000"/>
    </bean>
The java class which adds messages uses:
Code:
  String queueName = "net-thing-" + id;
  jmsTemplate.send (queueName, new MessageCreator ()
    {
      public Message createMessage (Session session) throws JMSException
      {
      return session.createTextMessage (mytext) ;
      }
    }) ;
The java class which processes messages uses:
Code:
while (true)
{
  try
    {
    Message msg = jmsTemplate.receive (queueName) ;
    // do stuff
    }
  catch (receiveTimeoutException e)
    {
    // ignore
    }
}
I have found that when I call jmsTemplate.receive it blocks which means I need a separate thread to sit around waiting for things to do.

Is there a way that spring can manage this? Is there a way to get Spring to call onMessage (or similar) when a message arrives for that queue without having to define the queue in advance or having to create my own threads to do the event processing.

Any help would be greatly appreciated.