我正在尝试使用基于XML而不是配置文件来实现Spring RabbitMq。消息被发送(我可以在RabbitMQ管理管理中看到它),但消费者不打印任何输出。消费者已初始化(可确认调用构造函数)。能告诉我以下问题:
rabbitConfiguration.xml :
<rabbit:connection-factory id="connectionFactory" host="localhost" username="guest" password="guest" />
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory" exchange="my.exchange" routing-key="my.test.1" />
<rabbit:admin connection-factory="connectionFactory" />
<rabbit:queue id="myQueue" name="my.queue" />
<rabbit:topic-exchange id="myExchange" name="my.exchange">
<rabbit:bindings>
<rabbit:binding queue="myQueue" pattern="my.#.*">
</rabbit:binding>
</rabbit:bindings>
</rabbit:topic-exchange>
<rabbit:listener-container id="myListenerContainer" connection-factory="connectionFactory" >
<rabbit:listener ref="aListener" method="printer" queues="myQueue"/>
</rabbit:listener-container>
<bean id="aListener" class="rabbitmq.MyReceiver" />
rabbitmq.MyReceiver.java
Public class MyReceiver {
public MyReceiver() {
System.out.println("init..");
}
public void printer(String msg){
System.out.println("message: " + msg);
}
}
以下是不同类别中的制作人代码:
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("rabbitConfiguration.xml");//loading beans
RabbitTemplate rb = (RabbitTemplate) context.getBean("amqpTemplate");
rb.convertAndSend("blah balh");
context.close();