Browse Source

v0817-v2.0

master
zy_Java 5 years ago
parent
commit
65f0934f74
  1. 5
      game/src/main/java/com/ccsens/game/mq/GameScoreListener.java
  2. 1
      game/src/main/java/com/ccsens/game/service/MessageService.java
  3. 36
      game/src/main/java/com/ccsens/game/service/RabbitMQListener.java
  4. 28
      game/src/main/java/com/ccsens/game/util/SendMsg.java
  5. 2
      game/src/main/resources/application-dev.yml
  6. 2
      game/src/main/resources/application-test.yml
  7. 4
      game/src/main/resources/druid-test.yml
  8. 4
      tall/src/main/resources/application.yml
  9. 7
      util/src/main/java/com/ccsens/util/config/RabbitMQConfig.java

5
game/src/main/java/com/ccsens/game/mq/GameScoreListener.java

@ -22,9 +22,7 @@ import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
@ -66,7 +64,8 @@ public class GameScoreListener {
inMessage.setToDomain(MessageConstant.DomainType.User);
inMessage.setTos(tos);
inMessage.setData(JSONObject.toJSONString(gameMessageCountOut));
rabbitTemplate.convertAndSend(RabbitMQConfig.MESSAGE_QUEUE_NAME, inMessage);
// rabbitTemplate.convertAndSend(RabbitMQConfig.MESSAGE_QUEUE_NAME, inMessage);
rabbitTemplate.convertAndSend(RabbitMQConfig.GAME_SCORE, inMessage);
});
}

1
game/src/main/java/com/ccsens/game/service/MessageService.java

@ -18,7 +18,6 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

36
game/src/main/java/com/ccsens/game/service/RabbitMQListener.java

@ -18,21 +18,21 @@ import java.io.IOException;
import java.util.List;
import java.util.TreeMap;
//@Slf4j
//@Component
//@RabbitListener(queues = RabbitMQConfig.GAME_STATUS)
//public class RabbitMQListener {
// private Logger logger = LoggerFactory.getLogger(RabbitMQListener.class);
// @Autowired
// private IMessageService messageService;
//
// @RabbitHandler
// public void process(String messageJson) throws IOException {
// System.out.println("++++++++++++++"+messageJson);
//// List<GameMessageWithChangeStatusOut> gameMessageList = JacksonUtil.jsonToBean(messageJson,
//// GameMessageWithChangeStatusOut.class, true);
// log.info("认证MQ {}",messageJson);
// messageService.doChangeStatusMessage(JacksonUtil.jsonToBean(messageJson,
// GameMessageWithChangeStatusOut.class, true));
// }
//}
@Slf4j
@Component
@RabbitListener(queues = RabbitMQConfig.GAME_STATUS)
public class RabbitMQListener {
private Logger logger = LoggerFactory.getLogger(RabbitMQListener.class);
@Autowired
private IMessageService messageService;
@RabbitHandler
public void process(String messageJson) throws IOException {
System.out.println("++++++++++++++"+messageJson);
// List<GameMessageWithChangeStatusOut> gameMessageList = JacksonUtil.jsonToBean(messageJson,
// GameMessageWithChangeStatusOut.class, true);
log.info("认证MQ {}",messageJson);
messageService.doChangeStatusMessage(JacksonUtil.jsonToBean(messageJson,
GameMessageWithChangeStatusOut.class, true));
}
}

28
game/src/main/java/com/ccsens/game/util/SendMsg.java

