|
@@ -1,57 +0,0 @@
|
|
|
-package com.diagbot.config;
|
|
|
-
|
|
|
-
|
|
|
-import com.diagbot.rabbit.Receiver;
|
|
|
-import org.springframework.amqp.core.Binding;
|
|
|
-import org.springframework.amqp.core.BindingBuilder;
|
|
|
-import org.springframework.amqp.core.Queue;
|
|
|
-import org.springframework.amqp.core.TopicExchange;
|
|
|
-import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
|
|
-import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
|
|
|
-import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
|
|
|
-import org.springframework.context.annotation.Bean;
|
|
|
-import org.springframework.context.annotation.Configuration;
|
|
|
-
|
|
|
-/**
|
|
|
- * @Description: 消息消费者配置
|
|
|
- * @author: gaodm
|
|
|
- * @time: 2018/8/1 14:59
|
|
|
- */
|
|
|
-@Configuration
|
|
|
-public class RabbitConfig {
|
|
|
-
|
|
|
-
|
|
|
- public final static String queueName = "spring-boot";
|
|
|
-
|
|
|
- @Bean
|
|
|
- Queue queue() {
|
|
|
- return new Queue(queueName, false);
|
|
|
- }
|
|
|
-
|
|
|
- @Bean
|
|
|
- TopicExchange exchange() {
|
|
|
- return new TopicExchange("spring-boot-exchange");
|
|
|
- }
|
|
|
-
|
|
|
- @Bean
|
|
|
- Binding binding(Queue queue, TopicExchange exchange) {
|
|
|
- return BindingBuilder.bind(queue).to(exchange).with(queueName);
|
|
|
- }
|
|
|
-
|
|
|
- @Bean
|
|
|
- SimpleMessageListenerContainer container(ConnectionFactory connectionFactory,
|
|
|
- MessageListenerAdapter listenerAdapter) {
|
|
|
- SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
|
|
|
- container.setConnectionFactory(connectionFactory);
|
|
|
- container.setQueueNames(queueName);
|
|
|
- container.setMessageListener(listenerAdapter);
|
|
|
- return container;
|
|
|
- }
|
|
|
-
|
|
|
- @Bean
|
|
|
- MessageListenerAdapter listenerAdapter(Receiver receiver) {
|
|
|
- return new MessageListenerAdapter(receiver, "receiveMessage");
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-}
|