I have an application in Spring with is using RabbitMQ. I'm using xml based context configuration and rabbit namespace in this xml. So far it looked as this:
<rabbit:connection-factory id="rabbitConnectionFactory" host="localhost" port="5672"/>
but now I want to use JNDI variables for host and port properties. I know how to use JNDI when I have "classic" bean definitions but I have know idea how to use JNDI and rabbit namespace at the same time. I wasn't able to define any child elements of rabbit:connection element. I get an error saying that it can't have any child nodes.
Any help appreciated :)
EDIT This is how I use JNDI lookup in "standard" beans (with no special namespace)
<bean id="connector" class="com.foo.ConnectionProvider">
<constructor-arg name="url">
<jee:jndi-lookup expected-type="java.lang.String" jndi-name="java:comp/env/service/url"/>
</constructor-arg>
</bean>
And in META-INF/context.xml:
<ResourceLink name="service/url" global="service/url" type="java.lang.String"/>
But as I said I don't know how to accomplish it using rabbit namespace. Have tried googling with no success..
I figured out I can use "standard" bean definition. I'm not completely happy with the solution, but at least, it works.
<bean id="rabbitConnectionFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
<constructor-arg name="hostname" >
<jee:jndi-lookup expected-type="java.lang.String"
jndi-name="java:comp/env/rabbit/host"/>
</constructor-arg>
<constructor-arg name="port" >
<jee:jndi-lookup expected-type="java.lang.Integer"
jndi-name="java:comp/env/rabbit/port"/>
</constructor-arg>
<property name="username" value="guest"/>
<property name="password" value="guest"/>
</bean>
<rabbit:template id="amqpTemplate" connection-factory="rabbitConnectionFactory" exchange="mcs-notifications.topic"/>
<rabbit:admin connection-factory="rabbitConnectionFactory"/>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments