ibaralf
ibaralf

Reputation: 12518

Grails Config.groovy file read from a file

What's the best practice to do this? Basically I am using rabbitMQ and it has a setting for how many concurrent processes, I am deploying as WAR to a test server and would like to optimize this number of concurrents by simply changing the value and avoid making new WAR files each time.

I'm thinking reading a properties file that I can just change the value and restart server?

Ex: in my config.groovy file

rabbitmq {
    connectionfactory {
        username = 'groovy'
        password = 'groovy'
        hostname = 'localhost'

    }
    queues = {
        processTerritory exclusive: true
    }
    concurrentConsumers = **READ INTEGER VALUE FROM A FILE**
}

Upvotes: 3

Views: 1196

Answers (1)

rlovtang
rlovtang

Reputation: 5060

You can import external config files from Config.groovy. There is already commented out code in Config.groovy that shows how to do it:

grails.config.locations = [ "classpath:${appName}-config.properties",
                         "classpath:${appName}-config.groovy"]

Lets say your applications name is foo, you can now put foo-config.groovy or foo-config.properties somewhere on the classpath. For Tomcat you can put the file in the lib folder.

It's also covered in the user documentation

Then, in foo-config.groovy you can put:

rabbitmq.concurrentConsumers = 10

or whatever value is appropriate for that server.

Grails 3

Grails 3 does not include this feature by default, but you can use the external-config plugin

Upvotes: 2

Related Questions