(Quick Reference)

1 Introduction

Version: 2.0.0.RC2

Table of Contents

1 Introduction

This plugin makes it easy to both send and receive JMS messages inside a Grails application.

Examples

The following are some simple examples to give you a feel for the plugin.

Service Queue Listeners

class ListeningService {

static exposes = ['jms']

def onMessage(message) { assert message == 1 } }

class SomeController {

def jmsService

def someAction = { jmsService.send(service: 'listening', 1) } }

Service Method Queue Listeners

import grails.plugin.jms.Queue

class ListeningService {

static exposes = ['jms']

@Queue def receive(message) { assert message == 1 } }

class SomeController {

def jmsService

def someAction = { jmsService.send(service: 'listening', method: 'receive', 1) } }

Topic Listeners

import grails.plugin.jms.Subscriber

class ListeningService {

static exposes = ['jms']

@Subscriber def newMessages(message) { assert message == 1 } }

class SomeController {

def jmsService

def someAction = { jmsService.send(topic: 'newMessages', 1) } }

Post Processing Messages

import javax.jms.Message

class SomeController {

def jmsService

def someAction = { jmsService.send(service: 'initial', 1) { Message msg -> msg.JMSReplyTo = createDestination(service: 'reply') msg } } }

1.1 Spring JMS

This plugin is built on top of Spring's JMS support

There are some core Spring JMS concepts that you should at least be aware of.

JmsTemplate

Spring provides JmsTemplate which is what this plugin uses to send messages.

MessageConverter

The MessageConverter abstraction conveniently allows pluggable message conversion. By default, this plugin uses Spring's SimpleMessageConverter which handles 'standard' message payloads and JMS Message types.

MessageListenerContainer

A listener container polls a JMS destination for messages. Each listener (i.e. each service method that receives JMS messages) has it's own listener container.

This plugin uses the DefaultMessageListenerContainer implementation.

MessageListenerAdapter

A listener adapter connects a listener container to the actual destination of the message. It handles message conversion amongst other things.

By default, this plugin uses a MessageListenerAdapter subclass that is Grails aware and sets up the necessary Grails environment for listener methods (e.g. Hibernate session).