merge
This commit is contained in:
@@ -12,17 +12,17 @@ public class RabbitConstant {
|
||||
*/
|
||||
public static final String EMAIL_QUEUE = "email";
|
||||
/**
|
||||
* http请求队列
|
||||
* 短信队列
|
||||
*/
|
||||
public static final String HTTP_REQUEST_QUEUE = "http.request";
|
||||
public static final String MESSAGE_QUEUE = "message";
|
||||
/**
|
||||
* 邮件队列路由键(*表示一个词,#表示零个或多个词)
|
||||
*/
|
||||
public static final String EMAIL_ROUTING_KEY = "email.key";
|
||||
/**
|
||||
* http请求路由键
|
||||
* 短信队列路由键
|
||||
*/
|
||||
public static final String HTTP_REQUEST_ROUTING_KEY = "http.request.key";
|
||||
public static final String MESSAGE_ROUTING_KEY = "message.key";
|
||||
/**
|
||||
* 交换机
|
||||
*/
|
||||
|
||||
@@ -11,7 +11,7 @@ import javax.annotation.Resource;
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import static com.xwbing.rabbit.RabbitConstant.EMAIL_QUEUE;
|
||||
import static com.xwbing.rabbit.RabbitConstant.HTTP_REQUEST_QUEUE;
|
||||
import static com.xwbing.rabbit.RabbitConstant.MESSAGE_QUEUE;
|
||||
|
||||
/**
|
||||
* 项目名称: boot-module-demo
|
||||
@@ -40,13 +40,13 @@ public class Receiver {
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理http队列消息
|
||||
* 处理短信队列消息
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
@RabbitListener(queues = HTTP_REQUEST_QUEUE)
|
||||
public String processHttp(String[] msg) {
|
||||
String response = MessageFormat.format("收到{0}队列的消息:{1}", HTTP_REQUEST_QUEUE, msg);
|
||||
@RabbitListener(queues = MESSAGE_QUEUE)
|
||||
public String processMessage(String[] msg) {
|
||||
String response = MessageFormat.format("收到{0}队列的消息:{1}", MESSAGE_QUEUE, msg);
|
||||
return response.toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,12 +63,12 @@ public class Sender implements RabbitTemplate.ConfirmCallback, RabbitTemplate.Re
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送信息到http队列
|
||||
* 发送信息到message队列
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
public void sendHttpRequest(String[] msg) {
|
||||
send(msg, RabbitConstant.CONTROL_EXCHANGE, RabbitConstant.HTTP_REQUEST_ROUTING_KEY);
|
||||
public void sendMessage(String[] msg) {
|
||||
send(msg, RabbitConstant.CONTROL_EXCHANGE, RabbitConstant.MESSAGE_ROUTING_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,11 @@ import org.springframework.context.annotation.Configuration;
|
||||
*/
|
||||
@Configuration
|
||||
public class TopicExchangeConfig {
|
||||
//声明队列
|
||||
/**
|
||||
* 声明队列
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public Queue emailQueue() {
|
||||
return new Queue(RabbitConstant.EMAIL_QUEUE, true);//true表示持久化该队列
|
||||
@@ -23,16 +27,24 @@ public class TopicExchangeConfig {
|
||||
|
||||
@Bean
|
||||
public Queue httpRequestQueue() {
|
||||
return new Queue(RabbitConstant.HTTP_REQUEST_QUEUE, true);
|
||||
return new Queue(RabbitConstant.MESSAGE_QUEUE, true);
|
||||
}
|
||||
|
||||
//声明交换机
|
||||
/**
|
||||
* 声明交换机
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public TopicExchange topicExchange() {
|
||||
return new TopicExchange(RabbitConstant.CONTROL_EXCHANGE);
|
||||
}
|
||||
|
||||
//绑定
|
||||
/**
|
||||
* 绑定
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public Binding bindingEmail() {
|
||||
return BindingBuilder.bind(emailQueue()).to(topicExchange()).with(RabbitConstant.EMAIL_ROUTING_KEY);//*表示一个词,#表示零个或多个词
|
||||
@@ -40,6 +52,6 @@ public class TopicExchangeConfig {
|
||||
|
||||
@Bean
|
||||
public Binding bindingHttpRequest() {
|
||||
return BindingBuilder.bind(httpRequestQueue()).to(topicExchange()).with(RabbitConstant.HTTP_REQUEST_ROUTING_KEY);
|
||||
return BindingBuilder.bind(httpRequestQueue()).to(topicExchange()).with(RabbitConstant.MESSAGE_ROUTING_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class TestControl {
|
||||
|
||||
@GetMapping("send")
|
||||
public void send(@RequestParam String[] msg) {
|
||||
sender.sendHttpRequest(msg);
|
||||
sender.sendMessage(msg);
|
||||
}
|
||||
|
||||
@LogInfo("redis功能测试")
|
||||
|
||||
Reference in New Issue
Block a user