重构消息处理框架ExchangeTask 只做新消息获取和分发
This commit is contained in:
@@ -6,6 +6,8 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -13,8 +15,10 @@ import com.gzzn.omms.msgexchangeapi.dao.CminmsgDao;
|
||||
import com.gzzn.omms.msgexchangeapi.entity.Cminmsg;
|
||||
import com.gzzn.omms.msgexchangeapi.entity.msg.Msg;
|
||||
|
||||
@Service
|
||||
@Service("cminmsgService")
|
||||
public class CminmsgServiceImpl implements ICminmsgService {
|
||||
private static Logger logger = LoggerFactory.getLogger(CminmsgServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private CminmsgDao cminmsgDao;
|
||||
|
||||
@@ -46,7 +50,7 @@ public class CminmsgServiceImpl implements ICminmsgService {
|
||||
|
||||
@Override
|
||||
public List<Cminmsg> getNewMsgsAfterId(Long id) {
|
||||
List<Cminmsg> lsCminmsgs = cminmsgDao.findByCminmsgsIdGreaterThanOrderByCminmsgsDateReceived(id);
|
||||
List<Cminmsg> lsCminmsgs = cminmsgDao.findByCminmsgsIdGreaterThanAndCminmsgsDateProcessedIsNull(id);
|
||||
if(null == lsCminmsgs)
|
||||
{
|
||||
return Collections.emptyList();
|
||||
@@ -57,18 +61,37 @@ public class CminmsgServiceImpl implements ICminmsgService {
|
||||
|
||||
|
||||
@Override
|
||||
public Optional<Cminmsg> getRespSchdCminmsg(Date date) {
|
||||
List<Cminmsg> lsCminmsgs = getNewMsgsAfterDate(date);
|
||||
Optional<Cminmsg> opCminmsg = lsCminmsgs
|
||||
.stream()
|
||||
.filter(x->{
|
||||
String msgBlob = x.getCminmsgsClobMsg();
|
||||
Msg msg = exchangeService.xmlstrToObject(msgBlob, Msg.class);
|
||||
String type = msg.getMeta().getType();
|
||||
String subType = msg.getMeta().getStyp();
|
||||
return type.equals("SCHD") && subType.equals("RESP");
|
||||
})
|
||||
.findFirst();
|
||||
public Optional<Cminmsg> getRespSchdCminmsg(Date date,Integer tryTimes,Long intervalMs) {
|
||||
Optional<Cminmsg> opCminmsg = Optional.empty();
|
||||
Integer currentTimes=0;//当前尝试次数
|
||||
|
||||
while (currentTimes < tryTimes) {
|
||||
currentTimes++;
|
||||
|
||||
List<Cminmsg> lsCminmsgs = getNewMsgsAfterDate(date);
|
||||
opCminmsg = lsCminmsgs
|
||||
.stream()
|
||||
.filter(x->{
|
||||
String msgBlob = x.getCminmsgsClobMsg();
|
||||
Msg msg = exchangeService.xmlstrToObject(msgBlob, Msg.class);
|
||||
String type = msg.getMeta().getType();
|
||||
String subType = msg.getMeta().getStyp();
|
||||
return type.equals("SCHD") && subType.equals("RESP");
|
||||
})
|
||||
.findFirst();
|
||||
//
|
||||
if(opCminmsg.isPresent())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//等待xx秒继续循环过程
|
||||
try {
|
||||
Thread.sleep(intervalMs);
|
||||
} catch (InterruptedException e) {
|
||||
logger.warn("Thread.sleep:暂停线程异常");
|
||||
}
|
||||
}//end while
|
||||
return opCminmsg;
|
||||
}//end function
|
||||
|
||||
@@ -82,7 +105,7 @@ public class CminmsgServiceImpl implements ICminmsgService {
|
||||
|
||||
List<Cminmsg> lsCmins = (List<Cminmsg>) cminmsgDao.findAll(ids);
|
||||
List<Cminmsg> lsCminsProcessed = lsCmins.stream().map(node->{
|
||||
node.setCminmsgsDateReceived(new Date());
|
||||
node.setCminmsgsDateProcessed(new Date());
|
||||
return node;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user