4 changed files with 175 additions and 177 deletions
@ -1,130 +1,130 @@ |
|||
package com.ccsens.util.config; |
|||
|
|||
import cn.hutool.core.util.StrUtil; |
|||
import com.ccsens.util.PropUtil; |
|||
import org.springframework.amqp.core.Binding; |
|||
import org.springframework.amqp.core.BindingBuilder; |
|||
import org.springframework.amqp.core.FanoutExchange; |
|||
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 RabbitMQConfig { |
|||
private static final String RabbitMQ_QUEUE_NAME = "Queue_Anyring"; |
|||
private static final String TALL_MESSAGE_1 = "tall_message_1"; |
|||
private static final String TALL_MESSAGE_2 = "tall_message_2"; |
|||
public static final String GAME_STATUS = PropUtil.gameMqName; |
|||
|
|||
public static final String WISDOM_CAR = "wisdom_car"; |
|||
public static final String WISDOM_CAR_2 = "wisdom_car2"; |
|||
|
|||
public static final String BENEFICIATION = "beneficiation"; |
|||
|
|||
|
|||
private static final String GAME_STATUS_DELAY_SEND_QUEUE = "gameStatusDelaySendQueue"; |
|||
private static final String GAME_STATUS_DELAY_SEND_EXCHANGE = "gameStatusDelaySendExchange"; |
|||
private static final String GAME_STATUS_DELAY_SEND_ROUTING_KEY = "gameStatusDelaySendRoutingKey"; |
|||
|
|||
// private static final String GAME_MQ_A = "GAME_MQ_A";
|
|||
|
|||
|
|||
/**消息队列发送*/ |
|||
public static final String MESSAGE_QUEUE_NAME = "tall_message_1"; |
|||
/**游戏计算分数*/ |
|||
public static final String GAME_SCORE = "game_score"; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
@Bean |
|||
public Queue queueGame(){ |
|||
return new Queue(PropUtil.gameMqName); |
|||
} |
|||
|
|||
@Bean |
|||
public Queue queue(){ |
|||
return new Queue(RabbitMQ_QUEUE_NAME); |
|||
} |
|||
@Bean |
|||
public Queue queue1(){ |
|||
return new Queue(TALL_MESSAGE_1); |
|||
} |
|||
@Bean |
|||
public Queue queue2(){ |
|||
return new Queue(TALL_MESSAGE_2); |
|||
} |
|||
|
|||
@Bean |
|||
public Queue queue3(){ |
|||
return new Queue(GAME_SCORE); |
|||
} |
|||
|
|||
@Bean |
|||
public Queue wisdomCar(){ |
|||
return new Queue(WISDOM_CAR); |
|||
} |
|||
|
|||
@Bean |
|||
public Queue wisdomCar2(){ |
|||
return new Queue(WISDOM_CAR_2); |
|||
} |
|||
|
|||
|
|||
@Bean |
|||
public Queue beneficiation(){ |
|||
return new Queue(BENEFICIATION); |
|||
} |
|||
//package com.ccsens.util.config;
|
|||
//
|
|||
//import cn.hutool.core.util.StrUtil;
|
|||
//import com.ccsens.util.PropUtil;
|
|||
//import org.springframework.amqp.core.Binding;
|
|||
//import org.springframework.amqp.core.BindingBuilder;
|
|||
//import org.springframework.amqp.core.FanoutExchange;
|
|||
//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 RabbitMQConfig {
|
|||
// private static final String RabbitMQ_QUEUE_NAME = "Queue_Anyring";
|
|||
// private static final String TALL_MESSAGE_1 = "tall_message_1";
|
|||
// private static final String TALL_MESSAGE_2 = "tall_message_2";
|
|||
// public static final String GAME_STATUS = PropUtil.gameMqName;
|
|||
//
|
|||
// public static final String WISDOM_CAR = "wisdom_car";
|
|||
// public static final String WISDOM_CAR_2 = "wisdom_car2";
|
|||
//
|
|||
// public static final String BENEFICIATION = "beneficiation";
|
|||
//
|
|||
//
|
|||
// private static final String GAME_STATUS_DELAY_SEND_QUEUE = "gameStatusDelaySendQueue";
|
|||
// private static final String GAME_STATUS_DELAY_SEND_EXCHANGE = "gameStatusDelaySendExchange";
|
|||
// private static final String GAME_STATUS_DELAY_SEND_ROUTING_KEY = "gameStatusDelaySendRoutingKey";
|
|||
//
|
|||
//// private static final String GAME_MQ_A = "GAME_MQ_A";
|
|||
//
|
|||
//
|
|||
// /**消息队列发送*/
|
|||
// public static final String MESSAGE_QUEUE_NAME = "tall_message_1";
|
|||
// /**游戏计算分数*/
|
|||
// public static final String GAME_SCORE = "game_score";
|
|||
//
|
|||
//
|
|||
//
|
|||
//
|
|||
//
|
|||
// @Bean
|
|||
// public Queue wisdom_car(){
|
|||
// return new Queue(GAME_MQ_A);
|
|||
// public Queue queueGame(){
|
|||
// return new Queue(PropUtil.gameMqName);
|
|||
// }
|
|||
//
|
|||
// @Bean
|
|||
// public Queue queue(){
|
|||
// return new Queue(RabbitMQ_QUEUE_NAME);
|
|||
// }
|
|||
|
|||
// /**
|
|||
// * 延时发送队列
|
|||
// * @return
|
|||
// */
|
|||
// @Bean
|
|||
// public Queue delayQueue(){
|
|||
//// return QueueBuilder.durable(GAME_STATUS_DELAY_SEND_QUEUE).build();
|
|||
// return new Queue(GAME_STATUS_DELAY_SEND_QUEUE,true);
|
|||
// public Queue queue1(){
|
|||
// return new Queue(TALL_MESSAGE_1);
|
|||
// }
|
|||
// @Bean
|
|||
// public Queue queue2(){
|
|||
// return new Queue(TALL_MESSAGE_2);
|
|||
// }
|
|||
//
|
|||
// /**
|
|||
// * 延时交换机
|
|||
// * @return
|
|||
// */
|
|||
// @Bean
|
|||
// public CustomExchange delayExchange(){
|
|||
// Map<String, Object> args = new HashMap<>();
|
|||
// args.put("x-delayed-type", "direct");
|
|||
// return new CustomExchange(GAME_STATUS_DELAY_SEND_EXCHANGE, "x-delayed-message", true, false, args);
|
|||
// public Queue queue3(){
|
|||
// return new Queue(GAME_SCORE);
|
|||
// }
|
|||
//
|
|||
// /**
|
|||
// * 绑定
|
|||
// */
|
|||
// @Bean
|
|||
// Binding queueBinding(Queue delayQueue, CustomExchange customExchange) {
|
|||
// return BindingBuilder.bind(delayQueue).to(customExchange).with(GAME_STATUS_DELAY_SEND_ROUTING_KEY).noargs();
|
|||
// public Queue wisdomCar(){
|
|||
// return new Queue(WISDOM_CAR);
|
|||
// }
|
|||
|
|||
|
|||
//创建Fanout交换器
|
|||
@Bean |
|||
FanoutExchange fanoutExchange() { |
|||
return new FanoutExchange("fanoutExchange"); |
|||
} |
|||
//将对列绑定到Fanout交换器
|
|||
@Bean |
|||
Binding bindingExchangeA(Queue queueGame, FanoutExchange fanoutExchange) { |
|||
if(StrUtil.isEmpty(queueGame.getName())){ |
|||
return null; |
|||
} |
|||
return BindingBuilder.bind(queueGame).to(fanoutExchange); |
|||
} |
|||
|
|||
|
|||
} |
|||
//
|
|||
// @Bean
|
|||
// public Queue wisdomCar2(){
|
|||
// return new Queue(WISDOM_CAR_2);
|
|||
// }
|
|||
//
|
|||
//
|
|||
// @Bean
|
|||
// public Queue beneficiation(){
|
|||
// return new Queue(BENEFICIATION);
|
|||
// }
|
|||
//// @Bean
|
|||
//// public Queue wisdom_car(){
|
|||
//// return new Queue(GAME_MQ_A);
|
|||
//// }
|
|||
//
|
|||
//// /**
|
|||
//// * 延时发送队列
|
|||
//// * @return
|
|||
//// */
|
|||
//// @Bean
|
|||
//// public Queue delayQueue(){
|
|||
////// return QueueBuilder.durable(GAME_STATUS_DELAY_SEND_QUEUE).build();
|
|||
//// return new Queue(GAME_STATUS_DELAY_SEND_QUEUE,true);
|
|||
//// }
|
|||
////
|
|||
//// /**
|
|||
//// * 延时交换机
|
|||
//// * @return
|
|||
//// */
|
|||
//// @Bean
|
|||
//// public CustomExchange delayExchange(){
|
|||
//// Map<String, Object> args = new HashMap<>();
|
|||
//// args.put("x-delayed-type", "direct");
|
|||
//// return new CustomExchange(GAME_STATUS_DELAY_SEND_EXCHANGE, "x-delayed-message", true, false, args);
|
|||
//// }
|
|||
////
|
|||
//// /**
|
|||
//// * 绑定
|
|||
//// */
|
|||
//// @Bean
|
|||
//// Binding queueBinding(Queue delayQueue, CustomExchange customExchange) {
|
|||
//// return BindingBuilder.bind(delayQueue).to(customExchange).with(GAME_STATUS_DELAY_SEND_ROUTING_KEY).noargs();
|
|||
//// }
|
|||
//
|
|||
//
|
|||
// //创建Fanout交换器
|
|||
// @Bean
|
|||
// FanoutExchange fanoutExchange() {
|
|||
// return new FanoutExchange("fanoutExchange");
|
|||
// }
|
|||
// //将对列绑定到Fanout交换器
|
|||
// @Bean
|
|||
// Binding bindingExchangeA(Queue queueGame, FanoutExchange fanoutExchange) {
|
|||
// if(StrUtil.isEmpty(queueGame.getName())){
|
|||
// return null;
|
|||
// }
|
|||
// return BindingBuilder.bind(queueGame).to(fanoutExchange);
|
|||
// }
|
|||
//
|
|||
//
|
|||
//}
|
|||
|
@ -1,55 +1,55 @@ |
|||
package com.ccsens.util.message; |
|||
|
|||
import com.ccsens.util.JacksonUtil; |
|||
import com.ccsens.util.bean.message.common.InMessage; |
|||
import com.ccsens.util.bean.message.common.MessageConstant; |
|||
import com.ccsens.util.bean.message.common.MessageRule; |
|||
import com.ccsens.util.config.RabbitMQConfig; |
|||
import com.fasterxml.jackson.core.JsonProcessingException; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.amqp.core.AmqpTemplate; |
|||
import org.springframework.amqp.rabbit.core.RabbitTemplate; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import javax.annotation.PostConstruct; |
|||
import javax.annotation.Resource; |
|||
import java.util.Set; |
|||
|
|||
/** |
|||
* @author 逗 |
|||
*/ |
|||
@Component |
|||
@Slf4j |
|||
public class SwitchoverProjectUtil { |
|||
@Resource |
|||
private AmqpTemplate amqpTemplate; |
|||
private static SwitchoverProjectUtil util; |
|||
|
|||
@PostConstruct |
|||
public void init(){ |
|||
util = this; |
|||
util.amqpTemplate = this.amqpTemplate; |
|||
} |
|||
|
|||
public static void switchoverProject(Set<String> userIdSet,Long projectId, String... params) throws JsonProcessingException { |
|||
log.info("切换项目:{}--{}",projectId,userIdSet); |
|||
//设定发送规则
|
|||
MessageRule messageRule = MessageRule.defaultRule(MessageConstant.DomainType.User); |
|||
messageRule.setAckRule(MessageRule.AckRule.NONE); |
|||
messageRule.setOfflineDiscard((byte) 1); |
|||
//生成消息
|
|||
RecoveryWithStartRecipe recoveryWithStartRecipe = new RecoveryWithStartRecipe(projectId); |
|||
if (params != null && params.length > 0) { |
|||
recoveryWithStartRecipe.getData().setUrl(params[0]); |
|||
} |
|||
//封装成inMessage
|
|||
InMessage inMessage = new InMessage(); |
|||
inMessage.setToDomain(MessageConstant.DomainType.User); |
|||
inMessage.setTos(userIdSet); |
|||
inMessage.setData(JacksonUtil.beanToJson(recoveryWithStartRecipe)); |
|||
inMessage.setRule(messageRule); |
|||
log.info("发送切换项目信息:{}",inMessage); |
|||
util.amqpTemplate.convertAndSend(RabbitMQConfig.MESSAGE_QUEUE_NAME, |
|||
JacksonUtil.beanToJson(inMessage)); |
|||
} |
|||
} |
|||
//package com.ccsens.util.message;
|
|||
//
|
|||
//import com.ccsens.util.JacksonUtil;
|
|||
//import com.ccsens.util.bean.message.common.InMessage;
|
|||
//import com.ccsens.util.bean.message.common.MessageConstant;
|
|||
//import com.ccsens.util.bean.message.common.MessageRule;
|
|||
//import com.ccsens.util.config.RabbitMQConfig;
|
|||
//import com.fasterxml.jackson.core.JsonProcessingException;
|
|||
//import lombok.extern.slf4j.Slf4j;
|
|||
//import org.springframework.amqp.core.AmqpTemplate;
|
|||
//import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|||
//import org.springframework.stereotype.Component;
|
|||
//
|
|||
//import javax.annotation.PostConstruct;
|
|||
//import javax.annotation.Resource;
|
|||
//import java.util.Set;
|
|||
//
|
|||
///**
|
|||
// * @author 逗
|
|||
// */
|
|||
//@Component
|
|||
//@Slf4j
|
|||
//public class SwitchoverProjectUtil {
|
|||
// @Resource
|
|||
// private AmqpTemplate amqpTemplate;
|
|||
// private static SwitchoverProjectUtil util;
|
|||
//
|
|||
// @PostConstruct
|
|||
// public void init(){
|
|||
// util = this;
|
|||
// util.amqpTemplate = this.amqpTemplate;
|
|||
// }
|
|||
//
|
|||
// public static void switchoverProject(Set<String> userIdSet,Long projectId, String... params) throws JsonProcessingException {
|
|||
// log.info("切换项目:{}--{}",projectId,userIdSet);
|
|||
// //设定发送规则
|
|||
// MessageRule messageRule = MessageRule.defaultRule(MessageConstant.DomainType.User);
|
|||
// messageRule.setAckRule(MessageRule.AckRule.NONE);
|
|||
// messageRule.setOfflineDiscard((byte) 1);
|
|||
// //生成消息
|
|||
// RecoveryWithStartRecipe recoveryWithStartRecipe = new RecoveryWithStartRecipe(projectId);
|
|||
// if (params != null && params.length > 0) {
|
|||
// recoveryWithStartRecipe.getData().setUrl(params[0]);
|
|||
// }
|
|||
// //封装成inMessage
|
|||
// InMessage inMessage = new InMessage();
|
|||
// inMessage.setToDomain(MessageConstant.DomainType.User);
|
|||
// inMessage.setTos(userIdSet);
|
|||
// inMessage.setData(JacksonUtil.beanToJson(recoveryWithStartRecipe));
|
|||
// inMessage.setRule(messageRule);
|
|||
// log.info("发送切换项目信息:{}",inMessage);
|
|||
// util.amqpTemplate.convertAndSend(RabbitMQConfig.MESSAGE_QUEUE_NAME,
|
|||
// JacksonUtil.beanToJson(inMessage));
|
|||
// }
|
|||
//}
|
|||
|
Loading…
Reference in new issue