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