TCP Protocol Document In Eventmesh-Runtime

1. Protocol Format

dataFlow

Protocol Specification

Magic Code: 9 bit, defaultValue:EventMesh

Protocol Version: 4 bit, defaultValue:0000

Message Size: 4 bit, the total length of message

Header Size: 4 bit,the length of Message Header

Message Header: the specific header content of message 

Message Body: the specific body content of message 

2. Message Object in business logic layer

  • Message Composition

The class of Package.java is message object in business logic layer. It contains two parts: header and body.

public class Package {

    private Header header;
    private Object body;
}


public class Header {

    private Command cmd;
    private int code;
    private String msg;
    private String seq;
}
  • Specificatiion

Message Header(header): The field of Command in Header, used to distinguishing different message types.

Message Body(body): The message body is defined as different objects according to the message type.

Commandtype of Body
HEARTBEAT_REQUEST, HEARTBEAT_RESPONSE, HELLO_RESPONSE, CLIENT_GOODBYE_REQUEST, CLIENT_GOODBYE_RESPONSE, SERVER_GOODBYE_REQUEST, SERVER_GOODBYE_RESPONSE, LISTEN_REQUEST, LISTEN_RESPONSE, UNSUBSCRIBE_REQUEST, SUBSCRIBE_RESPONSE, UNSUBSCRIBE_RESPONSE, ASYNC_MESSAGE_TO_SERVER_ACK, BROADCAST_MESSAGE_TO_SERVER_ACK--
HELLO_REQUESTUserAgent
SUBSCRIBE_REQUESTSubscription
REQUEST_TO_SERVER, REQUEST_TO_CLIENT, RESPONSE_TO_SERVER, RESPONSE_TO_CLIENT, ASYNC_MESSAGE_TO_SERVER, ASYNC_MESSAGE_TO_CLIENT, BROADCAST_MESSAGE_TO_SERVER, BROADCAST_MESSAGE_TO_CLIENT, ASYNC_MESSAGE_TO_CLIENT_ACK, BROADCAST_MESSAGE_TO_CLIENT_ACK, RESPONSE_TO_CLIENT_ACK, REQUEST_TO_CLIENT_ACKOpenMessage
REDIRECT_TO_CLIENTRedirectInfo

3. The Interactive Command between Client and Server(Eventmesh-Runtime)

public enum Command {

    //HeartBeat
    HEARTBEAT_REQUEST(0),                              //client send heartbeat request to server
    HEARTBEAT_RESPONSE(1),                             //server reply heartbeat response to client

    //Hello
    HELLO_REQUEST(2),                                  //client send connect request to server
    HELLO_RESPONSE(3),                                 //server reply connect response to client

    //Disconncet
    CLIENT_GOODBYE_REQUEST(4),                         //client send disconnect request to server
    CLIENT_GOODBYE_RESPONSE(5),                        //server reply disconnect response to client
    SERVER_GOODBYE_REQUEST(6),                         //server send disconncet request to client
    SERVER_GOODBYE_RESPONSE(7),                        //client reply disconnect response to server

    //Subscribe and UnSubscribe
    SUBSCRIBE_REQUEST(8),                              //client send subscribe request to server
    SUBSCRIBE_RESPONSE(9),                             //server reply subscribe response to client
    UNSUBSCRIBE_REQUEST(10),                           //client send unsubscribe request to server
    UNSUBSCRIBE_RESPONSE(11),                          //server reply unsubscribe response to client

    //Listen
    LISTEN_REQUEST(12),                            	   //client send listen request to server
    LISTEN_RESPONSE(13),                               //server reply listen response to client

    //send sync message
    REQUEST_TO_SERVER(14),                             //client(Producer) send sync msg to server
    REQUEST_TO_CLIENT(15),                             //server push sync msg to client(Consumer)
    REQUEST_TO_CLIENT_ACK(16),                         //client(Consumer) send ack of sync msg to server
    RESPONSE_TO_SERVER(17),                            //client(Consumer) send reply msg to server
    RESPONSE_TO_CLIENT(18),                            //server push reply msg to client(Producer)
    RESPONSE_TO_CLIENT_ACK(19),                        //client(Producer) send ack of reply msg to server

    //send async message
    ASYNC_MESSAGE_TO_SERVER(20),                       //client send async msg to server
    ASYNC_MESSAGE_TO_SERVER_ACK(21),                   //server reply ack of async msg to client
    ASYNC_MESSAGE_TO_CLIENT(22),                       //server push async msg to client
    ASYNC_MESSAGE_TO_CLIENT_ACK(23),                   //client reply ack of async msg to server

