gpc / jms

JMS integration for Grails.
http://grails.org/plugin/jms
16 stars 28 forks source link

The context startup does not take into account the setting of `auto-startup` to false. #56

Closed jindalshivali closed 6 months ago

jindalshivali commented 7 months ago

Steps to reproduce:

Define a listener bean:

eventListenerContainer {
            concurrentConsumers = 10
            autoStartup = false
            connectionFactoryBean = "jmsConnectionFactory"
            messageSelector = null
            cacheLevel = 0
        }

When the application server starts, the eventListenerContainer is already running (isActive=true, and isRunning=true but autoStartup=false)

This seems to be because the plugin code calls the start() method on all the listener containers during application Context start irrespective of whether or not the autoStartup field is set to true.

It looks like the code in below file https://github.com/gpc/jms/blob/master/src/main/groovy/grails/plugin/jms/JmsGrailsPlugin.groovy Method

doWithApplicationContext():

 void doWithApplicationContext() {
        listenerConfigs.each { serviceClassName, serviceClassListenerConfigs ->
            serviceClassListenerConfigs.each {
                startListenerContainer(it, applicationContext)
            }
        }

The code above starts all the containers irrespective of the autoStartup property.

jindalshivali commented 7 months ago

Currently, when the startListenerContainer() method is invoked, below is what happens.

    def startListenerContainer(listenerConfig, applicationContext) {
        applicationContext.getBean(listenerConfig.listenerContainerBeanName).start()
    }

Instead the code should be as below:

    def startListenerContainer(listenerConfig, applicationContext) {
        def listenerContainer = applicationContext.getBean(listenerConfig.listenerContainerBeanName)

        if (listenerContainer.isAutoStartup()) {
            listenerContainer.start()
        }
    }
codeconsole commented 7 months ago

@jindalshivali can you submit a pull request?

jindalshivali commented 7 months ago

We have a forked version of the repo which is currently being used after the fix in our application. Will submit a PR.

jindalshivali commented 7 months ago

Added the PR to the issue.

codeconsole commented 6 months ago

https://github.com/gpc/jms/pull/57