Search in sources :

Example 1 with ConnectorRuntimeException

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()));
    }
}
Also used : ConnectorRuntimeException(org.apache.eventmesh.api.exception.ConnectorRuntimeException) MessageEntity(org.apache.eventmesh.connector.standalone.broker.model.MessageEntity) SendResult(org.apache.eventmesh.api.SendResult) ConnectorRuntimeException(org.apache.eventmesh.api.exception.ConnectorRuntimeException)

Example 2 with ConnectorRuntimeException

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);
    }
}
Also used : ConnectorRuntimeException(org.apache.eventmesh.api.exception.ConnectorRuntimeException) OnExceptionContext(org.apache.eventmesh.api.exception.OnExceptionContext) SendResult(org.apache.eventmesh.api.SendResult) ConnectorRuntimeException(org.apache.eventmesh.api.exception.ConnectorRuntimeException)

Example 3 with ConnectorRuntimeException

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);
        }
    };
}
Also used : ConnectorRuntimeException(org.apache.eventmesh.api.exception.ConnectorRuntimeException) RequestCallback(org.apache.rocketmq.client.producer.RequestCallback) Message(org.apache.rocketmq.common.message.Message) OnExceptionContext(org.apache.eventmesh.api.exception.OnExceptionContext) CloudEvent(io.cloudevents.CloudEvent)

Example 4 with ConnectorRuntimeException

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;
}
Also used : ConnectorRuntimeException(org.apache.eventmesh.api.exception.ConnectorRuntimeException) OnExceptionContext(org.apache.eventmesh.api.exception.OnExceptionContext) SendResult(org.apache.eventmesh.api.SendResult) SendCallback(org.apache.eventmesh.api.SendCallback)

Example 5 with ConnectorRuntimeException

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);
    }
}
Also used : ConnectorRuntimeException(org.apache.eventmesh.api.exception.ConnectorRuntimeException) OnExceptionContext(org.apache.eventmesh.api.exception.OnExceptionContext) SendResult(org.apache.eventmesh.api.SendResult) ConnectorRuntimeException(org.apache.eventmesh.api.exception.ConnectorRuntimeException)

Aggregations

ConnectorRuntimeException (org.apache.eventmesh.api.exception.ConnectorRuntimeException)5 SendResult (org.apache.eventmesh.api.SendResult)4 OnExceptionContext (org.apache.eventmesh.api.exception.OnExceptionContext)4 CloudEvent (io.cloudevents.CloudEvent)1 SendCallback (org.apache.eventmesh.api.SendCallback)1 MessageEntity (org.apache.eventmesh.connector.standalone.broker.model.MessageEntity)1 RequestCallback (org.apache.rocketmq.client.producer.RequestCallback)1 Message (org.apache.rocketmq.common.message.Message)1