作者 王勇

版本迭代,收发消息,与mysql断开联系

... ... @@ -44,12 +44,12 @@ public class RabbitController {
@Resource
private AsyncTaskService asyncTaskService;
@PostMapping("/product/old")
public ResultJson productOld(String xmlStr)
@PostMapping("/product_old")
public ResultJson productOld(String xmlMessage)
{
try {
// 1、解析 xml 文件,获取数据
XmlData xmlData = xmlUtils.parsingMessage(xmlStr);
XmlData xmlData = xmlUtils.parsingMessage(xmlMessage);
String SNDR = xmlData.getSender();
String RCVR = xmlData.getQueueName();
Date DDTM = xmlData.getSendDateTime() == null ? new Date() : xmlData.getSendDateTime();
... ... @@ -67,7 +67,7 @@ public class RabbitController {
}
}
@PostMapping("/product/new")
@PostMapping("/product_new")
public ResultJson productNew(@RequestParam(value = "SNDR") String SNDR,
@RequestParam(value = "RCVR", required = false) String RCVR,
@DateTimeFormat(pattern = "yyyyMMddHHmmss")
... ... @@ -78,7 +78,7 @@ public class RabbitController {
@RequestParam(value = "SEQN", required = false) String SEQN,
@RequestParam(value = "VSHT") String VSHT,
@RequestParam(value = "SERV") String SERV,
@RequestParam(value = "content") String content)
@RequestParam(value = "MSG") String MSG)
{
try {
// 1、获取数据
... ... @@ -92,13 +92,14 @@ public class RabbitController {
.sequence(SEQN)
.virtualHostName(VSHT)
.serverName(SERV)
.sendContent(content)
.sendContent(MSG)
.build();
// 2、校验格式、数据
ResultJson resultJson = xmlUtils.checkFormatAndData(xmlData);
if (!"200".equals(resultJson.getCode())) {
return resultJson;
}
log.info(""+xmlData);
XmlData sentData = (XmlData) resultJson.getData();
// 3、通过格式校验之后,进行配置校验
Boolean binding = userMessageBindingService.validateXmlBinding(sentData);
... ...
... ... @@ -7,7 +7,7 @@ package com.sunyo.wlpt.message.bus.service.exception;
*/
public enum CustomExceptionType {
MESSAGE_SUCCESS("10200", "消息发送成功"),
MESSAGE_SUCCESS("10200", "发送消息,成功!"),
RECEIVE_SUCCESS("20200", "接收消息,成功!"),
RECEIVE_SERVER_EXCEPTION("20500", "服务器异常,接收消息失败!请联系管理员处理"),
... ...
... ... @@ -172,10 +172,11 @@ public class ElasticsearchService {
*
* @param messageNote {@link MessageNote}
*/
public void saveOrUpdateMessageNote(MessageNote messageNote)
public Boolean saveOrUpdateMessageNote(MessageNote messageNote)
{
// id,存在即是更新;id不存在即是保存
messageNoteRepository.save(messageNote);
MessageNote save = messageNoteRepository.save(messageNote);
return save != null ? true : false;
}
/**
... ...
... ... @@ -67,18 +67,18 @@ public class MessageNoteServiceImpl implements MessageNoteService {
if (id.contains(splitItem)) {
String[] split = id.split(splitItem);
for (int i = 0; i < split.length; i++) {
MessageNote messageNote = messageNoteMapper.selectByPrimaryKey(split[i]);
if (messageNote != null) {
messageNoteMapper.deleteByPrimaryKey(split[i]);
}
// MessageNote messageNote = messageNoteMapper.selectByPrimaryKey(split[i]);
// if (messageNote != null) {
// messageNoteMapper.deleteByPrimaryKey(split[i]);
// }
elasticsearchService.deleteMessageNoteById(split[i]);
}
return 2;
} else {
MessageNote messageNote = messageNoteMapper.selectByPrimaryKey(id);
if (messageNote != null) {
messageNoteMapper.deleteByPrimaryKey(id);
}
// MessageNote messageNote = messageNoteMapper.selectByPrimaryKey(id);
// if (messageNote != null) {
// messageNoteMapper.deleteByPrimaryKey(id);
// }
elasticsearchService.deleteMessageNoteById(id);
return 2;
}
... ... @@ -163,10 +163,9 @@ public class MessageNoteServiceImpl implements MessageNoteService {
.description(description)
.build();
MessageNote note = note_fillId(messageNote);
int num = messageNoteMapper.insertSelective(note);
// int num = messageNoteMapper.insertSelective(note);
// ES没有事务,故先执行SQL
insertMessageToES(note);
return num;
return insertMessageToES(note) ? 1 : 0;
}
/**
... ... @@ -262,10 +261,9 @@ public class MessageNoteServiceImpl implements MessageNoteService {
.superPassword(busServer.getSuperPassword())
.build();
directUtils.sendMessage(xmlData);
int num = messageNoteMapper.insertSelective(note);
// int num = messageNoteMapper.insertSelective(note);
// ES没有事务,故先执行SQL
insertMessageToES(note);
return num;
return insertMessageToES(note) ? 1 : 0;
} else {
return 0;
}
... ... @@ -277,9 +275,9 @@ public class MessageNoteServiceImpl implements MessageNoteService {
*
* @param note 消息
*/
public void insertMessageToES(MessageNote note)
public Boolean insertMessageToES(MessageNote note)
{
elasticsearchService.saveOrUpdateMessageNote(note);
return elasticsearchService.saveOrUpdateMessageNote(note);
}
}
... ...
... ... @@ -56,9 +56,10 @@ public class XmlUtils {
Element msg = document.getRootElement();
Element meta = msg.element("META");
Date sendDateTime = DateUtils.strToDateLong(meta.elementText("DDTM"));
// msg.elementText("BODY");
XmlData xmlData = XmlData.builder()
.sendContent(msg.elementText("BODY"))
.sendContent(xmlStr)
.sender(meta.elementText("SNDR"))
.queueName(meta.elementText("RCVR"))
.sendTime(meta.elementText("DDTM"))
... ... @@ -201,7 +202,7 @@ public class XmlUtils {
if (!virtualHost.getId().equals(busQueue.getVirtualHostId())) {
return ResultJson.error(CustomExceptionType.RECEIVE_HOST_QUEUE_ERROR);
}
if(busQueueService.validateByUserNameAndQueueName(receiver,queueName).size()==0){
if (busQueueService.validateByUserNameAndQueueName(receiver, queueName).size() == 0) {
return ResultJson.error(CustomExceptionType.RECEIVE_USER_QUEUE_ERROR);
}
... ...