Search in sources :

Example 1 with SendMessageRequestHeader

use of org.apache.eventmesh.common.protocol.http.header.message.SendMessageRequestHeader in project incubator-eventmesh by apache.

the class SendAsyncMessageProcessor method processRequest.

@Override
public void processRequest(ChannelHandlerContext ctx, AsyncContext<HttpCommand> asyncContext) throws Exception {
    HttpCommand responseEventMeshCommand;
    cmdLogger.info("cmd={}|{}|client2eventMesh|from={}|to={}", RequestCode.get(Integer.valueOf(asyncContext.getRequest().getRequestCode())), EventMeshConstants.PROTOCOL_HTTP, RemotingHelper.parseChannelRemoteAddr(ctx.channel()), IPUtils.getLocalAddress());
    SendMessageRequestHeader sendMessageRequestHeader = (SendMessageRequestHeader) asyncContext.getRequest().getHeader();
    // SendMessageRequestBody sendMessageRequestBody = (SendMessageRequestBody) asyncContext.getRequest().getBody();
    SendMessageResponseHeader sendMessageResponseHeader = SendMessageResponseHeader.buildHeader(Integer.valueOf(asyncContext.getRequest().getRequestCode()), eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster, IPUtils.getLocalAddress(), eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEnv, eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC);
    String protocolType = sendMessageRequestHeader.getProtocolType();
    ProtocolAdaptor<ProtocolTransportObject> httpCommandProtocolAdaptor = ProtocolPluginFactory.getProtocolAdaptor(protocolType);
    CloudEvent event = httpCommandProtocolAdaptor.toCloudEvent(asyncContext.getRequest());
    // validate event
    if (event == null || StringUtils.isBlank(event.getId()) || event.getSource() == null || event.getSpecVersion() == null || StringUtils.isBlank(event.getType()) || StringUtils.isBlank(event.getSubject())) {
        responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse(sendMessageResponseHeader, SendMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg()));
        asyncContext.onComplete(responseEventMeshCommand);
        return;
    }
    String idc = Objects.requireNonNull(event.getExtension(ProtocolKey.ClientInstanceKey.IDC)).toString();
    String pid = Objects.requireNonNull(event.getExtension(ProtocolKey.ClientInstanceKey.PID)).toString();
    String sys = Objects.requireNonNull(event.getExtension(ProtocolKey.ClientInstanceKey.SYS)).toString();
    // validate event-extension
    if (StringUtils.isBlank(idc) || StringUtils.isBlank(pid) || !StringUtils.isNumeric(pid) || StringUtils.isBlank(sys)) {
        responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse(sendMessageResponseHeader, SendMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg()));
        asyncContext.onComplete(responseEventMeshCommand);
        return;
    }
    String bizNo = Objects.requireNonNull(event.getExtension(SendMessageRequestBody.BIZSEQNO)).toString();
    String uniqueId = Objects.requireNonNull(event.getExtension(SendMessageRequestBody.UNIQUEID)).toString();
    String producerGroup = Objects.requireNonNull(event.getExtension(SendMessageRequestBody.PRODUCERGROUP)).toString();
    String topic = event.getSubject();
    // validate body
    if (StringUtils.isBlank(bizNo) || StringUtils.isBlank(uniqueId) || StringUtils.isBlank(producerGroup) || StringUtils.isBlank(topic) || event.getData() == null) {
        responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse(sendMessageResponseHeader, SendMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getRetCode(), EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getErrMsg()));
        asyncContext.onComplete(responseEventMeshCommand);
        return;
    }
    // do acl check
    if (eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshServerSecurityEnable) {
        String remoteAddr = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
        String user = event.getExtension(ProtocolKey.ClientInstanceKey.USERNAME).toString();
        String pass = event.getExtension(ProtocolKey.ClientInstanceKey.PASSWD).toString();
        String subsystem = event.getExtension(ProtocolKey.ClientInstanceKey.SYS).toString();
        int requestCode = Integer.parseInt(asyncContext.getRequest().getRequestCode());
        try {
            Acl.doAclCheckInHttpSend(remoteAddr, user, pass, subsystem, topic, requestCode);
        } catch (Exception e) {
            // String errorMsg = String.format("CLIENT HAS NO PERMISSION,send failed, topic:%s, subsys:%s, realIp:%s", topic, subsys, realIp);
            responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse(sendMessageResponseHeader, SendMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_ACL_ERR.getRetCode(), e.getMessage()));
            asyncContext.onComplete(responseEventMeshCommand);
            aclLogger.warn("CLIENT HAS NO PERMISSION,SendAsyncMessageProcessor send failed", e);
            return;
        }
    }
    // control flow rate limit
    if (!eventMeshHTTPServer.getMsgRateLimiter().tryAcquire(EventMeshConstants.DEFAULT_FASTFAIL_TIMEOUT_IN_MILLISECONDS, TimeUnit.MILLISECONDS)) {
        responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse(sendMessageResponseHeader, SendMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_HTTP_MES_SEND_OVER_LIMIT_ERR.getRetCode(), EventMeshRetCode.EVENTMESH_HTTP_MES_SEND_OVER_LIMIT_ERR.getErrMsg()));
        eventMeshHTTPServer.metrics.getSummaryMetrics().recordHTTPDiscard();
        asyncContext.onComplete(responseEventMeshCommand);
        return;
    }
    EventMeshProducer eventMeshProducer = eventMeshHTTPServer.getProducerManager().getEventMeshProducer(producerGroup);
    if (!eventMeshProducer.getStarted().get()) {
        responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse(sendMessageResponseHeader, SendMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_GROUP_PRODUCER_STOPED_ERR.getRetCode(), EventMeshRetCode.EVENTMESH_GROUP_PRODUCER_STOPED_ERR.getErrMsg()));
        asyncContext.onComplete(responseEventMeshCommand);
        return;
    }
    String ttl = String.valueOf(EventMeshConstants.DEFAULT_MSG_TTL_MILLS);
    if (StringUtils.isBlank(event.getExtension(SendMessageRequestBody.TTL).toString()) && !StringUtils.isNumeric(event.getExtension(SendMessageRequestBody.TTL).toString())) {
        event = CloudEventBuilder.from(event).withExtension(SendMessageRequestBody.TTL, ttl).build();
    }
    String content = new String(event.getData().toBytes(), StandardCharsets.UTF_8);
    if (content.length() > eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEventSize) {
        httpLogger.error("Event size exceeds the limit: {}", eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEventSize);
        responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse(sendMessageResponseHeader, SendMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getRetCode(), "Event size exceeds the limit: " + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEventSize));
        asyncContext.onComplete(responseEventMeshCommand);
        return;
    }
    try {
        // body
        // omsMsg.setBody(sendMessageRequestBody.getContent().getBytes(EventMeshConstants.DEFAULT_CHARSET));
        // // topic
        // omsMsg.setTopic(sendMessageRequestBody.getTopic());
        // omsMsg.putSystemProperties(Constants.PROPERTY_MESSAGE_DESTINATION, sendMessageRequestBody.getTopic());
        // 
        // if (!StringUtils.isBlank(sendMessageRequestBody.getTag())) {
        // omsMsg.putUserProperties(EventMeshConstants.TAG, sendMessageRequestBody.getTag());
        // }
        // ttl
        // omsMsg.putUserProperties(Constants.PROPERTY_MESSAGE_TIMEOUT, ttl);
        // // bizNo
        // omsMsg.putSystemProperties(Constants.PROPERTY_MESSAGE_SEARCH_KEYS, sendMessageRequestBody.getBizSeqNo());
        event = CloudEventBuilder.from(event).withExtension("msgtype", "persistent").withExtension(EventMeshConstants.REQ_C2EVENTMESH_TIMESTAMP, String.valueOf(System.currentTimeMillis())).withExtension(EventMeshConstants.REQ_EVENTMESH2MQ_TIMESTAMP, String.valueOf(System.currentTimeMillis())).build();
        if (messageLogger.isDebugEnabled()) {
            messageLogger.debug("msg2MQMsg suc, bizSeqNo={}, topic={}", bizNo, topic);
        }
    } catch (Exception e) {
        messageLogger.error("msg2MQMsg err, bizSeqNo={}, topic={}", bizNo, topic, e);
        responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse(sendMessageResponseHeader, SendMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PACKAGE_MSG_ERR.getRetCode(), EventMeshRetCode.EVENTMESH_PACKAGE_MSG_ERR.getErrMsg() + EventMeshUtil.stackTrace(e, 2)));
        asyncContext.onComplete(responseEventMeshCommand);
        return;
    }
    final SendMessageContext sendMessageContext = new SendMessageContext(bizNo, event, eventMeshProducer, eventMeshHTTPServer);
    eventMeshHTTPServer.metrics.getSummaryMetrics().recordSendMsg();
    long startTime = System.currentTimeMillis();
    final CompleteHandler<HttpCommand> handler = new CompleteHandler<HttpCommand>() {

        @Override
        public void onResponse(HttpCommand httpCommand) {
            try {
                if (httpLogger.isDebugEnabled()) {
                    httpLogger.debug("{}", httpCommand);
                }
                eventMeshHTTPServer.sendResponse(ctx, httpCommand.httpResponse());
                eventMeshHTTPServer.metrics.getSummaryMetrics().recordHTTPReqResTimeCost(System.currentTimeMillis() - asyncContext.getRequest().getReqTime());
            } catch (Exception ex) {
            // ignore
            }
        }
    };
    try {
        event = CloudEventBuilder.from(sendMessageContext.getEvent()).withExtension(EventMeshConstants.REQ_EVENTMESH2MQ_TIMESTAMP, String.valueOf(System.currentTimeMillis())).build();
        sendMessageContext.setEvent(event);
        eventMeshProducer.send(sendMessageContext, new SendCallback() {

            @Override
            public void onSuccess(SendResult sendResult) {
                HttpCommand succ = asyncContext.getRequest().createHttpCommandResponse(sendMessageResponseHeader, SendMessageResponseBody.buildBody(EventMeshRetCode.SUCCESS.getRetCode(), EventMeshRetCode.SUCCESS.getErrMsg() + sendResult.toString()));
                asyncContext.onComplete(succ, handler);
                long endTime = System.currentTimeMillis();
                eventMeshHTTPServer.metrics.getSummaryMetrics().recordSendMsgCost(endTime - startTime);
                messageLogger.info("message|eventMesh2mq|REQ|ASYNC|send2MQCost={}ms|topic={}|bizSeqNo={}|uniqueId={}", endTime - startTime, topic, bizNo, uniqueId);
            }

            @Override
            public void onException(OnExceptionContext context) {
                HttpCommand err = asyncContext.getRequest().createHttpCommandResponse(sendMessageResponseHeader, SendMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_SEND_ASYNC_MSG_ERR.getRetCode(), EventMeshRetCode.EVENTMESH_SEND_ASYNC_MSG_ERR.getErrMsg() + EventMeshUtil.stackTrace(context.getException(), 2)));
                asyncContext.onComplete(err, handler);
                eventMeshHTTPServer.getHttpRetryer().pushRetry(sendMessageContext.delay(10000));
                long endTime = System.currentTimeMillis();
                eventMeshHTTPServer.metrics.getSummaryMetrics().recordSendMsgFailed();
                eventMeshHTTPServer.metrics.getSummaryMetrics().recordSendMsgCost(endTime - startTime);
                messageLogger.error("message|eventMesh2mq|REQ|ASYNC|send2MQCost={}ms|topic={}|bizSeqNo={}|uniqueId={}", endTime - startTime, topic, bizNo, uniqueId, context.getException());
            }
        });
    } catch (Exception ex) {
        HttpCommand err = asyncContext.getRequest().createHttpCommandResponse(sendMessageResponseHeader, SendMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_SEND_ASYNC_MSG_ERR.getRetCode(), EventMeshRetCode.EVENTMESH_SEND_ASYNC_MSG_ERR.getErrMsg() + EventMeshUtil.stackTrace(ex, 2)));
        asyncContext.onComplete(err);
        eventMeshHTTPServer.getHttpRetryer().pushRetry(sendMessageContext.delay(10000));
        long endTime = System.currentTimeMillis();
        messageLogger.error("message|eventMesh2mq|REQ|ASYNC|send2MQCost={}ms|topic={}|bizSeqNo={}|uniqueId={}", endTime - startTime, topic, bizNo, uniqueId, ex);
        eventMeshHTTPServer.metrics.getSummaryMetrics().recordSendMsgFailed();
        eventMeshHTTPServer.metrics.getSummaryMetrics().recordSendMsgCost(endTime - startTime);
    }
    return;
}
Also used : SendMessageResponseHeader(org.apache.eventmesh.common.protocol.http.header.message.SendMessageResponseHeader) EventMeshProducer(org.apache.eventmesh.runtime.core.protocol.http.producer.EventMeshProducer) SendMessageRequestHeader(org.apache.eventmesh.common.protocol.http.header.message.SendMessageRequestHeader) ProtocolTransportObject(org.apache.eventmesh.common.protocol.ProtocolTransportObject) OnExceptionContext(org.apache.eventmesh.api.exception.OnExceptionContext) SendMessageContext(org.apache.eventmesh.runtime.core.protocol.http.producer.SendMessageContext) SendResult(org.apache.eventmesh.api.SendResult) CompleteHandler(org.apache.eventmesh.runtime.core.protocol.http.async.CompleteHandler) HttpCommand(org.apache.eventmesh.common.protocol.http.HttpCommand) CloudEvent(io.cloudevents.CloudEvent) SendCallback(org.apache.eventmesh.api.SendCallback)

