How to set rabbitmq connection properties using JNDI variables in Spring xml config?

lotk

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..

lotk

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to set rabbitmq connection properties using JNDI variables in Spring xml config?

From Dev

How to set local config properties with Spring Config Service

From Dev

how to set prefetch when using spring rabbitmq

From Dev

how to set prefetch when using spring rabbitmq

From Dev

How to use variables in RabbitMQ Config file for LDAP

From Dev

How to set Consistency Level in Spring Data Cassandra XML config

From Dev

Spring-Boot > Setting application.properties using JNDI

From Dev

Spring-Boot > Setting application.properties using JNDI

From Dev

how to set ActiveMQ connection username and password through JNDI

From Dev

How to close JNDI connection?

From Dev

How to close JNDI connection?

From Dev

How to set custom connection properties on DataSource in Spring Boot 1.3.x with default Tomcat connection pool

From Dev

How can I obtain the DataSource connection through the JNDI name in Spring?

From Dev

How to monitor amqp/rabbitMQ connection with Spring?

From Dev

Unmarshalling error whan using CXF with Spring Java Config, when some extra properties are sent (but no error when using XML config)

From Dev

How to connect to MongoDB on CloudBees using Spring Data (XML config)?

From Dev

Spring Loading all JNDI Properties

From Dev

How to setup multiple topics in a RabbitMQ Java config class using Spring Framework?

From Dev

How to get jndi environment variables with junit test in Spring?

From Dev

How to get jndi environment variables with junit test in Spring?

From Dev

Spring inject xml values to properties-config.xml then to a bean

From Dev

How to set the Profile using application.properties in Spring?

From Dev

I am using rabbitmq in Spring framework, how to call basicRecover on connection create?

From Dev

How to config DataSource in Spring through beans in XML instead of application.properties?

From Dev

How to set useUnicode=true and characterEncoding=utf8 properties on Spring-managed MySQL JDBC connection

From Dev

Howto use JNDI database connection with Spring Boot and Spring Data using embedded Tomcat?

From Dev

Setting Message Properties using Spring Cloud Stream with RabbitMQ

From Dev

set message persistence in rabbitmq.xml file in spring

From Java

spring boot : How to set spring properties dynamically

Related Related

  1. 1

    How to set rabbitmq connection properties using JNDI variables in Spring xml config?

  2. 2

    How to set local config properties with Spring Config Service

  3. 3

    how to set prefetch when using spring rabbitmq

  4. 4

    how to set prefetch when using spring rabbitmq

  5. 5

    How to use variables in RabbitMQ Config file for LDAP

  6. 6

    How to set Consistency Level in Spring Data Cassandra XML config

  7. 7

    Spring-Boot > Setting application.properties using JNDI

  8. 8

    Spring-Boot > Setting application.properties using JNDI

  9. 9

    how to set ActiveMQ connection username and password through JNDI

  10. 10

    How to close JNDI connection?

  11. 11

    How to close JNDI connection?

  12. 12

    How to set custom connection properties on DataSource in Spring Boot 1.3.x with default Tomcat connection pool

  13. 13

    How can I obtain the DataSource connection through the JNDI name in Spring?

  14. 14

    How to monitor amqp/rabbitMQ connection with Spring?

  15. 15

    Unmarshalling error whan using CXF with Spring Java Config, when some extra properties are sent (but no error when using XML config)

  16. 16

    How to connect to MongoDB on CloudBees using Spring Data (XML config)?

  17. 17

    Spring Loading all JNDI Properties

  18. 18

    How to setup multiple topics in a RabbitMQ Java config class using Spring Framework?

  19. 19

    How to get jndi environment variables with junit test in Spring?

  20. 20

    How to get jndi environment variables with junit test in Spring?

  21. 21

    Spring inject xml values to properties-config.xml then to a bean

  22. 22

    How to set the Profile using application.properties in Spring?

  23. 23

    I am using rabbitmq in Spring framework, how to call basicRecover on connection create?

  24. 24

    How to config DataSource in Spring through beans in XML instead of application.properties?

  25. 25

    How to set useUnicode=true and characterEncoding=utf8 properties on Spring-managed MySQL JDBC connection

  26. 26

    Howto use JNDI database connection with Spring Boot and Spring Data using embedded Tomcat?

  27. 27

    Setting Message Properties using Spring Cloud Stream with RabbitMQ

  28. 28

    set message persistence in rabbitmq.xml file in spring

  29. 29

    spring boot : How to set spring properties dynamically

HotTag

Archive