|
@@ -1,37 +1,15 @@
|
|
package org.example.lc.config;
|
|
package org.example.lc.config;
|
|
|
|
|
|
import org.springframework.amqp.core.Queue;
|
|
import org.springframework.amqp.core.Queue;
|
|
-import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
|
|
|
-import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
|
|
|
-import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
|
|
|
+import org.springframework.amqp.core.QueueBuilder;
|
|
|
|
+import org.springframework.amqp.core.TopicExchange;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
-import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Configuration;
|
|
-import org.springframework.context.annotation.Scope;
|
|
|
|
|
|
|
|
@Configuration
|
|
@Configuration
|
|
public class RabbitConfig {
|
|
public class RabbitConfig {
|
|
|
|
|
|
-
|
|
|
|
- @Value("${rabbitmq.host}")
|
|
|
|
- private String host;
|
|
|
|
-
|
|
|
|
- @Value("${rabbitmq.port}")
|
|
|
|
- private int port;
|
|
|
|
-
|
|
|
|
- @Value("${rabbitmq.username}")
|
|
|
|
- private String username;
|
|
|
|
-
|
|
|
|
- @Value("${rabbitmq.password}")
|
|
|
|
- private String password;
|
|
|
|
-
|
|
|
|
- @Value("${rabbitmq.publisher-confirms}")
|
|
|
|
- private boolean publisherConfirm;
|
|
|
|
-
|
|
|
|
- @Value("${rabbitmq.virtual-host}")
|
|
|
|
- private String virtualHost;
|
|
|
|
-
|
|
|
|
@Value("${queue.name.apply}")
|
|
@Value("${queue.name.apply}")
|
|
private String applyQueue;
|
|
private String applyQueue;
|
|
|
|
|
|
@@ -71,24 +49,11 @@ public class RabbitConfig {
|
|
return new Queue(quitQueue);
|
|
return new Queue(quitQueue);
|
|
}
|
|
}
|
|
|
|
|
|
- @Bean
|
|
|
|
- public ConnectionFactory connFactory() {
|
|
|
|
- CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
|
|
|
|
- connectionFactory.setHost(host);
|
|
|
|
- connectionFactory.setPort(port);
|
|
|
|
- connectionFactory.setUsername(username);
|
|
|
|
- connectionFactory.setPassword(password);
|
|
|
|
- connectionFactory.setVirtualHost(virtualHost);
|
|
|
|
- connectionFactory.setPublisherConfirms(publisherConfirm); //必须要设置
|
|
|
|
- return connectionFactory;
|
|
|
|
- }
|
|
|
|
|
|
|
|
@Bean
|
|
@Bean
|
|
- @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
|
|
|
- //必须是prototype类型
|
|
|
|
- public RabbitTemplate rabbitTemplate() {
|
|
|
|
- RabbitTemplate template = new RabbitTemplate(connFactory());
|
|
|
|
- return template;
|
|
|
|
|
|
+ TopicExchange exchange() {
|
|
|
|
+ return new TopicExchange("exchange");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
}
|
|
}
|