use of org.apache.eventmesh.api.SendResult in project incubator-eventmesh by apache.
the class ProducerImpl method send.
public SendResult send(CloudEvent cloudEvent) {
this.checkProducerServiceState(rocketmqProducer.getDefaultMQProducerImpl());
org.apache.rocketmq.common.message.Message msg = RocketMQMessageFactory.createWriter(cloudEvent.getSubject()).writeBinary(cloudEvent);
msg = supplySysProp(msg, cloudEvent);
String messageId = null;
try {
org.apache.rocketmq.client.producer.SendResult sendResultRmq = this.rocketmqProducer.send(msg);
SendResult sendResult = new SendResult();
sendResult.setTopic(sendResultRmq.getMessageQueue().getTopic());
messageId = sendResultRmq.getMsgId();
sendResult.setMessageId(messageId);
return sendResult;
} catch (Exception e) {
log.error(String.format("Send message Exception, %s", msg), e);
throw this.checkProducerException(msg.getTopic(), messageId, e);
}
}
use of org.apache.eventmesh.api.SendResult in project incubator-eventmesh by apache.
the class StandaloneProducer method publish.
public void publish(CloudEvent cloudEvent, SendCallback sendCallback) throws Exception {
Preconditions.checkNotNull(cloudEvent);
Preconditions.checkNotNull(sendCallback);
try {
SendResult sendResult = publish(cloudEvent);
sendCallback.onSuccess(sendResult);
} catch (Exception ex) {
OnExceptionContext onExceptionContext = OnExceptionContext.builder().messageId(cloudEvent.getId()).topic(cloudEvent.getSubject()).exception(new ConnectorRuntimeException(ex)).build();
sendCallback.onException(onExceptionContext);
}
}
use of org.apache.eventmesh.api.SendResult 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.api.SendResult in project incubator-eventmesh by apache.
the class SendMessageContext method retry.
@Override
public boolean retry() throws Exception {
if (eventMeshProducer == null) {
return false;
}
if (retryTimes > 0) {
// retry once
return false;
}
retryTimes++;
eventMeshProducer.send(this, new SendCallback() {
@Override
public void onSuccess(SendResult sendResult) {
}
@Override
public void onException(OnExceptionContext context) {
logger.warn("", context.getException());
eventMeshHTTPServer.metrics.getSummaryMetrics().recordSendBatchMsgFailed(1);
}
});
return true;
}
use of org.apache.eventmesh.api.SendResult 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