@ -3,25 +3,17 @@ package com.ccsens.game.util;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ccsens.game.bean.dto.ClientDto;
import com.ccsens.game.bean.dto.message.ChangeStatusMessageDto;
import com.ccsens.game.bean.dto.message.GameMessageWithChangeStatusOut;
import com.ccsens.game.bean.po.GameGroup;
import com.ccsens.game.bean.po.GameGroupExample;
import com.ccsens.game.bean.po.GameRecord;
import com.ccsens.game.bean.vo.ClientVo;
import com.ccsens.game.persist.dao.GameGroupDao;
import com.ccsens.game.persist.dao.GameUserJoinDao;
import com.ccsens.game.service.ClientService;
import com.ccsens.util.JacksonUtil;
import com.ccsens.util.RedisUtil;
import com.ccsens.util.WebConstant;
import com.ccsens.util.bean.message.common.InMessage;
import com.ccsens.util.bean.message.common.MessageConstant;
import com.ccsens.util.config.RabbitMQConfig;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
@ -59,18 +51,22 @@ public class SendMsg {
}
Set<String> userIds = new HashSet<>();
userJoins.forEach(join -> {
// outs.add(getMsg(userJoins, gameRecord, join, status));
outs.add(getMsg(userJoins, gameRecord, join, status));
InMessage inMessage = new InMessage();
userIds.add(String.valueOf(join.getUserId()));
inMessage.setToDomain(MessageConstant.DomainType.User);
inMessage.setTos(userIds);
inMessage.setData(JSONObject.toJSONString(getMsg(userJoins, gameRecord, join, status)));
rabbitTemplate.convertAndSend(RabbitMQConfig.MESSAGE_QUEUE_NAME, JSONObject.toJSONString(inMessage));
// InMessage inMessage = new InMessage();
//
// userIds.add(String.valueOf(join.getUserId()));
// inMessage.setToDomain(MessageConstant.DomainType.User);
// inMessage.setTos(userIds);
// inMessage.setData(JSONObject.toJSONString(getMsg(userJoins, gameRecord, join, status)));
// rabbitTemplate.convertAndSend(RabbitMQConfig.MESSAGE_QUEUE_NAME, JSONObject.toJSONString(inMessage));
});
if (CollectionUtil.isNotEmpty(outs)) {
rabbitTemplate.convertAndSend(RabbitMQConfig.GAME_STATUS, JacksonUtil.beanToJson(outs));
log.info("发送成功:{}", JacksonUtil.beanToJson(outs));
}
}

2
game/src/main/resources/application-dev.yml

@ -8,7 +8,7 @@ spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
rabbitmq:
host: 49.233.89.188
host: 81.70.54.64
password: 111111
port: 5672
username: admin

2
game/src/main/resources/application-test.yml

@ -14,7 +14,7 @@ spring:
username: admin
redis:
database: 0
host: 127.0.0.1
host: 192.168.0.99
jedis:
pool:
max-active: 200

4
game/src/main/resources/druid-test.yml

@ -15,7 +15,7 @@ spring:
maxWait: 60000
minEvictableIdleTimeMillis: 300000
minIdle: 5
password:
password: 37080c1f223685592316b02dad8816c019290a476e54ebb638f9aa3ba8b6bdb9
poolPreparedStatements: true
servletLogSlowSql: true
servletLoginPassword: 111111
@ -27,7 +27,7 @@ spring:
testOnReturn: false
testWhileIdle: true
timeBetweenEvictionRunsMillis: 60000
url: jdbc:mysql://test.tall.wiki/game?useUnicode=true&characterEncoding=UTF-8
url: jdbc:mysql://49.233.89.188:3306/game?useUnicode=true&characterEncoding=UTF-8
username: root
validationQuery: SELECT 1 FROM DUAL
env: CCSENS_GAME

4
tall/src/main/resources/application.yml

@ -1,4 +1,4 @@
spring:
profiles:
active: dev
include: util-dev,common
active: test
include: util-test,common

7
util/src/main/java/com/ccsens/util/config/RabbitMQConfig.java

@ -1,18 +1,15 @@
package com.ccsens.util.config;
import org.springframework.amqp.core.*;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
import java.util.Map;
@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";
private static final String GAME_STATUS = "game_status";
public static final String GAME_STATUS = "game_status";
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";

Loading…
Cancel
Save