users@glassfish.java.net

Re: How to dynamically create and use Queues? (JMS)

From: <glassfish_at_javadesktop.org>
Date: Thu, 18 Dec 2008 07:09:38 PST

Hi antilochus,

> Oh.. that would explain why they're not Serializable!
> Hmm... so my only option is to use an 'admin created'
> queue.

No, we have solved exactly the issue your are looking for. Indeed, the temporary queue is not serializable, because inside the server the Direct... classes are used (EMBEDDED mode), while outside the IO implementations are used.

But if you remember why temporary queues exist, the solution is quite simple.

A temporary queue was introduced to do synchronous request/reply using JMS
and the JMSReplyTo header field:

tq = session.createTemporaryQueue();
message = session.createTextMessage();
message.setJmsReplyTo( tq );
sender = session.createQueueSender( queue );
sender.send( message );

The temporary queue is serialized by the provider specific way and
can be extracted at the other side:

message = receiver.receive();
tq = message.getJMSReplyTo();

The only thing you would need is a central queue registry reachable by a permanent queue and served by an MDB in the server.

Then a client can connect, create a temporary queue, register it in the server and get an acknowledge message on its own temporary queue to complete the handshake.

Internally, OpenMQ generates special queue names like "temporary_destination://queue/159.29.47.20/6411751793416955648/1"
which cannot created by the administrative interface. These names are sent together with the class name inside the message Packet to the other side.
Using that name the other side can recreate the queue in the correct representation.

The central queue registry could store the queue objects in local JNDI, but should not make a remote lookup to avoid serialization issues. Instead, any client should query the registry with the name and get the queue in the JMSReplyTo field.

> Have you an idea on how my EJB could create
> one of those on demand? I'm wondering if "GlassFish
> Project - AMX (Appserver Management EXtensions)" is
> what I should be looking at?

Have a look at the OpenMQ docs, e.g. for OpenMQ 4.1:

http://docs.sun.com/app/docs/doc/819-7758?l=en

This is the Developers Guide for JMX clients.

Cheers, Jörg
[Message sent by forum member 'jthoennes' (jthoennes)]

http://forums.java.net/jive/thread.jspa?messageID=322382