Permalink
Browse files

Fix GPRABBITMQ-38: on reload, start any stopped listeners.

When a developer modifies an artifact that a message listener service depends
on, the message listener is re-registered in the application context. As we
are setting the autoStartup property to false, that means the listeners are
stopped but not restarted. After any class is reloaded, we now check for any
stopped listeners and start them if we find any.
  • Loading branch information...
1 parent 15adf43 commit 1cb08c56a84434b5c952b51583425da468ec47b5 @pledbrook pledbrook committed Nov 7, 2012
Showing with 24 additions and 5 deletions.
  1. +24 −5 RabbitmqGrailsPlugin.groovy
@@ -217,11 +217,8 @@ class RabbitmqGrailsPlugin {
}
containerBeans.each { beanName, bean ->
if(isServiceListener(beanName)) {
- def retryTemplate = applicationContext.rabbitRetryHandler.retryOperations
- def cache = new MapRetryContextCache()
- retryTemplate.retryContextCache = cache
- def missingIdAdvice = new MissingMessageIdAdvice(cache)
- bean.adviceChain = [missingIdAdvice, applicationContext.rabbitRetryHandler] as Advice[]
+ initialiseAdviceChain bean, applicationContext
+
// Now that the listener is properly configured, we can start it.
bean.start()
}
@@ -246,6 +243,19 @@ class RabbitmqGrailsPlugin {
startServiceListener(serviceGrailsClass.propertyName, evt.ctx)
}
}
+
+ // Other listener containers may have been stopped if they were
+ // affected by the re-registering of the changed class. For example,
+ // if the Rabbitmq consumer service directly or indirectly depends
+ // on a modified service. So we need to restart those that aren't
+ // running.
+ def containerBeans = applicationContext.getBeansOfType(SimpleMessageListenerContainer)
+ containerBeans.each { beanName, bean ->
+ if (!bean.running) {
+ initialiseAdviceChain bean, applicationContext
+ bean.start()
+ }
+ }
}
}
@@ -261,4 +271,13 @@ class RabbitmqGrailsPlugin {
def beanName = servicePropertyName + RabbitServiceConfigurer.LISTENER_CONTAINER_SUFFIX
applicationContext.getBean(beanName).start()
}
+
+ protected initialiseAdviceChain(listenerBean, applicationContext) {
+ def retryTemplate = applicationContext.rabbitRetryHandler.retryOperations
+ def cache = new MapRetryContextCache()
+ retryTemplate.retryContextCache = cache
+
+ def missingIdAdvice = new MissingMessageIdAdvice(cache)
+ listenerBean.adviceChain = [missingIdAdvice, applicationContext.rabbitRetryHandler] as Advice[]
+ }
}

0 comments on commit 1cb08c5

Please sign in to comment.