Example 2 with SendMessageRequestHeader

use of org.apache.eventmesh.common.protocol.http.header.message.SendMessageRequestHeader in project incubator-eventmesh by apache.

the class SendMessageRequestProtocolResolver method buildEvent.

public static CloudEvent buildEvent(Header header, Body body) throws ProtocolHandleException {
    try {
        SendMessageRequestHeader sendMessageRequestHeader = (SendMessageRequestHeader) header;
        SendMessageRequestBody sendMessageRequestBody = (SendMessageRequestBody) body;
        String protocolType = sendMessageRequestHeader.getProtocolType();
        String protocolDesc = sendMessageRequestHeader.getProtocolDesc();
        String protocolVersion = sendMessageRequestHeader.getProtocolVersion();
        String code = sendMessageRequestHeader.getCode();
        String env = sendMessageRequestHeader.getEnv();
        String idc = sendMessageRequestHeader.getIdc();
        String ip = sendMessageRequestHeader.getIp();
        String pid = sendMessageRequestHeader.getPid();
        String sys = sendMessageRequestHeader.getSys();
        String username = sendMessageRequestHeader.getUsername();
        String passwd = sendMessageRequestHeader.getPasswd();
        ProtocolVersion version = sendMessageRequestHeader.getVersion();
        String language = sendMessageRequestHeader.getLanguage();
        String producerGroup = sendMessageRequestBody.getProducerGroup();
        String content = sendMessageRequestBody.getContent();
        CloudEvent event = null;
        if (StringUtils.equals(SpecVersion.V1.toString(), protocolVersion)) {
            event = EventFormatProvider.getInstance().resolveFormat(JsonFormat.CONTENT_TYPE).deserialize(content.getBytes(StandardCharsets.UTF_8));
            event = CloudEventBuilder.v1(event).withExtension(ProtocolKey.REQUEST_CODE, code).withExtension(ProtocolKey.ClientInstanceKey.ENV, env).withExtension(ProtocolKey.ClientInstanceKey.IDC, idc).withExtension(ProtocolKey.ClientInstanceKey.IP, ip).withExtension(ProtocolKey.ClientInstanceKey.PID, pid).withExtension(ProtocolKey.ClientInstanceKey.SYS, sys).withExtension(ProtocolKey.ClientInstanceKey.USERNAME, username).withExtension(ProtocolKey.ClientInstanceKey.PASSWD, passwd).withExtension(ProtocolKey.VERSION, version.getVersion()).withExtension(ProtocolKey.LANGUAGE, language).withExtension(ProtocolKey.PROTOCOL_TYPE, protocolType).withExtension(ProtocolKey.PROTOCOL_DESC, protocolDesc).withExtension(ProtocolKey.PROTOCOL_VERSION, protocolVersion).withExtension(SendMessageRequestBody.PRODUCERGROUP, producerGroup).build();
        } else if (StringUtils.equals(SpecVersion.V03.toString(), protocolVersion)) {
            event = EventFormatProvider.getInstance().resolveFormat(JsonFormat.CONTENT_TYPE).deserialize(content.getBytes(StandardCharsets.UTF_8));
            event = CloudEventBuilder.v03(event).withExtension(ProtocolKey.REQUEST_CODE, code).withExtension(ProtocolKey.ClientInstanceKey.ENV, env).withExtension(ProtocolKey.ClientInstanceKey.IDC, idc).withExtension(ProtocolKey.ClientInstanceKey.IP, ip).withExtension(ProtocolKey.ClientInstanceKey.PID, pid).withExtension(ProtocolKey.ClientInstanceKey.SYS, sys).withExtension(ProtocolKey.ClientInstanceKey.USERNAME, username).withExtension(ProtocolKey.ClientInstanceKey.PASSWD, passwd).withExtension(ProtocolKey.VERSION, version.getVersion()).withExtension(ProtocolKey.LANGUAGE, language).withExtension(ProtocolKey.PROTOCOL_TYPE, protocolType).withExtension(ProtocolKey.PROTOCOL_DESC, protocolDesc).withExtension(ProtocolKey.PROTOCOL_VERSION, protocolVersion).withExtension(SendMessageRequestBody.PRODUCERGROUP, producerGroup).build();
        }
        return event;
    } catch (Exception e) {
        throw new ProtocolHandleException(e.getMessage(), e.getCause());
    }
}
Also used : SendMessageRequestHeader(org.apache.eventmesh.common.protocol.http.header.message.SendMessageRequestHeader) ProtocolHandleException(org.apache.eventmesh.protocol.api.exception.ProtocolHandleException) ProtocolVersion(org.apache.eventmesh.common.protocol.http.common.ProtocolVersion) SendMessageRequestBody(org.apache.eventmesh.common.protocol.http.body.message.SendMessageRequestBody) CloudEvent(io.cloudevents.CloudEvent) ProtocolHandleException(org.apache.eventmesh.protocol.api.exception.ProtocolHandleException)