    //send broadcast message
    BROADCAST_MESSAGE_TO_SERVER(24),                   //client send broadcast msg to server
    BROADCAST_MESSAGE_TO_SERVER_ACK(25),               //server reply ack of broadcast msg to client
    BROADCAST_MESSAGE_TO_CLIENT(26),                   //server push broadcast msg to client
    BROADCAST_MESSAGE_TO_CLIENT_ACK(27),               //client reply ack of broadcast msg to server

    //redirect
    REDIRECT_TO_CLIENT(30),                            //server send redirect instruction to client
}

4. Client initiates interaction

SceneClient SendServer ReplyRemark
HelloHELLO_REQUESTHELLO_RESPONSE
HeartbeatHEARTBEAT_REQUESTHEARTBEAT_RESPONSE
SubscribeSUBSCRIBE_REQUESTSUBSCRIBE_RESPONSE
UnsubscribeUNSUBSCRIBE_REQUESTUNSUBSCRIBE_RESPONSE
ListenLISTEN_REQUESTLISTEN_RESPONSE
Send sync msgREQUEST_TO_SERVERRESPONSE_TO_CLIENT
Send reply msg of sync msgRESPONSE_TO_SERVER--
Send async msgASYNC_MESSAGE_TO_SERVERASYNC_MESSAGE_TO_SERVER_ACK
Send broadcast msgBROADCAST_MESSAGE_TO_SERVERBROADCAST_MESSAGE_TO_SERVER_ACK
Client start disconnectCLIENT_GOODBYE_REQUESTCLIENT_GOODBYE_RESPONSE

5. Server initiates interaction

SceneServer SendClient ReplyRemark
Push sync msg to clientREQUEST_TO_CLIENTREQUEST_TO_CLIENT_ACK
Push reply msg of sync msg to clientRESPONSE_TO_CLIENTRESPONSE_TO_CLIENT_ACK
Push async msg to clientASYNC_MESSAGE_TO_CLIENTASYNC_MESSAGE_TO_CLIENT_ACK
Push broadcast msg to clientBROADCAST_MESSAGE_TO_CLIENTBROADCAST_MESSAGE_TO_CLIENT_ACK
Server start disconnectSERVER_GOODBYE_REQUEST--
Server send redirectREDIRECT_TO_CLIENT--

6. Message classification

  • Send sync msg

rr-msg

  • Send async msg

async-msg

  • Send broadcast msg

broadcast-msg

HTTP Protocol Document In Eventmesh-Runtime

The class of LiteMessage.java is message definition in http protocal of EventMesh-Runtime.If you want to send msg by using http protocol,you can use client in eventmesh-sdk-java, and you just need care the specific protocol in the field of content.

public class LiteMessage {

    private String bizSeqNo;

    private String uniqueId;

    private String topic;

    private String content;

    private Map<String, String> prop;

    private long createTime = System.currentTimeMillis();
}

1. Message Send and Message Composition

Request Method: POST

Message Composition: RequestHeader + RequestBody

  • Heartbeat Msg

RequestHeader

KeyDescription
EnvEnviroment of Client
RegionRegion of Client
IdcIDC of Client
DcnDCN of Client
SysSubsystem ID of Client
PidClient Process ID
IpClient Ip
UsernameClient username
PasswdClient password
VersionProtocol version
LanguageDevelop language
CodeRequest Code

RequestBody

KeyDescription
clientTypeProducer:clientType is ClientType.PUB,Consumer:clientType is ClientType.SUB
heartbeatEntitiesHeartbeat content,contains topic,url...
  • Subscribe Msg

RequestHeader

same with RequestHeader of heartbeat msg

RequestBody

KeyDescription
topictopic of client want to subscribe
urlurl of client, server push msg to the url when receiving msg from other components
  • Unsubscribe Msg

RequestHeader

same with RequestHeader of Heartbeat Msg

RequestBody

same with RequestBody of Subscribe Msg

  • Send async msg

RequestHeader

same with RequestHeader of Heartbeat Msg

RequestBody

KeyDescription
topictopic of msg
contentmsg content
ttltimeout time of msg
bizSeqNobiz sequence number of msg
uniqueIdunique mark of msg

2. Client initiates interaction

SceneClient SendServer ReplyRemark
HeartbeatHEARTBEAT(203)SUCCESS(0)/EVENTMESH_HEARTBEAT_ERROR(19)
SubscribeSUBSCRIBE(206)SUCCESS(0)/EVENTMESH_SUBSCRIBE_ERROR(17)
UnsubscribeUNSUBSCRIBE(207)SUCCESS(0)/EVENTMESH_UNSUBSCRIBE_ERROR(18)
Send async msgMSG_SEND_ASYNC(104)SUCCESS(0)/EVENTMESH_SEND_ASYNC_MSG_ERR(14)

3. Server initiates interaction

SceneServer SendClient ReplyRemark
Push async msg to clientHTTP_PUSH_CLIENT_ASYNC(105)retCoderetCode=0,send success