adam bien's blog

(Asynchronous :-)) AJAX/RESTFul Java EE Integration With Glassfish And Others - Installation And Smoke Test (with GF v2) 📎

Short announcement, great feature. OpenMQ 4.3, which will come with Glassfish 2.1, includes a REST-Style API for JMS messaging. This features is delivered as a reusable, single WAR (imqums.war). It can be even easily backported to an existing Glassfish installation:

  1. Install openMQ 4.3 (it's painless - only few clicks required). This is only required to get the WAR: imqums.war 
  2. Go to the installation directory and copy [openMQ43]\mq\lib\imqums.war into your Glassfish v2 autodeployment ([glassfish-v2]\domains\domain1\autodeploy) directory.
  3. Launch the sample with: http://localhost:8080/ums/
  4. Start the example.

The sample application will create destinations for you on the fly. These are "physical" queues. You only have to create a logical queue in the admin console (approx. 3 clicks) - and then you are able to receive JSON messages with a ...Message Driven Bean. The Message Driven Bean has to be mapped to the logical queue (the mapped name):

@MessageDriven(mappedName = "ajax", activationConfig =  {
        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
    })
public class AJAXListenerBean implements MessageListener {
   
    @EJB
    private MessageConsumer consumer;
 
    public void onMessage(Message msg) {
        TextMessage tm = (TextMessage) msg;
        try {
            String message = tm.getText();
            consumer.consume(message);
        } catch (JMSException ex) {
            throw new EJBException("Cannot receive payload : " +ex,ex);
        }
    }
 }

The REST-API is simple, concise and Java-independent per definition. It is perfectly suitable for integration of non-Java clients with enterprise applications (AJAX, Perl, PHP etc.). Even load / extraction jobs, or monitoring could be easily implemented with the UMS.

[The sample is borrowed from the book, which I currently write :-)].