use of com.yanghui.elephant.common.protocol.header.CheckTransactionStateRequestHeader in project elephant by yanghuijava.
the class TransactionCheckJob method sentToClient.
private void sentToClient(RemotingCommand request) {
Map<String, Set<Channel>> groupChannelTable = this.producerManager.getGroupChannelTable();
CheckTransactionStateRequestHeader requestHeader = (CheckTransactionStateRequestHeader) request.getCommandCustomHeader();
if (groupChannelTable.get(requestHeader.getProducerGroup()) == null || CollectionUtils.isEmpty(groupChannelTable.get(requestHeader.getProducerGroup()))) {
return;
}
List<Channel> channels = Lists.newArrayList(groupChannelTable.get(requestHeader.getProducerGroup()));
Channel c = channels.get(new Random().nextInt(channels.size()));
if (c.isActive()) {
c.writeAndFlush(request);
}
}
use of com.yanghui.elephant.common.protocol.header.CheckTransactionStateRequestHeader in project elephant by yanghuijava.
the class TransactionCheckJob method execute.
@Override
public void execute(ShardingContext shardingContext) {
List<MessageEntity> findList = this.messageEntityMapper.queryTransactionNotComplete();
log.info("查询没有完成的事务消息(查询1分钟之前的)记录数:{}", findList);
if (findList.isEmpty()) {
return;
}
try {
for (MessageEntity entity : findList) {
CheckTransactionStateRequestHeader requestHeader = new CheckTransactionStateRequestHeader();
requestHeader.setMessageId(entity.getMessageId());
requestHeader.setDestination(entity.getDestination());
requestHeader.setProducerGroup(entity.getGroup());
if (!StringUtil.isNullOrEmpty(entity.getProperties())) {
requestHeader.setProperties(entity.getProperties());
}
RemotingCommand request = RemotingCommand.buildRequestCmd(requestHeader, RequestCode.CHECK_TRANSACTION);
request.setBody(entity.getBody());
sentToClient(request);
}
} catch (Exception e) {
log.error("回查发送异常:{}", e);
}
}
Aggregations