use of org.apache.eventmesh.api.exception.ConnectorRuntimeException in project incubator-eventmesh by apache.
the class StandaloneProducer method publish.
public SendResult publish(CloudEvent cloudEvent) {
Preconditions.checkNotNull(cloudEvent);
try {
MessageEntity messageEntity = standaloneBroker.putMessage(cloudEvent.getSubject(), cloudEvent);
SendResult sendResult = new SendResult();
sendResult.setTopic(cloudEvent.getSubject());
sendResult.setMessageId(String.valueOf(messageEntity.getOffset()));
return sendResult;
} catch (Exception e) {
logger.error("send message error, topic: {}", cloudEvent.getSubject(), e);
throw new ConnectorRuntimeException(String.format("Send message error, topic: %s", cloudEvent.getSubject()));
}
}
use of org.apache.eventmesh.api.exception.ConnectorRuntimeException in project incubator-eventmesh by apache.
the class StandaloneProducer method sendAsync.
public void sendAsync(CloudEvent cloudEvent, SendCallback sendCallback) {
Preconditions.checkNotNull(cloudEvent, "CloudEvent cannot be null");
Preconditions.checkNotNull(sendCallback, "Callback cannot be null");
// todo: current is not async
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.exception.ConnectorRuntimeException in project incubator-eventmesh by apache.
the class ProducerImpl method rrCallbackConvert.
private RequestCallback rrCallbackConvert(final Message message, final RequestReplyCallback rrCallback) {
return new RequestCallback() {
@Override
public void onSuccess(org.apache.rocketmq.common.message.Message message) {
// clean the message property to lowercase
for (String sysPropKey : MessageConst.STRING_HASH_SET) {
if (StringUtils.isNotEmpty(message.getProperty(sysPropKey))) {
String prop = message.getProperty(sysPropKey);
String tmpPropKey = sysPropKey.toLowerCase().replaceAll("_", Constants.MESSAGE_PROP_SEPARATOR);
MessageAccessor.putProperty(message, tmpPropKey, prop);
message.getProperties().remove(sysPropKey);
}
}
CloudEvent event = RocketMQMessageFactory.createReader(message).toEvent();
rrCallback.onSuccess(event);
}
@Override
public void onException(Throwable e) {
String topic = message.getTopic();
ConnectorRuntimeException onsEx = ProducerImpl.this.checkProducerException(topic, null, e);
OnExceptionContext context = new OnExceptionContext();
context.setTopic(topic);
context.setException(onsEx);
rrCallback.onException(e);
}
};
}
use of org.apache.eventmesh.api.exception.ConnectorRuntimeException in project incubator-eventmesh by apache.
the class ProducerImpl method sendCallbackConvert.
private org.apache.rocketmq.client.producer.SendCallback sendCallbackConvert(final Message message, final SendCallback sendCallback) {
org.apache.rocketmq.client.producer.SendCallback rmqSendCallback = new org.apache.rocketmq.client.producer.SendCallback() {
@Override
public void onSuccess(org.apache.rocketmq.client.producer.SendResult sendResult) {
sendCallback.onSuccess(CloudEventUtils.convertSendResult(sendResult));
}
@Override
public void onException(Throwable e) {
String topic = message.getTopic();
ConnectorRuntimeException onsEx = ProducerImpl.this.checkProducerException(topic, null, e);
OnExceptionContext context = new OnExceptionContext();
context.setTopic(topic);
context.setException(onsEx);
sendCallback.onException(context);
}
};
return rmqSendCallback;
}
use of org.apache.eventmesh.api.exception.ConnectorRuntimeException 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);
}
}
Aggregations