(Quick Reference)

3 The Configuration Mechanism

Version: 2.0.0.RC2

3 The Configuration Mechanism

JMS is a complicated topic. There are different consumption and configuration patterns. While this plugin does set some reasonable defaults, it's very likely that you are going to need to customise these settings either globally or for specific senders or listeners.

To support this, the plugin makes configuration options available to you should you need to set it. This is achieved through the use of Spring's abstract beans and Grails' configuration mechanism.

How it works

The configuration is controlled by the Grails application configuration under the key jms. This is merged against plugin provided defaults.

Here is what the defaults look like...

templates:
    standard:
        connectionFactoryBean: jmsConnectionFactory
        messageConverterBean: standardJmsMessageConverter

...

That creates a map of "bean definitions" that get processed into real bean definitions.

The default config creates our standard (i.e. default) converters, jms templates for sending, and listener containers and adapters for receiving.

When sending messages with the jmsService you can specify which template to use to send the message. If none is specified, "standard" is used.

Likewise, listeners can specify which container and/or adapter bean definition to base themselves on. If none are specified, "standard" is used in both cases.

3.1 Changing Defaults

You can override the configuration defaults very easily.

Let's suppose you do not want any message conversion on listeners. If a listener container has no messageConverter listeners will receive raw messages. So we want to override the standard listener container definition to set the messageConverter property to null.

In your application's application.yml

jms:
    containers:
        standard:
            messageConverter: null

This definition will get merged against the plugin provided defaults to produce a standard listener container definition with messageConverter set to null.

Disabling the default dependency on the Persistence Interceptor.

If you are not using any GORM implementation such as Grails Hibernate Plugin (i.e. you uninstalled the hibernate plugin) or the GORM implementation you are using doesn't provide a Persistence Interceptor Bean, you will have to disable the default dependency to the Persistence Interceptor Bean. You can do this by setting in the application.yml the jms.adapters.standard.persistenceInterceptorBean to null .

jms:
    adapters:
        standard:
            persistenceInterceptorBean: null

3.2 Syntax Notes

There are some noteworthy things about this config syntax.

Bean names

The beans created automatically get suffixes applied to them. Template bean names get suffixed with 'JmsTemplate', container beans get suffixed with 'JmsListenerContainer' and adapter beans get suffixed with 'JmsListenerAdapter'.

Setting Beans

To set a property to another Spring bean, simply append Bean to the property name and set the property to the name of the bean.

Here is how the standard template is defined to use the bean named jmsConnectionFactory as it's connection factory...

templates {
    standard {
        connectionFactoryBean = "jmsConnectionFactory"
    }
}

Setting Class

To set the class of a bean, you must use the following syntax

templates {
    standard {
        meta {
            clazz = my.org.CustomJmsTemplate
        }
    }
}

Extending Definitions

Bean definition can inherit from parents and selectively override settings.

templates {
    other {
        meta {
            parentBean = 'standardJmsTemplate'
        }
        connectionFactoryBean = "someOtherJmsConnectionFactory"
    }
}

This creates an "other" template, that inherits all of the standard settings but uses a custom connectionFactory.