Search in sources :

Example 1 with SendMessageRequestBody

use of org.apache.eventmesh.common.protocol.http.body.message.SendMessageRequestBody 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 2 with SendMessageRequestBody

use of org.apache.eventmesh.common.protocol.http.body.message.SendMessageRequestBody 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)2 SendMessageRequestBody (org.apache.eventmesh.common.protocol.http.body.message.SendMessageRequestBody)2 ProtocolVersion (org.apache.eventmesh.common.protocol.http.common.ProtocolVersion)2 SendMessageRequestHeader (org.apache.eventmesh.common.protocol.http.header.message.SendMessageRequestHeader)2 ProtocolHandleException (org.apache.eventmesh.protocol.api.exception.ProtocolHandleException)2 CloudEventBuilder (io.cloudevents.core.builder.CloudEventBuilder)1