Search in sources :

Example 11 with SendResult

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

Example 12 with SendResult

use of org.apache.eventmesh.api.SendResult in project incubator-eventmesh by apache.

the class EventMeshConsumer method sendMessageBack.

public void sendMessageBack(final CloudEvent event, final String uniqueId, String bizSeqNo) throws Exception {
    EventMeshProducer sendMessageBack = eventMeshHTTPServer.getProducerManager().getEventMeshProducer(consumerGroupConf.getConsumerGroup());
    if (sendMessageBack == null) {
        logger.warn("consumer:{} consume fail, sendMessageBack, bizSeqNo:{}, uniqueId:{}", consumerGroupConf.getConsumerGroup(), bizSeqNo, uniqueId);
        return;
    }
    final SendMessageContext sendMessageBackContext = new SendMessageContext(bizSeqNo, event, sendMessageBack, eventMeshHTTPServer);
    sendMessageBack.send(sendMessageBackContext, new SendCallback() {

        @Override
        public void onSuccess(SendResult sendResult) {
        }

        @Override
        public void onException(OnExceptionContext context) {
            logger.warn("consumer:{} consume fail, sendMessageBack, bizSeqno:{}, uniqueId:{}", consumerGroupConf.getConsumerGroup(), bizSeqNo, uniqueId);
        }
    });
}
Also used : EventMeshProducer(org.apache.eventmesh.runtime.core.protocol.http.producer.EventMeshProducer) OnExceptionContext(org.apache.eventmesh.api.exception.OnExceptionContext) SendMessageContext(org.apache.eventmesh.runtime.core.protocol.http.producer.SendMessageContext) SendResult(org.apache.eventmesh.api.SendResult) SendCallback(org.apache.eventmesh.api.SendCallback)

Example 13 with SendResult

use of org.apache.eventmesh.api.SendResult in project incubator-eventmesh by apache.

the class EventMeshConsumer method sendMessageBack.

public void sendMessageBack(String consumerGroup, final CloudEvent event, final String uniqueId, String bizSeqNo) throws Exception {
    EventMeshProducer producer = eventMeshGrpcServer.getProducerManager().getEventMeshProducer(consumerGroup);
    if (producer == null) {
        logger.warn("consumer:{} consume fail, sendMessageBack, bizSeqNo:{}, uniqueId:{}", consumerGroup, bizSeqNo, uniqueId);
        return;
    }
    final SendMessageContext sendMessageBackContext = new SendMessageContext(bizSeqNo, event, producer, eventMeshGrpcServer);
    producer.send(sendMessageBackContext, new SendCallback() {

        @Override
        public void onSuccess(SendResult sendResult) {
        }

        @Override
        public void onException(OnExceptionContext context) {
            logger.warn("consumer:{} consume fail, sendMessageBack, bizSeqNo:{}, uniqueId:{}", consumerGroup, bizSeqNo, uniqueId);
        }
    });
}
Also used : EventMeshProducer(org.apache.eventmesh.runtime.core.protocol.grpc.producer.EventMeshProducer) OnExceptionContext(org.apache.eventmesh.api.exception.OnExceptionContext) SendMessageContext(org.apache.eventmesh.runtime.core.protocol.grpc.producer.SendMessageContext) SendResult(org.apache.eventmesh.api.SendResult) SendCallback(org.apache.eventmesh.api.SendCallback)

Example 14 with SendResult

use of org.apache.eventmesh.api.SendResult in project incubator-eventmesh by apache.

the class BatchPublishMessageProcessor method process.

