Skip to content

Commit a27d4c8

Browse files
committed
Added configurable MessageConverter
1 parent a815e54 commit a27d4c8

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

RabbitmqGrailsPlugin.groovy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class RabbitmqGrailsPlugin {
6161
def connectionFactoryHostname = connectionFactoryConfig?.hostname
6262
def connectionChannelCacheSize = connectionFactoryConfig?.channelCacheSize ?: 10
6363

64+
def messageConverterBean = rabbitmqConfig.messageConverterBean
65+
6466
if(!connectionFactoryUsername || !connectionFactoryPassword || !connectionFactoryHostname) {
6567
log.error 'RabbitMQ connection factory settings (rabbitmq.connectionfactory.username, rabbitmq.connectionfactory.password and rabbitmq.connectionfactory.hostname) must be defined in Config.groovy'
6668
} else {
@@ -82,6 +84,7 @@ class RabbitmqGrailsPlugin {
8284
}
8385
rabbitTemplate(RabbitTemplate) {
8486
connectionFactory = rabbitMQConnectionFactory
87+
if (messageConverterBean) messageConverter = ref(messageConverterBean)
8588
}
8689
adm(RabbitAdmin, rabbitMQConnectionFactory)
8790
Set registeredServices = new HashSet()
@@ -220,12 +223,14 @@ class RabbitmqGrailsPlugin {
220223
}
221224

222225
def doWithApplicationContext = { applicationContext ->
226+
def rabbitTemplate = applicationContext.getBean('rabbitTemplate', RabbitTemplate.class)
223227
def containerBeans = applicationContext.getBeansOfType(SimpleMessageListenerContainer)
224228
containerBeans.each { beanName, bean ->
225229
if(beanName.endsWith(LISTENER_CONTAINER_SUFFIX)) {
226230
def adapter = new MessageListenerAdapter()
227231
def serviceName = beanName - LISTENER_CONTAINER_SUFFIX
228232
adapter.delegate = applicationContext.getBean(serviceName)
233+
adapter.messageConverter = rabbitTemplate.messageConverter
229234
bean.messageListener = adapter
230235

231236
// Now that the listener is properly configured, we can start it.

0 commit comments

Comments
 (0)