Search in sources :

Example 1 with EventMeshMessage

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;
}
Also used : EventMeshMessage(org.apache.eventmesh.common.protocol.tcp.EventMeshMessage)

Example 2 with EventMeshMessage

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;
}
Also used : EventMeshMessage(org.apache.eventmesh.common.protocol.tcp.EventMeshMessage)

Example 3 with EventMeshMessage

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());
                    }
                }
            }
        });
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) Header(org.apache.eventmesh.common.protocol.tcp.Header) Command(org.apache.eventmesh.common.protocol.tcp.Command) ProtocolAdaptor(org.apache.eventmesh.protocol.api.ProtocolAdaptor) Package(org.apache.eventmesh.common.protocol.tcp.Package) ChannelFutureListener(io.netty.channel.ChannelFutureListener) EventMeshMessage(org.apache.eventmesh.common.protocol.tcp.EventMeshMessage)

Example 4 with EventMeshMessage

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;
}
Also used : EventMeshMessage(org.apache.eventmesh.common.protocol.tcp.EventMeshMessage)

Example 5 with EventMeshMessage

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;
}
Also used : HashMap(java.util.HashMap) Package(org.apache.eventmesh.common.protocol.tcp.Package) EventMeshMessage(org.apache.eventmesh.common.protocol.tcp.EventMeshMessage)

Aggregations

EventMeshMessage (org.apache.eventmesh.common.protocol.tcp.EventMeshMessage)22 Package (org.apache.eventmesh.common.protocol.tcp.Package)7 EventMeshTCPClientConfig (org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig)5 Properties (java.util.Properties)4 UserAgent (org.apache.eventmesh.common.protocol.tcp.UserAgent)4 CloudEvent (io.cloudevents.CloudEvent)2 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)2 Message (io.openmessaging.api.Message)2 Header (org.apache.eventmesh.common.protocol.tcp.Header)2 ReceiveMsgHook (org.apache.eventmesh.runtime.client.hook.ReceiveMsgHook)2 SubClientImpl (org.apache.eventmesh.runtime.client.impl.SubClientImpl)2 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelFutureListener (io.netty.channel.ChannelFutureListener)1 HashMap (java.util.HashMap)1 Command (org.apache.eventmesh.common.protocol.tcp.Command)1 ProtocolAdaptor (org.apache.eventmesh.protocol.api.ProtocolAdaptor)1 PubClientImpl (org.apache.eventmesh.runtime.client.impl.PubClientImpl)1 Test (org.junit.Test)1