0

I am facing some errors in a spring boot project where I am using spring integration to connect to RabbitMQ. I am doing the configuration for RabbitMQ in XML files like this:

<!-- RabbitMQ configuration -->
<rabbit:connection-factory
        id="rabbitConnectionFactory_2"
        host="${queuing.events.host}"
        port="${queuing.events.port}"
        username="${queuing.events.username}"
        password="${queuing.events.password}"
        virtual-host="${queuing.events.virtual-host}"
        publisher-returns="true"/>

<rabbit:template id="amqpTemplate_2" connection-factory="rabbitConnectionFactory_2" />
<rabbit:admin id="rabbitAdmin_2" connection-factory="rabbitConnectionFactory_2"/>
<rabbit:listener-container connection-factory="rabbitConnectionFactory_2" auto-startup="true" requeue-rejected="false" />

<bean id="rabbitListenerContainerFactory_2" class="org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory">
    <property name="connectionFactory" ref="rabbitConnectionFactory_2"/>
</bean>
<!--  -->

But I am creating two of each component. How to set the primaries ones?

Now the problem comes here, I was using this version for spring cloud:

<spring-cloud.version>Dalston.SR2</spring-cloud.version>

And everything was working fine, but if I update the version to:

<spring-cloud.version>Edgware.RELEASE</spring-cloud.version>

This error is coming:

Description:

Parameter 0 of method rabbitSender in org.springframework.cloud.sleuth.zipkin2.sender.ZipkinRabbitSenderConfiguration required a single bean, but 2 were found:
- rabbitConnectionFactory: defined in null
- rabbitConnectionFactory_2: defined in null


Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

And the error comes because of this dependency:

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-sleuth-zipkin</artifactId>
    </dependency>

If I remove this dependency the error is not coming.

You can find an example project to reproduce this scenario. In the pom file you'll see this:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.9.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <spring-cloud.version>Dalston.SR2</spring-cloud.version> <!-- it works with this version-->
    <!-- <spring-cloud.version>Edgware.RELEASE</spring-cloud.version> -->  <!-- doesn't work with this version-->
</properties>

<dependencies>
    <!-- SPRING BOOT -->

    <!-- it fails because of this dependency in that we are using Edgware.RELEASE version -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-sleuth-zipkin</artifactId>
    </dependency>
    ...

https://github.com/fjmpaez911/spring-integration-zipkin-cloud

So I need to know how to set a primary configuration for RabbitMQ and in addition I think that could be an issue because this error only comes if I use this version Edgware.RELEASE

Am I missing something?

2 Answers2

1

fran, in Edgware.RELEASE the <artifactId>spring-cloud-sleuth-zipkin</artifactId> will resolve Zipkin 2 dependencies try using <artifactId> spring-cloud-starter-zipkin-legacy</artifactId> instead

HODEH
  • 111
  • 10
0

To define the primary connection factory for RabbitMQ in XML files, you can do something like this:

<!-- Here the primary connection -->
<bean id="rabbitConnectionFactory" primary="true" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
    <constructor-arg value="${spring.rabbitmq.host}"/>
    <property name="username" value="${spring.rabbitmq.username}"/>
    <property name="password" value="${spring.rabbitmq.password}"/>
    <property name="virtualHost" value="${spring.rabbitmq.virtual-host}"/>
</bean>

<!-- RabbitMQ configuration -->
<rabbit:connection-factory
        id="rabbitConnectionFactory_2"
        host="${queuing.events.host}"
        port="${queuing.events.port}"
        username="${queuing.events.username}"
        password="${queuing.events.password}"
        virtual-host="${queuing.events.virtual-host}"
        publisher-returns="true"/>

<rabbit:template id="amqpTemplate_2" connection-factory="rabbitConnectionFactory_2" />
<rabbit:admin id="rabbitAdmin_2" connection-factory="rabbitConnectionFactory_2"/>
<rabbit:listener-container connection-factory="rabbitConnectionFactory_2" auto-startup="true" requeue-rejected="false" />

<bean id="rabbitListenerContainerFactory_2" class="org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory">
    <property name="connectionFactory" ref="rabbitConnectionFactory_2"/>
</bean>
Leader
  • 11
  • 3