use of org.apache.eventmesh.common.protocol.tcp.EventMeshMessage in project incubator-eventmesh by apache.
the class EventMeshTestUtils method generateBroadcastMqMsg.
public static EventMeshMessage generateBroadcastMqMsg() {
EventMeshMessage mqMsg = new EventMeshMessage();
mqMsg.setTopic(ExampleConstants.EVENTMESH_TCP_ASYNC_TEST_TOPIC);
mqMsg.getProperties().put("replyto", "localhost@ProducerGroup-producerPool-9-access#V1_4_0#CI");
mqMsg.getProperties().put("ttl", "30000");
mqMsg.getProperties().put("propertymessagereplyto", "notnull");
mqMsg.setBody("testAsyncMessage");
return mqMsg;
}
use of org.apache.eventmesh.common.protocol.tcp.EventMeshMessage in project incubator-eventmesh by apache.
the class MessageUtils method generateRRMsg.
public static EventMeshMessage generateRRMsg(String topic, int i) {
EventMeshMessage msg = new EventMeshMessage();
msg.setTopic(topic);
msg.getProperties().put("msgtype", "persistent");
msg.getProperties().put("TTL", "300000");
msg.getProperties().put("KEYS", generateRandomString(16));
msg.setBody("testRR" + i);
return msg;
}
use of org.apache.eventmesh.common.protocol.tcp.EventMeshMessage in project incubator-eventmesh by apache.
the class SessionPusher method push.
public void push(final DownStreamMsgContext downStreamMsgContext) {
Command cmd;
if (SubscriptionMode.BROADCASTING.equals(downStreamMsgContext.subscriptionItem.getMode())) {
cmd = Command.BROADCAST_MESSAGE_TO_CLIENT;
} else if (SubscriptionType.SYNC.equals(downStreamMsgContext.subscriptionItem.getType())) {
cmd = Command.REQUEST_TO_CLIENT;
} else {
cmd = Command.ASYNC_MESSAGE_TO_CLIENT;
}
String protocolType = Objects.requireNonNull(downStreamMsgContext.event.getExtension(Constants.PROTOCOL_TYPE)).toString();
ProtocolAdaptor protocolAdaptor = ProtocolPluginFactory.getProtocolAdaptor(protocolType);
Package pkg = new Package();
downStreamMsgContext.event = CloudEventBuilder.from(downStreamMsgContext.event).withExtension(EventMeshConstants.REQ_EVENTMESH2C_TIMESTAMP, String.valueOf(System.currentTimeMillis())).build();
EventMeshMessage body = null;
int retCode = 0;
String retMsg = null;
try {
pkg = (Package) protocolAdaptor.fromCloudEvent(downStreamMsgContext.event);
pkg.setHeader(new Header(cmd, OPStatus.SUCCESS.getCode(), null, downStreamMsgContext.seq));
pkg.getHeader().putProperty(Constants.PROTOCOL_TYPE, protocolType);
messageLogger.info("pkg|mq2eventMesh|cmd={}|mqMsg={}|user={}", cmd, pkg, session.getClient());
} catch (Exception e) {
pkg.setHeader(new Header(cmd, OPStatus.FAIL.getCode(), e.getStackTrace().toString(), downStreamMsgContext.seq));
retCode = -1;
retMsg = e.toString();
} finally {
session.getClientGroupWrapper().get().getEventMeshTcpMonitor().getTcpSummaryMetrics().getEventMesh2clientMsgNum().incrementAndGet();
session.getContext().writeAndFlush(pkg).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
logger.error("downstreamMsg fail,seq:{}, retryTimes:{}, event:{}", downStreamMsgContext.seq, downStreamMsgContext.retryTimes, downStreamMsgContext.event);
deliverFailMsgsCount.incrementAndGet();
// how long to isolate client when push fail
long isolateTime = System.currentTimeMillis() + session.getEventMeshTCPConfiguration().eventMeshTcpPushFailIsolateTimeInMills;
session.setIsolateTime(isolateTime);
logger.warn("isolate client:{},isolateTime:{}", session.getClient(), isolateTime);
// retry
long delayTime = SubscriptionType.SYNC.equals(downStreamMsgContext.subscriptionItem.getType()) ? session.getEventMeshTCPConfiguration().eventMeshTcpMsgRetrySyncDelayInMills : session.getEventMeshTCPConfiguration().eventMeshTcpMsgRetryAsyncDelayInMills;
downStreamMsgContext.delay(delayTime);
session.getClientGroupWrapper().get().getEventMeshTcpRetryer().pushRetry(downStreamMsgContext);
} else {
deliveredMsgsCount.incrementAndGet();
logger.info("downstreamMsg success,seq:{}, retryTimes:{}, bizSeq:{}", downStreamMsgContext.seq, downStreamMsgContext.retryTimes, EventMeshUtil.getMessageBizSeq(downStreamMsgContext.event));
if (session.isIsolated()) {
logger.info("cancel isolated,client:{}", session.getClient());
session.setIsolateTime(System.currentTimeMillis());
}
}
}
});
}
}
use of org.apache.eventmesh.common.protocol.tcp.EventMeshMessage in project incubator-eventmesh by apache.
the class MessageUtils method generateBroadcastMsg.
public static EventMeshMessage generateBroadcastMsg(String topic, int i) {
EventMeshMessage msg = new EventMeshMessage();
msg.setTopic(topic);
msg.getProperties().put("REPLY_TO", "");
msg.getProperties().put("TTL", "30000");
msg.getProperties().put("PROPERTY_MESSAGE_REPLY_TO", "notnull");
msg.setBody("testBroadCastMessage" + i);
return msg;
}
use of org.apache.eventmesh.common.protocol.tcp.EventMeshMessage in project incubator-eventmesh by apache.
the class TcpMessageProtocolResolver method buildEventMeshMessage.
public static Package buildEventMeshMessage(CloudEvent cloudEvent) {
EventMeshMessage eventMeshMessage = new EventMeshMessage();
eventMeshMessage.setTopic(cloudEvent.getSubject());
eventMeshMessage.setBody(new String(cloudEvent.getData().toBytes(), StandardCharsets.UTF_8));
Map<String, String> prop = new HashMap<>();
for (String extKey : cloudEvent.getExtensionNames()) {
prop.put(extKey, cloudEvent.getExtension(extKey).toString());
}
eventMeshMessage.setProperties(prop);
Package pkg = new Package();
pkg.setBody(eventMeshMessage);
return pkg;
}
Aggregations