Search in sources :

Example 1 with Response

use of org.apache.eventmesh.common.protocol.grpc.protos.Response in project incubator-eventmesh by apache.

the class HeartbeatService method heartbeat.

public void heartbeat(Heartbeat request, StreamObserver<Response> responseObserver) {
    logger.info("cmd={}|{}|client2eventMesh|from={}|to={}", "heartbeat", EventMeshConstants.PROTOCOL_GRPC, request.getHeader().getIp(), eventMeshGrpcServer.getEventMeshGrpcConfiguration().eventMeshIp);
    EventEmitter<Response> emitter = new EventEmitter<>(responseObserver);
    threadPoolExecutor.submit(() -> {
        HeartbeatProcessor heartbeatProcessor = new HeartbeatProcessor(eventMeshGrpcServer);
        try {
            heartbeatProcessor.process(request, emitter);
        } catch (Exception e) {
            logger.error("Error code {}, error message {}", StatusCode.EVENTMESH_HEARTBEAT_ERR.getRetCode(), StatusCode.EVENTMESH_HEARTBEAT_ERR.getErrMsg(), e);
            ServiceUtils.sendRespAndDone(StatusCode.EVENTMESH_HEARTBEAT_ERR, e.getMessage(), emitter);
        }
    });
}
Also used : Response(org.apache.eventmesh.common.protocol.grpc.protos.Response) HeartbeatProcessor(org.apache.eventmesh.runtime.core.protocol.grpc.processor.HeartbeatProcessor)

Example 2 with Response

use of org.apache.eventmesh.common.protocol.grpc.protos.Response in project incubator-eventmesh by apache.

the class ProducerService method publish.

public void publish(SimpleMessage request, StreamObserver<Response> responseObserver) {
    cmdLogger.info("cmd={}|{}|client2eventMesh|from={}|to={}", "AsyncPublish", EventMeshConstants.PROTOCOL_GRPC, request.getHeader().getIp(), eventMeshGrpcServer.getEventMeshGrpcConfiguration().eventMeshIp);
    EventEmitter<Response> emitter = new EventEmitter<>(responseObserver);
    threadPoolExecutor.submit(() -> {
        SendAsyncMessageProcessor sendAsyncMessageProcessor = new SendAsyncMessageProcessor(eventMeshGrpcServer);
        try {
            sendAsyncMessageProcessor.process(request, emitter);
        } catch (Exception e) {
            logger.error("Error code {}, error message {}", StatusCode.EVENTMESH_SEND_ASYNC_MSG_ERR.getRetCode(), StatusCode.EVENTMESH_SEND_ASYNC_MSG_ERR.getErrMsg(), e);
            ServiceUtils.sendRespAndDone(StatusCode.EVENTMESH_SEND_ASYNC_MSG_ERR, e.getMessage(), emitter);
        }
    });
}
Also used : Response(org.apache.eventmesh.common.protocol.grpc.protos.Response) SendAsyncMessageProcessor(org.apache.eventmesh.runtime.core.protocol.grpc.processor.SendAsyncMessageProcessor)

Example 3 with Response

use of org.apache.eventmesh.common.protocol.grpc.protos.Response in project incubator-eventmesh by apache.

the class ProducerService method batchPublish.

public void batchPublish(BatchMessage request, StreamObserver<Response> responseObserver) {
    cmdLogger.info("cmd={}|{}|client2eventMesh|from={}|to={}", "BatchPublish", EventMeshConstants.PROTOCOL_GRPC, request.getHeader().getIp(), eventMeshGrpcServer.getEventMeshGrpcConfiguration().eventMeshIp);
    EventEmitter<Response> emitter = new EventEmitter<>(responseObserver);
    threadPoolExecutor.submit(() -> {
        BatchPublishMessageProcessor batchPublishMessageProcessor = new BatchPublishMessageProcessor(eventMeshGrpcServer);
        try {
            batchPublishMessageProcessor.process(request, emitter);
        } catch (Exception e) {
            logger.error("Error code {}, error message {}", StatusCode.EVENTMESH_BATCH_PUBLISH_ERR.getRetCode(), StatusCode.EVENTMESH_BATCH_PUBLISH_ERR.getErrMsg(), e);
            ServiceUtils.sendRespAndDone(StatusCode.EVENTMESH_BATCH_PUBLISH_ERR, e.getMessage(), emitter);
        }
    });
}
Also used : Response(org.apache.eventmesh.common.protocol.grpc.protos.Response) BatchPublishMessageProcessor(org.apache.eventmesh.runtime.core.protocol.grpc.processor.BatchPublishMessageProcessor)

Example 4 with Response

use of org.apache.eventmesh.common.protocol.grpc.protos.Response in project incubator-eventmesh by apache.

the class ServiceUtils method sendRespAndDone.

public static void sendRespAndDone(StatusCode code, EventEmitter<Response> emitter) {
    Response response = Response.newBuilder().setRespCode(code.getRetCode()).setRespMsg(code.getErrMsg()).setRespTime(String.valueOf(System.currentTimeMillis())).build();
    emitter.onNext(response);
    emitter.onCompleted();
}
Also used : Response(org.apache.eventmesh.common.protocol.grpc.protos.Response)

Example 5 with Response

use of org.apache.eventmesh.common.protocol.grpc.protos.Response in project incubator-eventmesh by apache.

the class ServiceUtils method sendRespAndDone.

public static void sendRespAndDone(StatusCode code, String message, EventEmitter<Response> emitter) {
    Response response = Response.newBuilder().setRespCode(code.getRetCode()).setRespMsg(code.getErrMsg() + " " + message).setRespTime(String.valueOf(System.currentTimeMillis())).build();
    emitter.onNext(response);
    emitter.onCompleted();
}
Also used : Response(org.apache.eventmesh.common.protocol.grpc.protos.Response)

Aggregations

Response (org.apache.eventmesh.common.protocol.grpc.protos.Response)15 CloudEvent (io.cloudevents.CloudEvent)3 SimpleMessage (org.apache.eventmesh.common.protocol.grpc.protos.SimpleMessage)3 Subscription (org.apache.eventmesh.common.protocol.grpc.protos.Subscription)3 BatchMessage (org.apache.eventmesh.common.protocol.grpc.protos.BatchMessage)2 CloudEventBuilder (io.cloudevents.core.builder.CloudEventBuilder)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Collectors (java.util.stream.Collectors)1 EventMeshGrpcClientConfig (org.apache.eventmesh.client.grpc.config.EventMeshGrpcClientConfig)1 EventMeshClientUtil (org.apache.eventmesh.client.grpc.util.EventMeshClientUtil)1 EventMeshCommon (org.apache.eventmesh.client.tcp.common.EventMeshCommon)1 Constants (org.apache.eventmesh.common.Constants)1 ProtocolKey (org.apache.eventmesh.common.protocol.grpc.common.ProtocolKey)1 Heartbeat (org.apache.eventmesh.common.protocol.grpc.protos.Heartbeat)1 PublisherServiceBlockingStub (org.apache.eventmesh.common.protocol.grpc.protos.PublisherServiceGrpc.PublisherServiceBlockingStub)1 RequestHeader (org.apache.eventmesh.common.protocol.grpc.protos.RequestHeader)1 IPUtils (org.apache.eventmesh.common.utils.IPUtils)1 RandomStringUtils (org.apache.eventmesh.common.utils.RandomStringUtils)1