Reputation: 24635
I need to create temporary queues on fly. How is that possible?
Upvotes: 2
Views: 1405
Reputation: 988
From your jms Queue/TopicSession object: see QueueSession javadoc.
You need to keep the session open for the lifecycle of the temporary queue.
Typical usage is for a client to open a session and put a message on a shared processing queue,using the temporary queue in the reply-to field of the message. eg:(pseudo-code)
Queue queue = session.createQueue("shared");
Queue responseQueue = session.createTemporaryQueue();
Message message = session.createMessage();
message.setJMSReplyTo(responseQueue);
...
session.commit();
...
MessageConsumer responseConsumer = session.createConsumer(responseQueue);
Message response = responseConsumer.receive();
...
session.close();
The MDB ( or listener that read the shared process queue ) will send the response back to the reply-to queue. If the client is dead for any reason, its session is closed and the queue ceased to exist.
Upvotes: 3