use of org.apache.eventmesh.runtime.core.protocol.tcp.client.session.send.UpStreamMsgContext in project incubator-eventmesh by apache.
the class ClientGroupWrapper method sendMsgBackToBroker.
private void sendMsgBackToBroker(CloudEvent event, String bizSeqNo) throws Exception {
try {
String topic = event.getSubject();
logger.warn("send msg back to broker, bizSeqno:{}, topic:{}", bizSeqNo, topic);
long startTime = System.currentTimeMillis();
long taskExcuteTime = startTime;
send(new UpStreamMsgContext(null, event, null, startTime, taskExcuteTime), new SendCallback() {
@Override
public void onSuccess(SendResult sendResult) {
logger.info("group:{} consume fail, sendMessageBack success, bizSeqno:{}, " + "topic:{}", group, bizSeqNo, topic);
}
@Override
public void onException(OnExceptionContext context) {
logger.warn("group:{} consume fail, sendMessageBack fail, bizSeqno:{}," + " topic:{}", group, bizSeqNo, topic);
}
});
eventMeshTcpMonitor.getTcpSummaryMetrics().getEventMesh2mqMsgNum().incrementAndGet();
} catch (Exception e) {
logger.warn("try send msg back to broker failed");
throw e;
}
}
use of org.apache.eventmesh.runtime.core.protocol.tcp.client.session.send.UpStreamMsgContext in project incubator-eventmesh by apache.
the class MessageTransferTask method createSendCallback.
protected SendCallback createSendCallback(Command replyCmd, long taskExecuteTime, CloudEvent event) {
final long createTime = System.currentTimeMillis();
Package msg = new Package();
return new SendCallback() {
@Override
public void onSuccess(SendResult sendResult) {
session.getSender().getUpstreamBuff().release();
messageLogger.info("upstreamMsg message success|user={}|callback cost={}", session.getClient(), System.currentTimeMillis() - createTime);
if (replyCmd.equals(Command.BROADCAST_MESSAGE_TO_SERVER_ACK) || replyCmd.equals(Command.ASYNC_MESSAGE_TO_SERVER_ACK)) {
msg.setHeader(new Header(replyCmd, OPStatus.SUCCESS.getCode(), OPStatus.SUCCESS.getDesc(), pkg.getHeader().getSeq()));
msg.setBody(event);
Utils.writeAndFlush(msg, startTime, taskExecuteTime, session.getContext(), session);
}
}
@Override
public void onException(OnExceptionContext context) {
session.getSender().getUpstreamBuff().release();
// retry
UpStreamMsgContext upStreamMsgContext = new UpStreamMsgContext(session, event, pkg.getHeader(), startTime, taskExecuteTime);
upStreamMsgContext.delay(10000);
session.getClientGroupWrapper().get().getEventMeshTcpRetryer().pushRetry(upStreamMsgContext);
session.getSender().failMsgCount.incrementAndGet();
messageLogger.error("upstreamMsg mq message error|user={}|callback cost={}, errMsg={}", session.getClient(), (System.currentTimeMillis() - createTime), new Exception(context.getException()));
msg.setHeader(new Header(replyCmd, OPStatus.FAIL.getCode(), context.getException().toString(), pkg.getHeader().getSeq()));
msg.setBody(event);
Utils.writeAndFlush(msg, startTime, taskExecuteTime, session.getContext(), session);
}
};
}
Aggregations