如何在一个Spring应用程序上下文中声明2个不同的rabbitMQ

如何在一个Spring应用程序上下文中声明2个不同的rabbitMQ,spring,rabbitmq,amqp,Spring,Rabbitmq,Amqp,我在localhost:5672和localhost:5676上有两个不同的RabbitMQ实例。 我还在我的应用程序上下文中配置了它: <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instanc

我在localhost:5672和localhost:5676上有两个不同的RabbitMQ实例。 我还在我的应用程序上下文中配置了它:

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:rabbit="http://www.springframework.org/schema/rabbit"
   xsi:schemaLocation=
   "http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd" 
   xmlns:cache="http://www.springframework.org/schema/cache">

<bean id="rabbitConnectionFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
    <property name="username" value="${rabbit.username}"/>
    <property name="password" value="${rabbit.password}"/>
    <property name="host" value="${rabbit.host}"/>
    <property name="port" value="${rabbit.port}"/>
</bean>

<bean id="amqpTemplate" class="org.springframework.amqp.rabbit.core.RabbitTemplate">
    <property name="connectionFactory" ref="rabbitConnectionFactory"/>
    <property name="exchange" value="${rabbit.exchange}"/>
    <property name="routingKey" value="${rabbit.routing-key}"/>
    <property name="queue" value="${rabbit.queue}"/>
</bean>

<bean id="admin" class="org.springframework.amqp.rabbit.core.RabbitAdmin">
    <constructor-arg ref="rabbitConnectionFactory" />
</bean>

<bean id="rabbitTxManager"
      class="org.springframework.amqp.rabbit.transaction.RabbitTransactionManager">
    <property name="connectionFactory" ref="rabbitConnectionFactory"/>
</bean>

<bean id="messageListenerContainer" class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer">
    <property name="channelTransacted" value="true"/>
    <property name="transactionManager" ref="rabbitTxManager"/>
    <property name="prefetchCount" value="${rabbit.prefetchCount}"/>
    <property name="txSize" value="${rabbit.txSize}"/>
    <property name="connectionFactory" ref="rabbitConnectionFactory"/>
    <property name="messageListener" ref="handler"/>
    <property name="queueNames" value="${rabbit.queue}"/>
    <property name="concurrentConsumers" value="${rabbit.concurrentConsumers}"/>
    <property name="errorHandler" ref="errorHandler"/>
</bean>

<bean id="handler" class="com.pb.pav.timingbus.amqp.MessageHandler" >
    <constructor-arg index="0" ref="gson"/>
    <constructor-arg index="1" ref="sender"/>
</bean>

<bean id="errorHandler" class="com.pb.pav.timingbus.amqp.ExceptionHandler"/>

<bean id="gson" factory-bean="formattedBuilder" factory-method="create" />

<bean id="gsonBuilder" class="com.google.gson.GsonBuilder" />

<bean id="formattedBuilder" factory-bean="gsonBuilder" factory-method="setDateFormat"> 
    <constructor-arg index="0" value="yyyy-MM-dd HH:mm:ss.SSS"/>
</bean>

<bean id="sender" class="com.pb.timing.client.TimingWSClient">
    <constructor-arg index="0" value="${timing.url}"/>
</bean>

<bean id="busService" class="com.pb.pav.timingbus.BusService" />

<bean id="answerConnFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
    <property name="username" value="guest"/>
    <property name="password" value="guest"/>
    <property name="host" value="localhost"/>
    <property name="port" value="5676"/>
    <property name="channelCacheSize" value="2"/>
</bean>

<bean id="rabbitAnswer" class="org.springframework.amqp.rabbit.core.RabbitTemplate">
    <property name="connectionFactory" ref="answerConnFactory"/>
    <property name="exchange" value="timinganswers"/>
    <property name="routingKey" value="temp"/>
    <property name="queue" value="temp"/>
</bean>

<bean id="answerAdmin" class="org.springframework.amqp.rabbit.core.RabbitAdmin">
    <constructor-arg ref="answerConnFactory" />
</bean>

<bean id="mesSender" class="com.pb.pav.timingbus.amqp.MessageSender" >
    <constructor-arg index="0" ref="gson"/>
    <constructor-arg index="1" ref="rabbitAnswer"/>
</bean>

我的SpringWeb应用程序向兔子(localhost:5672,id=“amqpmetplate”)生成消息,然后从队列消费并保存到数据库

保存到DB应用程序后,生成答案(确定或错误),我需要将答案发布到第二个rabbitMQ(localhost:5676,id=“rabbitAnswer”)

当我尝试将答案发布到第二只兔子(localhost:5676,id=“rabbitAnswer”)时,他们将答案发布到第一只兔子,我不明白为什么???在发送消息之前,我正在记录连接端口,它是正确的-5676,但应用程序将消息发送到5672


我怀疑问题出在频道上,因为在第二只兔子时,我没有看到任何打开的频道。那么,我如何才能向我的第二只兔子声明不同的频道,并以正确的方式发送消息呢

我建议你将你的问题格式化,使阅读更容易。