在PCS项目:
talking 发送队列
1.1 创建
@Bean
public Queue orderTakingQueue() {
return createQueue(orderTakingQueueName);
}
1.2 绑定
@Bean
public Binding orderTakingQueueBinding(Queue orderTakingQueue, DirectExchange orderExchange) {
return BindingBuilder.bind(orderTakingQueue).to(orderExchange).with(orderTakingQueueName);
}
1.3 发送
public String getOrderTakingQueueName() {
return orderTakingQueueName;
}
@Override
public void sendOrderInfo(String orderInfo) {
System.out.println("Send order info to MQ: " + orderInfo);
rabbitTemplate.convertAndSend(mqConfig.getOrderExchangeName(), mqConfig.getOrderTakingQueueName(), orderInfo);
}
2.order 接受队列
2.1 创建
@Bean
public Queue orderTakingQueue() {
return createQueue(orderTakingQueueName);
}
2.2 绑定
@Bean
public Binding orderTakingQueueBinding(Queue orderTakingQueue, DirectExchange orderExchange) {
Binding binding = BindingBuilder.bind(orderTakingQueue).to(orderExchange).with(orderTakingQueueName);
return binding;
}
2.3 接受监听(方法)
@Bean
public SimpleMessageListenerContainer pkgQueueListenerContainer(ConnectionFactory connectionFactory,MessageReceiver messageReceiver)
{
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.setQueueNames(orderTakingQueueName);
container.setMessageListener(new MessageListenerAdapter(messageReceiver, "receiveOrderInfo"));
container.setConcurrentConsumers(32);
container.setPrefetchCount(20);
return container;
}