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());
}
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);
}
}
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;
}
Aggregations