Skip to content

Commit

Permalink
Implemented connection pooling as suggested in this post: padcom/grai…
Browse files Browse the repository at this point in the history
  • Loading branch information
kenschwartz committed Feb 23, 2015
1 parent 41058bd commit d3891a4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
39 changes: 28 additions & 11 deletions RoutingGrailsPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.springframework.beans.factory.config.MethodInvokingFactoryBean
import javax.activation.DataHandler

class RoutingGrailsPlugin {
def version = '1.3.3.3'
def version = '1.3.3.6'
def grailsVersion = '2.0.0 > *'
def loadAfter = ['controllers', 'services']
def artefacts = [new RouteArtefactHandler()]
Expand All @@ -35,10 +35,26 @@ class RoutingGrailsPlugin {
def trace = config?.trace ?: false
def routeClasses = application.routeClasses

jmsConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) {
brokerURL = config?.brokerURL ?: 'vm://LocalBroker'
userName = config?.userName ?: ''
password = config?.password ?: ''
}

pooledConnectionFactory(org.apache.activemq.pool.PooledConnectionFactory) { bean ->
bean.initMethod = 'start'
bean.destroyMethod = 'stop'
maxConnections = config?.maxConnections ?: 8
connectionFactory = ref('jmsConnectionFactory')
}

jmsConfig(org.apache.camel.component.jms.JmsConfiguration) {
connectionFactory = ref('pooledConnectionFactory')
concurrentConsumers = config?.concurrentConsumers ?: 10
}

activemq(org.apache.activemq.camel.component.ActiveMQComponent) {
brokerURL = config.brokerURL ?: 'vm://LocalBroker'
userName = config.userName ?: ''
password = config.password ?: ''
configuration = ref('jmsConfig')
}

initializeRouteBuilderHelpers()
Expand All @@ -64,11 +80,11 @@ class RoutingGrailsPlugin {
// this may cause problems if autostarted camel start invoking routes which calls service/controller
// methods, which use dynamically injected methods
// because doWithDynamicMethods is called after doWithSpring
camel.camelContext(id: camelContextId,
useMDCLogging: useMDCLogging,
autoStartup: false,
streamCache: streamCache,
trace: trace) {
camel.camelContext(id: camelContextId,
useMDCLogging: useMDCLogging,
autoStartup: false,
streamCache: streamCache,
trace: trace) {
def threadPoolProfileConfig = config?.defaultThreadPoolProfile

camel.threadPoolProfile(
Expand Down Expand Up @@ -98,9 +114,10 @@ class RoutingGrailsPlugin {

// otherwise we autostart camelContext here
def config = application.config.grails.routing
def autoStartup = config?.autoStartup ?: true

if (config.autoStartup != false) {
def camelContextId = config.camelContextId ?: 'camelContext'
if (autoStartup != false) {
def camelContextId = config?.camelContextId ?: 'camelContext'
application.mainContext.getBean(camelContextId).start()
}
}
Expand Down
4 changes: 2 additions & 2 deletions grails-app/conf/BuildConfig.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ grails.project.fork = [
]

grails.project.repos.default = "kmsRepo"
grails.project.repos.kmsRepo.url = "https://wiki.wikigood.com/artifactory/plugins-release-local"
grails.project.repos.kmsRepo.url = "http://wiki.wikigood.com/artifactory/plugins-release-local"
grails.project.repos.kmsRepo.type = "maven"
grails.project.repos.kmsRepo.username = "admin"
grails.project.repos.kmsRepo.password = "xxxxx"
grails.project.repos.kmsRepo.password = ''

grails.project.dependency.resolver = "maven" // or ivy

Expand Down

0 comments on commit d3891a4

Please sign in to comment.