Example 3 with SendMessageRequestHeader

use of org.apache.eventmesh.common.protocol.http.header.message.SendMessageRequestHeader in project incubator-eventmesh by apache.

the class SendMessageRequestProtocolResolver method buildEvent.

public static CloudEvent buildEvent(Header header, Body body) throws ProtocolHandleException {
    try {
        SendMessageRequestHeader sendMessageRequestHeader = (SendMessageRequestHeader) header;
        SendMessageRequestBody sendMessageRequestBody = (SendMessageRequestBody) body;
        String protocolType = sendMessageRequestHeader.getProtocolType();
        String protocolDesc = sendMessageRequestHeader.getProtocolDesc();
        String protocolVersion = sendMessageRequestHeader.getProtocolVersion();
        String code = sendMessageRequestHeader.getCode();
        String env = sendMessageRequestHeader.getEnv();
        String idc = sendMessageRequestHeader.getIdc();
        String ip = sendMessageRequestHeader.getIp();
        String pid = sendMessageRequestHeader.getPid();
        String sys = sendMessageRequestHeader.getSys();
        String username = sendMessageRequestHeader.getUsername();
        String passwd = sendMessageRequestHeader.getPasswd();
        ProtocolVersion version = sendMessageRequestHeader.getVersion();
        String language = sendMessageRequestHeader.getLanguage();
        String content = sendMessageRequestBody.getContent();
        CloudEvent event = null;
        CloudEventBuilder cloudEventBuilder;
        if (StringUtils.equals(SpecVersion.V1.toString(), protocolVersion)) {
            cloudEventBuilder = CloudEventBuilder.v1();
            cloudEventBuilder = cloudEventBuilder.withId(sendMessageRequestBody.getBizSeqNo()).withSubject(sendMessageRequestBody.getTopic()).withType("eventmeshmessage").withSource(URI.create("/")).withData(content.getBytes(StandardCharsets.UTF_8)).withExtension(ProtocolKey.REQUEST_CODE, code).withExtension(ProtocolKey.ClientInstanceKey.ENV, env).withExtension(ProtocolKey.ClientInstanceKey.IDC, idc).withExtension(ProtocolKey.ClientInstanceKey.IP, ip).withExtension(ProtocolKey.ClientInstanceKey.PID, pid).withExtension(ProtocolKey.ClientInstanceKey.SYS, sys).withExtension(ProtocolKey.ClientInstanceKey.USERNAME, username).withExtension(ProtocolKey.ClientInstanceKey.PASSWD, passwd).withExtension(ProtocolKey.VERSION, version.getVersion()).withExtension(ProtocolKey.LANGUAGE, language).withExtension(ProtocolKey.PROTOCOL_TYPE, protocolType).withExtension(ProtocolKey.PROTOCOL_DESC, protocolDesc).withExtension(ProtocolKey.PROTOCOL_VERSION, protocolVersion).withExtension(SendMessageRequestBody.BIZSEQNO, sendMessageRequestBody.getBizSeqNo()).withExtension(SendMessageRequestBody.UNIQUEID, sendMessageRequestBody.getUniqueId()).withExtension(SendMessageRequestBody.PRODUCERGROUP, sendMessageRequestBody.getProducerGroup()).withExtension(SendMessageRequestBody.TTL, sendMessageRequestBody.getTtl());
            if (StringUtils.isNotEmpty(sendMessageRequestBody.getTag())) {
                cloudEventBuilder = cloudEventBuilder.withExtension(SendMessageRequestBody.TAG, sendMessageRequestBody.getTag());
            }
            event = cloudEventBuilder.build();
        } else if (StringUtils.equals(SpecVersion.V03.toString(), protocolVersion)) {
            cloudEventBuilder = CloudEventBuilder.v03();
            cloudEventBuilder = cloudEventBuilder.withId(sendMessageRequestBody.getBizSeqNo()).withSubject(sendMessageRequestBody.getTopic()).withType("eventmeshmessage").withSource(URI.create("/")).withData(content.getBytes(StandardCharsets.UTF_8)).withExtension(ProtocolKey.REQUEST_CODE, code).withExtension(ProtocolKey.ClientInstanceKey.ENV, env).withExtension(ProtocolKey.ClientInstanceKey.IDC, idc).withExtension(ProtocolKey.ClientInstanceKey.IP, ip).withExtension(ProtocolKey.ClientInstanceKey.PID, pid).withExtension(ProtocolKey.ClientInstanceKey.SYS, sys).withExtension(ProtocolKey.ClientInstanceKey.USERNAME, username).withExtension(ProtocolKey.ClientInstanceKey.PASSWD, passwd).withExtension(ProtocolKey.VERSION, version.getVersion()).withExtension(ProtocolKey.LANGUAGE, language).withExtension(ProtocolKey.PROTOCOL_TYPE, protocolType).withExtension(ProtocolKey.PROTOCOL_DESC, protocolDesc).withExtension(ProtocolKey.PROTOCOL_VERSION, protocolVersion).withExtension(SendMessageRequestBody.BIZSEQNO, sendMessageRequestBody.getBizSeqNo()).withExtension(SendMessageRequestBody.UNIQUEID, sendMessageRequestBody.getUniqueId()).withExtension(SendMessageRequestBody.PRODUCERGROUP, sendMessageRequestBody.getProducerGroup()).withExtension(SendMessageRequestBody.TTL, sendMessageRequestBody.getTtl());
            if (StringUtils.isNotEmpty(sendMessageRequestBody.getTag())) {
                cloudEventBuilder = cloudEventBuilder.withExtension(SendMessageRequestBody.TAG, sendMessageRequestBody.getTag());
            }
            event = cloudEventBuilder.build();
        }
        return event;
    } catch (Exception e) {
        throw new ProtocolHandleException(e.getMessage(), e.getCause());
    }
}
Also used : SendMessageRequestHeader(org.apache.eventmesh.common.protocol.http.header.message.SendMessageRequestHeader) ProtocolHandleException(org.apache.eventmesh.protocol.api.exception.ProtocolHandleException) CloudEventBuilder(io.cloudevents.core.builder.CloudEventBuilder) ProtocolVersion(org.apache.eventmesh.common.protocol.http.common.ProtocolVersion) SendMessageRequestBody(org.apache.eventmesh.common.protocol.http.body.message.SendMessageRequestBody) CloudEvent(io.cloudevents.CloudEvent) ProtocolHandleException(org.apache.eventmesh.protocol.api.exception.ProtocolHandleException)

