|
@@ -11,6 +11,13 @@ import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import lombok.extern.log4j.Log4j2;
|
|
import lombok.extern.log4j.Log4j2;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.apache.rocketmq.client.exception.MQBrokerException;
|
|
|
|
+import org.apache.rocketmq.client.exception.MQClientException;
|
|
|
|
+import org.apache.rocketmq.client.producer.DefaultMQProducer;
|
|
|
|
+import org.apache.rocketmq.client.producer.SendResult;
|
|
|
|
+import org.apache.rocketmq.common.message.Message;
|
|
|
|
+import org.apache.rocketmq.remoting.common.RemotingHelper;
|
|
|
|
+import org.apache.rocketmq.remoting.exception.RemotingException;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
@@ -19,6 +26,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -37,6 +45,15 @@ public class ApiFormatHouseController {
|
|
@Value("${4dkankan.host.url}")
|
|
@Value("${4dkankan.host.url}")
|
|
private String redirectVrUrl;
|
|
private String redirectVrUrl;
|
|
|
|
|
|
|
|
+ @Value("${rocketmq.consumer.group}")
|
|
|
|
+ private String rocketMqGroup;
|
|
|
|
+
|
|
|
|
+ @Value("${rocketmq.consumer.topic}")
|
|
|
|
+ private String rocketTopic;
|
|
|
|
+
|
|
|
|
+ @Value("${rocketmq.name-server}")
|
|
|
|
+ private String rocketNameServer;
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
private RedisServiceUtils redisServiceUtils;
|
|
private RedisServiceUtils redisServiceUtils;
|
|
|
|
|
|
@@ -97,8 +114,8 @@ public class ApiFormatHouseController {
|
|
resultMap.put("roomId", tmApiHouseInfo.getCommunicateRoomId());
|
|
resultMap.put("roomId", tmApiHouseInfo.getCommunicateRoomId());
|
|
}
|
|
}
|
|
|
|
|
|
- //写入mq,异步落库
|
|
|
|
-
|
|
|
|
|
|
+ //写入mq,异步落库 todo:这里要改成线程安全
|
|
|
|
+ enqueueMq(tmApiHouseInfo);
|
|
|
|
|
|
if(!CollectionUtils.isEmpty(resultMap)){
|
|
if(!CollectionUtils.isEmpty(resultMap)){
|
|
return Result.success(resultMap);
|
|
return Result.success(resultMap);
|
|
@@ -107,6 +124,37 @@ public class ApiFormatHouseController {
|
|
return Result.success("成功提交");
|
|
return Result.success("成功提交");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void enqueueMq(TmApiHouseInfo tmApiHouseInfo){
|
|
|
|
+ if(null == tmApiHouseInfo){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ DefaultMQProducer producer = new DefaultMQProducer(rocketMqGroup);
|
|
|
|
+ // Specify name server addresses.
|
|
|
|
+ producer.setNamesrvAddr(rocketNameServer);
|
|
|
|
+ Message message = null;
|
|
|
|
+ try {
|
|
|
|
+ message = new Message(rocketTopic , "TagA" , JSON.toJSONString(tmApiHouseInfo).getBytes(RemotingHelper.DEFAULT_CHARSET));
|
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ if(null != message){
|
|
|
|
+ try {
|
|
|
|
+ SendResult sendResult = producer.send(message, 5000);
|
|
|
|
+ log.info("mq发送消息[{}]完成,结果为:{}" , message.getKeys() , sendResult);
|
|
|
|
+ } catch (MQClientException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } catch (RemotingException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } catch (MQBrokerException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ producer.shutdown();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
private String genVrLink(TmApiHouseInfo houseInfo) {
|
|
private String genVrLink(TmApiHouseInfo houseInfo) {
|
|
String terminalTypeStr = houseInfo.getTerminalType();
|
|
String terminalTypeStr = houseInfo.getTerminalType();
|
|
String userId = "";
|
|
String userId = "";
|