user1325126
user1325126

Reputation: 33

ActiveMQ configuration and Spring Expression Language (SpEL)

I have to start multiple instances (separate JVMs) of this one service on the same machine which has a persistent embedded broker. All config files are pre-generated and have their variable substitutions done on compilation way before the services start. I'm having problems with several instances trying to get a lock of AMQ data directory and KahaDB, obviously the 1st instance successfully gets the lock and the rest keep on trying unsuccessfully.

I need to set something like this:

. . .
<amq:broker dataDirectory="${activemq.directory}/data" id="broker" persistent="true" useJmx="false" >
. . .

I tried PropertyPlaceholderConfigurer but as I understand it loads the properties from a file specified in Spring configuration and at the time it starts up is too late already. I'm trying to use Spring Expression Language so I end up with something like this:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:jms="http://www.springframework.org/schema/jms"
       xmlns:amq="http://activemq.apache.org/schema/core"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/context
                           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                           http://www.springframework.org/schema/jms
                           http://www.springframework.org/schema/jms/spring-jms-3.0.xsd
                           http://activemq.apache.org/schema/core
                           http://activemq.apache.org/schema/core/activemq-core-5.5.0.xsd">


    <!--  Embedded ActiveMQ Broker         -->
    <amq:broker dataDirectory="#{systemProperties['activemq.directory']}/data" id="broker" persistent="true" useJmx="false" >
   ... 

I pass on the command line

-Dactivemq.directory=<my-directory>

On the log I see

 nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named '{systemProperties['activemq.directory']}/data' is defined

Does it seem like I'm missing something with AMQ and Spring3 SpEL? Is there some other solution to that does the same think I may be missing?

Upvotes: 0

Views: 918

Answers (2)

Nagy &#193;kos
Nagy &#193;kos

Reputation: 21

1. A very nasty, (but at least working) solution is to put a white space to the beginning if you want to use PropertyPlaceholderConfigurer.

<amq:broker useJmx="false" persistent="false">
  <amq:transportConnectors>
    <amq:transportConnector uri=" #{myconf.getConfigurationValue('JMS_URI')}" />
  </amq:transportConnectors>
</amq:broker>

myconf.properties: JMS_URI=tcp://localhost:0?daemon=false

2. What is also interesting that if you explicitly set at least the protocol, then it also works:

<amq:broker useJmx="false" persistent="false">
  <amq:transportConnectors>
    <amq:transportConnector uri="tcp://#{myconf.getConfigurationValue('JMS_URI')}" />
  </amq:transportConnectors>
</amq:broker>

myconf.properties: JMS_URI=localhost:0?daemon=false

Upvotes: 2

user1325126
user1325126

Reputation: 33

I ended up using simply the good old PropertyPlaceholderConfigurer and removing the SpEL notation, it works like a charm.

Upvotes: 0

Related Questions