Search in sources :

Example 1 with Message

use of io.openmessaging.api.Message in project incubator-eventmesh by apache.

the class EventMeshTCPClientFactoryTest method createEventMeshTCPClient.

@Test
public void createEventMeshTCPClient() {
    EventMeshTCPClientConfig meshTCPClientConfig = EventMeshTCPClientConfig.builder().host("localhost").port(1234).build();
    EventMeshTCPClient<EventMeshMessage> eventMeshMessageTCPClient = EventMeshTCPClientFactory.createEventMeshTCPClient(meshTCPClientConfig, EventMeshMessage.class);
    Assert.assertEquals(EventMeshMessageTCPClient.class, eventMeshMessageTCPClient.getClass());
    EventMeshTCPClient<CloudEvent> cloudEventTCPClient = EventMeshTCPClientFactory.createEventMeshTCPClient(meshTCPClientConfig, CloudEvent.class);
    Assert.assertEquals(CloudEventTCPClient.class, cloudEventTCPClient.getClass());
    EventMeshTCPClient<Message> openMessageTCPClient = EventMeshTCPClientFactory.createEventMeshTCPClient(meshTCPClientConfig, Message.class);
    Assert.assertEquals(OpenMessageTCPClient.class, openMessageTCPClient.getClass());
}
Also used : EventMeshTCPClientConfig(org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig) Message(io.openmessaging.api.Message) EventMeshMessage(org.apache.eventmesh.common.protocol.tcp.EventMeshMessage) CloudEvent(io.cloudevents.CloudEvent) EventMeshMessage(org.apache.eventmesh.common.protocol.tcp.EventMeshMessage) Test(org.junit.Test)

Example 2 with Message

use of io.openmessaging.api.Message in project incubator-eventmesh by apache.

the class OpenMessageProducer method request.

@Override
public void request(Message message, RRCallback<Message> rrCallback, long timeout) throws EventMeshException {
    validateOpenMessage(message);
    RequestParam requestParam = buildCommonPostParam(message).addHeader(ProtocolKey.REQUEST_CODE, RequestCode.MSG_SEND_SYNC.getRequestCode()).setTimeout(timeout);
    String target = selectEventMesh();
    RRCallbackResponseHandlerAdapter<Message> adapter = new RRCallbackResponseHandlerAdapter<>(message, rrCallback, timeout);
    try {
        HttpUtils.post(httpClient, null, target, requestParam, adapter);
    } catch (IOException e) {
        throw new EventMeshException(String.format("Request message error, target:%s", target), e);
    }
}
Also used : RequestParam(org.apache.eventmesh.client.http.model.RequestParam) Message(io.openmessaging.api.Message) IOException(java.io.IOException) EventMeshException(org.apache.eventmesh.common.exception.EventMeshException)

Example 3 with Message

use of io.openmessaging.api.Message in project incubator-eventmesh by apache.

the class MessageUtils method buildPackage.

public static Package buildPackage(Object message, Command command) {
    Package msg = new Package();
    msg.setHeader(new Header(command, 0, null, generateRandomString(seqLength)));
    if (message instanceof CloudEvent) {
        CloudEvent cloudEvent = (CloudEvent) message;
        Preconditions.checkNotNull(cloudEvent.getDataContentType(), "DateContentType cannot be null");
        msg.getHeader().putProperty(Constants.PROTOCOL_TYPE, EventMeshCommon.CLOUD_EVENTS_PROTOCOL_NAME);
        msg.getHeader().putProperty(Constants.PROTOCOL_VERSION, cloudEvent.getSpecVersion().toString());
        msg.getHeader().putProperty(Constants.PROTOCOL_DESC, "tcp");
        byte[] bodyByte = EventFormatProvider.getInstance().resolveFormat(cloudEvent.getDataContentType()).serialize((CloudEvent) message);
        msg.setBody(bodyByte);
    } else if (message instanceof EventMeshMessage) {
        msg.getHeader().putProperty(Constants.PROTOCOL_TYPE, EventMeshCommon.EM_MESSAGE_PROTOCOL_NAME);
        msg.getHeader().putProperty(Constants.PROTOCOL_VERSION, SpecVersion.V1.toString());
        msg.getHeader().putProperty(Constants.PROTOCOL_DESC, "tcp");
        msg.setBody(message);
    } else if (message instanceof Message) {
        msg.getHeader().putProperty(Constants.PROTOCOL_TYPE, EventMeshCommon.OPEN_MESSAGE_PROTOCOL_NAME);
        // todo: this version need to be confirmed.
        msg.getHeader().putProperty(Constants.PROTOCOL_VERSION, SpecVersion.V1.toString());
    } else {
        // unsupported protocol for server
        throw new IllegalArgumentException("Unsupported message protocol");
    }
    return msg;
}
Also used : Header(org.apache.eventmesh.common.protocol.tcp.Header) Message(io.openmessaging.api.Message) EventMeshMessage(org.apache.eventmesh.common.protocol.tcp.EventMeshMessage) Package(org.apache.eventmesh.common.protocol.tcp.Package) CloudEvent(io.cloudevents.CloudEvent) EventMeshMessage(org.apache.eventmesh.common.protocol.tcp.EventMeshMessage)

Aggregations

Message (io.openmessaging.api.Message)3 CloudEvent (io.cloudevents.CloudEvent)2 EventMeshMessage (org.apache.eventmesh.common.protocol.tcp.EventMeshMessage)2 IOException (java.io.IOException)1 RequestParam (org.apache.eventmesh.client.http.model.RequestParam)1 EventMeshTCPClientConfig (org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig)1 EventMeshException (org.apache.eventmesh.common.exception.EventMeshException)1 Header (org.apache.eventmesh.common.protocol.tcp.Header)1 Package (org.apache.eventmesh.common.protocol.tcp.Package)1 Test (org.junit.Test)1