public void process(BatchMessage message, EventEmitter<Response> emitter) throws Exception {
    RequestHeader requestHeader = message.getHeader();
    if (!ServiceUtils.validateHeader(requestHeader)) {
        ServiceUtils.sendRespAndDone(StatusCode.EVENTMESH_PROTOCOL_HEADER_ERR, emitter);
        return;
    }
    if (!ServiceUtils.validateBatchMessage(message)) {
        ServiceUtils.sendRespAndDone(StatusCode.EVENTMESH_PROTOCOL_BODY_ERR, emitter);
        return;
    }
    try {
        doAclCheck(message);
    } catch (Exception e) {
        aclLogger.warn("CLIENT HAS NO PERMISSION,BatchSendMessageProcessor send failed", e);
        ServiceUtils.sendRespAndDone(StatusCode.EVENTMESH_ACL_ERR, e.getMessage(), emitter);
        return;
    }
    // control flow rate limit
    if (!eventMeshGrpcServer.getMsgRateLimiter().tryAcquire(EventMeshConstants.DEFAULT_FASTFAIL_TIMEOUT_IN_MILLISECONDS, TimeUnit.MILLISECONDS)) {
        logger.error("Send message speed over limit.");
        ServiceUtils.sendRespAndDone(StatusCode.EVENTMESH_BATCH_SPEED_OVER_LIMIT_ERR, emitter);
        return;
    }
    String topic = message.getTopic();
    String producerGroup = message.getProducerGroup();
    String protocolType = requestHeader.getProtocolType();
    ProtocolAdaptor<ProtocolTransportObject> grpcCommandProtocolAdaptor = ProtocolPluginFactory.getProtocolAdaptor(protocolType);
    List<CloudEvent> cloudEvents = grpcCommandProtocolAdaptor.toBatchCloudEvent(new BatchMessageWrapper(message));
    for (CloudEvent event : cloudEvents) {
        String seqNum = event.getId();
        String uniqueId = event.getExtension(ProtocolKey.UNIQUE_ID).toString();
        ProducerManager producerManager = eventMeshGrpcServer.getProducerManager();
        EventMeshProducer eventMeshProducer = producerManager.getEventMeshProducer(producerGroup);
        SendMessageContext sendMessageContext = new SendMessageContext(seqNum, event, eventMeshProducer, eventMeshGrpcServer);
        long startTime = System.currentTimeMillis();
        eventMeshProducer.send(sendMessageContext, new SendCallback() {

            @Override
            public void onSuccess(SendResult sendResult) {
                long endTime = System.currentTimeMillis();
                logger.info("message|eventMesh2mq|REQ|BatchSend|send2MQCost={}ms|topic={}|bizSeqNo={}|uniqueId={}", endTime - startTime, topic, seqNum, uniqueId);
            }

            @Override
            public void onException(OnExceptionContext context) {
                long endTime = System.currentTimeMillis();
                logger.error("message|eventMesh2mq|REQ|BatchSend|send2MQCost={}ms|topic={}|bizSeqNo={}|uniqueId={}", endTime - startTime, topic, seqNum, uniqueId, context.getException());
            }
        });
    }
    ServiceUtils.sendRespAndDone(StatusCode.SUCCESS, "batch publish success", emitter);
}
Also used : EventMeshProducer(org.apache.eventmesh.runtime.core.protocol.grpc.producer.EventMeshProducer) ProtocolTransportObject(org.apache.eventmesh.common.protocol.ProtocolTransportObject) ProducerManager(org.apache.eventmesh.runtime.core.protocol.grpc.producer.ProducerManager) OnExceptionContext(org.apache.eventmesh.api.exception.OnExceptionContext) BatchMessageWrapper(org.apache.eventmesh.common.protocol.grpc.common.BatchMessageWrapper) AclException(org.apache.eventmesh.api.exception.AclException) SendMessageContext(org.apache.eventmesh.runtime.core.protocol.grpc.producer.SendMessageContext) SendResult(org.apache.eventmesh.api.SendResult) RequestHeader(org.apache.eventmesh.common.protocol.grpc.protos.RequestHeader) CloudEvent(io.cloudevents.CloudEvent) SendCallback(org.apache.eventmesh.api.SendCallback)

Example 15 with SendResult

use of org.apache.eventmesh.api.SendResult 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)

Aggregations

SendResult (org.apache.eventmesh.api.SendResult)20 OnExceptionContext (org.apache.eventmesh.api.exception.OnExceptionContext)17 SendCallback (org.apache.eventmesh.api.SendCallback)15 CloudEvent (io.cloudevents.CloudEvent)7 ProtocolTransportObject (org.apache.eventmesh.common.protocol.ProtocolTransportObject)7 ConnectorRuntimeException (org.apache.eventmesh.api.exception.ConnectorRuntimeException)5 EventMeshProducer (org.apache.eventmesh.runtime.core.protocol.http.producer.EventMeshProducer)5 SendMessageContext (org.apache.eventmesh.runtime.core.protocol.http.producer.SendMessageContext)5 HttpCommand (org.apache.eventmesh.common.protocol.http.HttpCommand)4 EventMeshProducer (org.apache.eventmesh.runtime.core.protocol.grpc.producer.EventMeshProducer)4 SendMessageContext (org.apache.eventmesh.runtime.core.protocol.grpc.producer.SendMessageContext)4 AclException (org.apache.eventmesh.api.exception.AclException)3 RequestHeader (org.apache.eventmesh.common.protocol.grpc.protos.RequestHeader)3 SimpleMessageWrapper (org.apache.eventmesh.common.protocol.grpc.common.SimpleMessageWrapper)2 ProducerManager (org.apache.eventmesh.runtime.core.protocol.grpc.producer.ProducerManager)2 CompleteHandler (org.apache.eventmesh.runtime.core.protocol.http.async.CompleteHandler)2 UpStreamMsgContext (org.apache.eventmesh.runtime.core.protocol.tcp.client.session.send.UpStreamMsgContext)2 CloudEventData (io.cloudevents.CloudEventData)1 CloudEventBuilder (io.cloudevents.core.builder.CloudEventBuilder)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1