https://gitee.com/liyghting/springrabbitmqdemo
基于spring启动的时候加载发布订阅配置,发送基于json的消息。
step1:实现Spring接口
step2:生产者配置信息Spring的Bean生成
?
具体代码请看RabbitmqConfig.java
?
class="line">rabbitmqProducerMap: testProducer1: exchangeName: testExchange routingKey: test1 producerBeanName: test1Producer testProducer2: exchangeName: testExchange routingKey: test2 producerBeanName: test2Producer
ProducerUtil.send("test1Producer", user);
具体请看TestProducer.java
rabbitmqBindingMap: test1Binding: queueName: test1Queue exchangeName: testExchange routingKey: test1 consumerBeanName: test1Consumer test2Binding: queueName: test2Queue exchangeName: testExchange routingKey: test2 consumerBeanName: test2Consumer
@Override
public ParameterizedTypeReference<ReceiveUser> getParameterizedTypeReference() {
return new ParameterizedTypeReference<ReceiveUser>() {
};
}
@Override
public void handleMsg(ReceiveUser msg) {
logger.info("Test1Consumer " + msg);
}
具体请看Test1Consumer.java