Aggregations

CloudEvent (io.cloudevents.CloudEvent)3 SendMessageRequestHeader (org.apache.eventmesh.common.protocol.http.header.message.SendMessageRequestHeader)3 SendMessageRequestBody (org.apache.eventmesh.common.protocol.http.body.message.SendMessageRequestBody)2 ProtocolVersion (org.apache.eventmesh.common.protocol.http.common.ProtocolVersion)2 ProtocolHandleException (org.apache.eventmesh.protocol.api.exception.ProtocolHandleException)2 CloudEventBuilder (io.cloudevents.core.builder.CloudEventBuilder)1 SendCallback (org.apache.eventmesh.api.SendCallback)1 SendResult (org.apache.eventmesh.api.SendResult)1 OnExceptionContext (org.apache.eventmesh.api.exception.OnExceptionContext)1 ProtocolTransportObject (org.apache.eventmesh.common.protocol.ProtocolTransportObject)1 HttpCommand (org.apache.eventmesh.common.protocol.http.HttpCommand)1 SendMessageResponseHeader (org.apache.eventmesh.common.protocol.http.header.message.SendMessageResponseHeader)1 CompleteHandler (org.apache.eventmesh.runtime.core.protocol.http.async.CompleteHandler)1 EventMeshProducer (org.apache.eventmesh.runtime.core.protocol.http.producer.EventMeshProducer)1 SendMessageContext (org.apache.eventmesh.runtime.core.protocol.http.producer.SendMessageContext)1