Search in sources :

Example 1 with CheckTransactionStateRequestHeader

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);
    }
}
Also used : Set(java.util.Set) Random(java.util.Random) Channel(io.netty.channel.Channel) CheckTransactionStateRequestHeader(com.yanghui.elephant.common.protocol.header.CheckTransactionStateRequestHeader)

Example 2 with CheckTransactionStateRequestHeader

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);
    }
}
Also used : RemotingCommand(com.yanghui.elephant.remoting.procotol.RemotingCommand) MessageEntity(com.yanghui.elephant.store.entity.MessageEntity) CheckTransactionStateRequestHeader(com.yanghui.elephant.common.protocol.header.CheckTransactionStateRequestHeader)

Aggregations

CheckTransactionStateRequestHeader (com.yanghui.elephant.common.protocol.header.CheckTransactionStateRequestHeader)2 RemotingCommand (com.yanghui.elephant.remoting.procotol.RemotingCommand)1 MessageEntity (com.yanghui.elephant.store.entity.MessageEntity)1 Channel (io.netty.channel.Channel)1 Random (java.util.Random)1 Set (java.util.Set)1