feat: 初始化
This commit is contained in:
+206
@@ -0,0 +1,206 @@
|
||||
package com.yida.data.rabbit.configure;
|
||||
|
||||
import com.yida.data.rabbit.constant.RabbitConstant;
|
||||
import com.yida.data.rabbit.util.RabbitUtil;
|
||||
import org.springframework.amqp.core.Binding;
|
||||
import org.springframework.amqp.core.BindingBuilder;
|
||||
import org.springframework.amqp.core.DirectExchange;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class RabbitConfigure {
|
||||
|
||||
@Bean
|
||||
public RabbitUtil rabbitUtil() {
|
||||
return new RabbitUtil();
|
||||
}
|
||||
|
||||
/**
|
||||
* 亲情电话交换机
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public DirectExchange telephoneExchange() {
|
||||
return new DirectExchange(RabbitConstant.TELEPHONE_EXCHANGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 亲情电话-套餐队列
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public Queue telephoneMealQueue() {
|
||||
return new Queue(RabbitConstant.TELEPHONE_MEAL_QUEUE, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 亲情电话-套餐交换机绑定
|
||||
*/
|
||||
@Bean
|
||||
public Binding telephoneMealBinding(@Qualifier("telephoneMealQueue") Queue queue,
|
||||
@Qualifier("telephoneExchange") DirectExchange exchange) {
|
||||
return BindingBuilder.bind(queue).to(exchange).with(RabbitConstant.TELEPHONE_MEAL_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 学生邀请队列
|
||||
*
|
||||
* @return org.springframework.amqp.core.Queue
|
||||
* @author ZYJ
|
||||
* @date 2021/8/25 11:00
|
||||
*/
|
||||
@Bean
|
||||
public Queue inviteImportQueue() {
|
||||
return new Queue(RabbitConstant.INVITE_IMPORT_QUEUE, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 学生邀请交换机
|
||||
*
|
||||
* @return org.springframework.amqp.core.DirectExchange
|
||||
* @author ZYJ
|
||||
* @date 2021/8/25 11:01
|
||||
*/
|
||||
@Bean
|
||||
public DirectExchange inviteImportExchange() {
|
||||
return new DirectExchange(RabbitConstant.INVITE_IMPORT_EXCHANGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 学生邀请队列和交换机绑定
|
||||
*
|
||||
* @param queue 学生邀请队列
|
||||
* @param exchange 学生邀请交换机
|
||||
* @return org.springframework.amqp.core.Binding
|
||||
* @author ZYJ
|
||||
* @date 2021/8/25 11:02
|
||||
*/
|
||||
@Bean
|
||||
public Binding inviteImportBinding(@Qualifier("inviteImportQueue") Queue queue,
|
||||
@Qualifier("inviteImportExchange") DirectExchange exchange) {
|
||||
return BindingBuilder.bind(queue).to(exchange).with(RabbitConstant.INVITE_IMPORT_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 图集点赞和取消赞队列
|
||||
*
|
||||
* @return org.springframework.amqp.core.Queue
|
||||
* @author ZYJ
|
||||
* @date 2021/9/7 11:30
|
||||
*/
|
||||
@Bean
|
||||
public Queue atlasLikeQueue() {
|
||||
return new Queue(RabbitConstant.ATLAS_LIKE_QUEUE, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 图集点赞和取消赞交换机
|
||||
*
|
||||
* @return org.springframework.amqp.core.DirectExchange
|
||||
* @author ZYJ
|
||||
* @date 2021/9/7 11:30
|
||||
*/
|
||||
@Bean
|
||||
public DirectExchange atlasLikeExchange() {
|
||||
return new DirectExchange(RabbitConstant.ATLAS_LIKE_EXCHANGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 图集点赞和取消赞绑定
|
||||
*
|
||||
* @param queue 图集点赞和取消赞队列
|
||||
* @param exchange 图集点赞和取消赞交换机
|
||||
* @return org.springframework.amqp.core.Binding
|
||||
* @author ZYJ
|
||||
* @date 2021/9/7 11:31
|
||||
*/
|
||||
@Bean
|
||||
public Binding atlasLikeBinding(@Qualifier("atlasLikeQueue") Queue queue,
|
||||
@Qualifier("atlasLikeExchange") DirectExchange exchange) {
|
||||
return BindingBuilder.bind(queue).to(exchange).with(RabbitConstant.ATLAS_LIKE_KEY);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 电子学生证定位队列
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public Queue cardLocationQueue() {
|
||||
return new Queue(RabbitConstant.CARD_810A_MSG_QUEUE, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 电子学生证交换机
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public DirectExchange cardExchange() {
|
||||
return new DirectExchange(RabbitConstant.CARD_EXCHANGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 电子学生证位置信息绑定
|
||||
*/
|
||||
@Bean
|
||||
public Binding cardLocationBinding(@Qualifier("cardLocationQueue") Queue queue,
|
||||
@Qualifier("cardExchange") DirectExchange exchange) {
|
||||
return BindingBuilder.bind(queue).to(exchange).with(RabbitConstant.CARD_810A_MSG_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 消息处理交换机
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public DirectExchange msgExchange() {
|
||||
return new DirectExchange(RabbitConstant.MSG_EXCHANGE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存系统通知队列
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public Queue msgNoticeSysSaveQueue() {
|
||||
return new Queue(RabbitConstant.MSG_NOTICE_SYS_SAVE_QUEUE, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存系统通知绑定
|
||||
*/
|
||||
@Bean
|
||||
public Binding msgNoticeSysSaveBinding(@Qualifier("msgNoticeSysSaveQueue") Queue queue,
|
||||
@Qualifier("msgExchange") DirectExchange exchange) {
|
||||
return BindingBuilder.bind(queue).to(exchange).with(RabbitConstant.MSG_NOTICE_SYS_SAVE_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* websocket消息消费队列
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public Queue msgWebsocketQueue() {
|
||||
return new Queue(RabbitConstant.MSG_WEBSOCKET_QUEUE, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* websocket消息消费绑定
|
||||
*/
|
||||
@Bean
|
||||
public Binding msgWebsocketBinding(@Qualifier("msgWebsocketQueue") Queue queue,
|
||||
@Qualifier("msgExchange") DirectExchange exchange) {
|
||||
return BindingBuilder.bind(queue).to(exchange).with(RabbitConstant.MSG_WEBSOCKET_KEY);
|
||||
}
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
package com.yida.data.rabbit.constant;
|
||||
|
||||
public interface RabbitConstant {
|
||||
|
||||
// 亲情电话交换机
|
||||
String TELEPHONE_EXCHANGE = "telephone_exchange";
|
||||
|
||||
// 亲情电话-套餐队列
|
||||
String TELEPHONE_MEAL_QUEUE = "telephone_meal_queue";
|
||||
|
||||
// 亲情电话-套餐绑定
|
||||
String TELEPHONE_MEAL_KEY = "telephone_meal_key";
|
||||
|
||||
/**
|
||||
* 学生邀请交换机
|
||||
*/
|
||||
String INVITE_IMPORT_EXCHANGE = "invite_import_exchange";
|
||||
|
||||
/**
|
||||
* 学生邀请队列
|
||||
*/
|
||||
String INVITE_IMPORT_QUEUE = "invite_import_queue";
|
||||
|
||||
/**
|
||||
* 学生邀请绑定key值
|
||||
*/
|
||||
String INVITE_IMPORT_KEY = "invite_import_key";
|
||||
|
||||
/**
|
||||
* 图集点赞和取消赞交换机
|
||||
*/
|
||||
String ATLAS_LIKE_EXCHANGE = "atlas_like_exchange";
|
||||
|
||||
/**
|
||||
* 图集点赞和取消赞队列
|
||||
*/
|
||||
String ATLAS_LIKE_QUEUE = "atlas_like_queue";
|
||||
|
||||
/**
|
||||
* 图集点赞和取消赞绑定key值
|
||||
*/
|
||||
String ATLAS_LIKE_KEY = "atlas_like_key";
|
||||
|
||||
/**
|
||||
* 微信公众号扫描回调交换机
|
||||
*/
|
||||
String WXPUBLIC_QR_EXCHANGE = "wxpublic_qr_exchange";
|
||||
/**
|
||||
* 区域后台绑定接收消息队列
|
||||
*/
|
||||
String AGENT_RECEIVE_MSG_QUEUE = "agent_receive_msg_queue";
|
||||
|
||||
/**
|
||||
* 区域后台绑定接收消息绑定
|
||||
*/
|
||||
String AGENT_RECEIVE_MSG_KEY = "agent_receive_msg_key";
|
||||
|
||||
/**
|
||||
* 访客邀请码队列
|
||||
*/
|
||||
String VISITOR_INVITE_CODE_QUEUE = "visitor_invite_code_queue";
|
||||
|
||||
/**
|
||||
* 访客邀请码绑定key
|
||||
*/
|
||||
String VISITOR_INVITE_CODE_KEY = "visitor_invite_code_key";
|
||||
|
||||
|
||||
/**
|
||||
* 电子学生证交换机
|
||||
*/
|
||||
String CARD_EXCHANGE = "card_exchange";
|
||||
|
||||
/**
|
||||
* 电子学生证接收定位消息队列
|
||||
*/
|
||||
String CARD_810A_MSG_QUEUE = "card_810a_msg_queue";
|
||||
|
||||
/**
|
||||
* 电子学生证接收定位消息绑定
|
||||
*/
|
||||
String CARD_810A_MSG_KEY = "card_810a_msg_key";
|
||||
|
||||
/**
|
||||
* 处理消息交换机
|
||||
*/
|
||||
String MSG_EXCHANGE = "msg_exchange";
|
||||
|
||||
/**
|
||||
* 系统通知保存队列
|
||||
*/
|
||||
String MSG_NOTICE_SYS_SAVE_QUEUE = "msg_notice_sys_save_queue";
|
||||
/**
|
||||
* 系统通知保存 绑定key
|
||||
*/
|
||||
String MSG_NOTICE_SYS_SAVE_KEY = "msg_notice_sys_save_key";
|
||||
|
||||
/**
|
||||
* websocket推送消息队列
|
||||
*/
|
||||
String MSG_WEBSOCKET_QUEUE = "msg_websocket_queue";
|
||||
|
||||
/**
|
||||
* websocket推送队列与交换机绑定key
|
||||
*/
|
||||
String MSG_WEBSOCKET_KEY = "msg_websocket_key";
|
||||
|
||||
/**
|
||||
* 企业微信处理交换机
|
||||
*/
|
||||
String QYWX_HANDLE_EXCHANGE = "qywx_handle_exchange";
|
||||
|
||||
/**
|
||||
* 企业微信处理队列
|
||||
*/
|
||||
String QYWX_HANDLE_QUEUE = "qywx_handle_queue";
|
||||
|
||||
/**
|
||||
* 企业微信处理绑定key值
|
||||
*/
|
||||
String QYWX_HANDLE_KEY = "qywx_handle_key";
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.yida.data.rabbit.util;
|
||||
|
||||
import org.springframework.amqp.core.AmqpTemplate;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.core.MessageBuilder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Component
|
||||
public class RabbitUtil {
|
||||
@Resource
|
||||
private AmqpTemplate amqpTemplate;
|
||||
|
||||
public void sendMsg(String exchange, String key, String msg) {
|
||||
amqpTemplate.send(exchange, key, MessageBuilder.withBody(msg.getBytes()).build());
|
||||
}
|
||||
|
||||
public void sendMsg(String exchange, String key, Message msg) {
|
||||
amqpTemplate.send(exchange, key, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* mq发送消息方法
|
||||
*
|
||||
* @param exchange 交换机
|
||||
* @param routingKey routingKey值
|
||||
* @param msg 发送的消息, 对象必须实现序列化接口
|
||||
* @author ZYJ
|
||||
* @date 2021/9/7 10:50
|
||||
*/
|
||||
public void convertAndSendMsg(String exchange, String routingKey, Object msg) {
|
||||
amqpTemplate.convertAndSend(exchange, routingKey, msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
# Auto Configure
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.yida.data.rabbit.configure.RabbitConfigure
|
||||
Reference in New Issue
Block a user