use of com.yanghui.elephant.remoting.procotol.RemotingCommand in project elephant by yanghuijava.
the class DefaultMQProducerImpl method checkTransactionState.
@Override
public void checkTransactionState(final String address, final String producerGroupe, final Message msg) {
Runnable run = new Runnable() {
@Override
public void run() {
try {
TransactionMQProducer producer = (TransactionMQProducer) defaultMQProducer;
LocalTransactionState localState = producer.getTransactionCheckListener().checkLocalTransactionState(msg);
CheckTransactionStateResponseHeader header = new CheckTransactionStateResponseHeader();
header.setCommitOrRollback(localState.name());
header.setMessageId(msg.getMessageId());
header.setProducerGroup(defaultMQProducer.getProducerGroup());
RemotingCommand request = RemotingCommand.buildRequestCmd(header, RequestCode.CHECK_TRANSACTION_RESPONSE);
mqProducerFactory.getRemotingClient().invokeOneway(address, request, 0);
} catch (Exception e) {
log.error("check transaction state error:{}", e);
}
}
};
this.checkExecutor.submit(run);
}
use of com.yanghui.elephant.remoting.procotol.RemotingCommand in project elephant by yanghuijava.
the class NettyRemotingAbstract method handlerRequestProcessor.
private void handlerRequestProcessor(final ChannelHandlerContext ctx, final RemotingCommand request, Pair<RequestProcessor, ExecutorService> pair) {
final RequestProcessor requestProcessor = pair.getObject1();
ExecutorService executorService = pair.getObject2();
if (executorService == null) {
RemotingCommand respose = requestProcessor.processRequest(ctx, request);
if (respose != null)
ctx.writeAndFlush(respose);
return;
}
executorService.submit(new Runnable() {
@Override
public void run() {
RemotingCommand respose = requestProcessor.processRequest(ctx, request);
if (respose != null)
ctx.writeAndFlush(respose);
}
});
}
use of com.yanghui.elephant.remoting.procotol.RemotingCommand in project elephant by yanghuijava.
the class NettyRemotingAbstract method invokeSyncImpl.
public RemotingCommand invokeSyncImpl(final Channel channel, final RemotingCommand request, final long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException {
final int unique = request.getUnique();
try {
final SocketAddress addr = channel.remoteAddress();
final ResponseFuture responseFuture = new ResponseFuture(unique, timeoutMillis);
this.responseTable.put(unique, responseFuture);
channel.writeAndFlush(request).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (future.isSuccess()) {
responseFuture.setSendRequestOK(true);
return;
}
responseFuture.setSendRequestOK(false);
responseTable.remove(unique);
responseFuture.setCause(future.cause());
responseFuture.putResponse(null);
log.warn("send a request command to channel <" + addr + "> failed.");
}
});
RemotingCommand respose = responseFuture.waitRespose(timeoutMillis);
if (null == respose) {
if (responseFuture.isSendRequestOK()) {
throw new RemotingTimeoutException(RemotingHelper.parseSocketAddressAddr(addr), timeoutMillis, responseFuture.getCause());
} else {
throw new RemotingSendRequestException(RemotingHelper.parseSocketAddressAddr(addr), responseFuture.getCause());
}
}
return respose;
} finally {
this.responseTable.remove(unique);
}
}
use of com.yanghui.elephant.remoting.procotol.RemotingCommand in project elephant by yanghuijava.
the class MessageRequestProcessor method transactionMessageHandle.
private RemotingCommand transactionMessageHandle(SendMessageRequestHeader requestHeader, RemotingCommand request) {
RemotingCommand response = RemotingCommand.buildResposeCmd(ResponseCode.SERVER_FAIL, request.getUnique());
MessageEntity entity = buildMessageEntity(request.getBody(), requestHeader, true);
int responseCode = saveMessage(entity);
response.setCode(responseCode);
return response;
}
use of com.yanghui.elephant.remoting.procotol.RemotingCommand 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