EventMesh Runtime Protocol

TCP Protocol

Protocol Format

NameSizeDescription
Magic Code9 bytesDefault: EventMesh
Protocol Version4 bytesDefault: 0000
Message Size4 bytesThe total length of the message
Header Size4 bytesThe length of the message header
Message BodyThe content of the message

Message Object in the Business Logic Layer

Message Composition

The Package class in the Package.java file is the TCP message object used in business logic layer. The class contains the header and body fields.

  1. public class Package {
  2. private Header header;
  3. private Object body;
  4. }
  5. public class Header {
  6. private Command cmd;
  7. private int code;
  8. private String msg;
  9. private String seq;
  10. }

Specification

  • Message Header (the header field): The cmd field in the Header class specifies the different types of messages.
  • Message Body (the body field): The type of the message body should be defined based on cmd field in the Header class.
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_ACKN/A
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

Example of Client-Server Interaction

  1. public enum Command {
  2. // Heartbeat
  3. HEARTBEAT_REQUEST(0), // Client send heartbeat request to server
  4. HEARTBEAT_RESPONSE(1), // Server reply heartbeat response to client
  5. // Hello
  6. HELLO_REQUEST(2), // Client send connect request to server
  7. HELLO_RESPONSE(3), // Server reply connect response to client
  8. // Disconncet
  9. CLIENT_GOODBYE_REQUEST(4), // Client send disconnect request to server
  10. CLIENT_GOODBYE_RESPONSE(5), // Server reply disconnect response to client
  11. SERVER_GOODBYE_REQUEST(6), // Server send disconncet request to client
  12. SERVER_GOODBYE_RESPONSE(7), // Client reply disconnect response to server
  13. // Subscribe and UnSubscribe
  14. SUBSCRIBE_REQUEST(8), // Slient send subscribe request to server
  15. SUBSCRIBE_RESPONSE(9), // Server reply subscribe response to client
  16. UNSUBSCRIBE_REQUEST(10), // Client send unsubscribe request to server
  17. UNSUBSCRIBE_RESPONSE(11), // Server reply unsubscribe response to client
  18. // Listen
  19. LISTEN_REQUEST(12), // Client send listen request to server
  20. LISTEN_RESPONSE(13), // Server reply listen response to client
  21. // Send sync message
  22. REQUEST_TO_SERVER(14), // Client (Producer) send sync message to server
  23. REQUEST_TO_CLIENT(15), // Server push sync message to client(Consumer)
  24. REQUEST_TO_CLIENT_ACK(16), // Client (Consumer) send ack of sync message to server
  25. RESPONSE_TO_SERVER(17), // Client (Consumer) send reply message to server
  26. RESPONSE_TO_CLIENT(18), // Server push reply message to client(Producer)
  27. RESPONSE_TO_CLIENT_ACK(19), // Client (Producer) send acknowledgement of reply message to server
  28. // Send async message
  29. ASYNC_MESSAGE_TO_SERVER(20), // Client send async msg to server
  30. ASYNC_MESSAGE_TO_SERVER_ACK(21), // Server reply ack of async msg to client
  31. ASYNC_MESSAGE_TO_CLIENT(22), // Server push async msg to client
  32. ASYNC_MESSAGE_TO_CLIENT_ACK(23), // Client reply ack of async msg to server
  33. // Send broadcast message
  34. BROADCAST_MESSAGE_TO_SERVER(24), // Client send broadcast msg to server
  35. BROADCAST_MESSAGE_TO_SERVER_ACK(25), // Server reply ack of broadcast msg to client
  36. BROADCAST_MESSAGE_TO_CLIENT(26), // Server push broadcast msg to client
  37. BROADCAST_MESSAGE_TO_CLIENT_ACK(27), // Client reply ack of broadcast msg to server
  38. // Redirect
  39. REDIRECT_TO_CLIENT(30), // Server send redirect instruction to client
  40. }

Client-Initiated Interaction

SceneClient RequestServer Response
HelloHELLO_REQUESTHELLO_RESPONSE
HeartbeatHEARTBEAT_REQUESTHEARTBEAT_RESPONSE
SubscribeSUBSCRIBE_REQUESTSUBSCRIBE_RESPONSE
UnsubscribeUNSUBSCRIBE_REQUESTUNSUBSCRIBE_RESPONSE
ListenLISTEN_REQUESTLISTEN_RESPONSE
Send sync messageREQUEST_TO_SERVERRESPONSE_TO_CLIENT
Send the response of sync messageRESPONSE_TO_SERVERN/A
Send async messageASYNC_MESSAGE_TO_SERVERASYNC_MESSAGE_TO_SERVER_ACK
Send broadcast messageBROADCAST_MESSAGE_TO_SERVERBROADCAST_MESSAGE_TO_SERVER_ACK
Client start to disconnectCLIENT_GOODBYE_REQUESTCLIENT_GOODBYE_RESPONSE

Server-Initiated Interaction

SceneServer RequestClient ResponseRemark
Push sync message to clientREQUEST_TO_CLIENTREQUEST_TO_CLIENT_ACK
Push the response message of sync message to clientRESPONSE_TO_CLIENTRESPONSE_TO_CLIENT_ACK
Push async message to clientASYNC_MESSAGE_TO_CLIENTASYNC_MESSAGE_TO_CLIENT_ACK
Push broadcast message to clientBROADCAST_MESSAGE_TO_CLIENTBROADCAST_MESSAGE_TO_CLIENT_ACK
Server start to disconnectSERVER_GOODBYE_REQUEST
Server send redirectREDIRECT_TO_CLIENT

Type of Message

Sync Message

Sync Message

Async Message

Async Message

Boardcast Message

Boardcast Message

HTTP Protocol

Protocol Format

The EventMeshMessage class in the EventMeshMessage.java file is the HTTP message definition of EventMesh Runtime.

  1. public class EventMeshMessage {
  2. private String bizSeqNo;
  3. private String uniqueId;
  4. private String topic;
  5. private String content;
  6. private Map<String, String> prop;
  7. private final long createTime = System.currentTimeMillis();
  8. }

HTTP Post Request

Heartbeat Message

Request Header
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
Request Body
KeyDescription
clientTypeClientType.PUB for Producer, ClientType.SUB for Consumer
heartbeatEntitiesTopic, URL, etc.

Subscribe Message

Request Header

The request header of the Subscribe message is identical to the request header of the Heartbeat message.

Request Body
KeyDescription
topicThe topic that the client requested to subscribe to
urlThe callback URL of the client

Unsubscribe Message

Request Header

The request header of the Unsubscribe message is identical to the request header of the Heartbeat message.

Request Body

The request body of the Unsubscribe message is identical to the request body of the Subscribe message.

Send Async Message

Request Header

The request header of the Send Async message is identical to the request header of the Heartbeat message.

Request Body
KeyDescription
topicTopic of the message
contentThe content of the message
ttlThe time-to-live of the message
bizSeqNoThe biz sequence number of the message
uniqueIdThe unique ID of the message

Client-Initiated Interaction

SceneClient RequestServer ResponseRemark
HeartbeatHEARTBEAT(203)SUCCESS(0) or EVENTMESH_HEARTBEAT_ERROR(19)
SubscribeSUBSCRIBE(206)SUCCESS(0) or EVENTMESH_SUBSCRIBE_ERROR(17)
UnsubscribeUNSUBSCRIBE(207)SUCCESS(0) or EVENTMESH_UNSUBSCRIBE_ERROR(18)
Send async messageMSG_SEND_ASYNC(104)SUCCESS(0) or EVENTMESH_SEND_ASYNC_MSG_ERR(14)

Server-Initiated Interaction

SceneClient RequestServer ResponseRemark
Push async message to the clientHTTP_PUSH_CLIENT_ASYNC(105)retCodeThe push is successful if the retCode is 0

gRPC Protocol

Protobuf

The eventmesh-protocol-gprc module contains the protobuf definition file of the Eventmesh client. The gradle build command generates the gRPC codes, which are located in /build/generated/source/proto/main. The generated gRPC codes are used in eventmesh-sdk-java module.

Data Model

Message

The message data model used by publish(), requestReply() and broadcast() APIs is defined as:

  1. message RequestHeader {
  2. string env = 1;
  3. string region = 2;
  4. string idc = 3;
  5. string ip = 4;
  6. string pid = 5;
  7. string sys = 6;
  8. string username = 7;
  9. string password = 8;
  10. string language = 9;
  11. string protocolType = 10;
  12. string protocolVersion = 11;
  13. string protocolDesc = 12;
  14. }
  15. message SimpleMessage {
  16. RequestHeader header = 1;
  17. string producerGroup = 2;
  18. string topic = 3;
  19. string content = 4;
  20. string ttl = 5;
  21. string uniqueId = 6;
  22. string seqNum = 7;
  23. string tag = 8;
  24. map<string, string> properties = 9;
  25. }
  26. message BatchMessage {
  27. RequestHeader header = 1;
  28. string producerGroup = 2;
  29. string topic = 3;
  30. message MessageItem {
  31. string content = 1;
  32. string ttl = 2;
  33. string uniqueId = 3;
  34. string seqNum = 4;
  35. string tag = 5;
  36. map<string, string> properties = 6;
  37. }
  38. repeated MessageItem messageItem = 4;
  39. }
  40. message Response {
  41. string respCode = 1;
  42. string respMsg = 2;
  43. string respTime = 3;
  44. }

Subscription

The subscription data model used by subscribe() and unsubscribe() APIs is defined as:

  1. message Subscription {
  2. RequestHeader header = 1;
  3. string consumerGroup = 2;
  4. message SubscriptionItem {
  5. enum SubscriptionMode {
  6. CLUSTERING = 0;
  7. BROADCASTING = 1;
  8. }
  9. enum SubscriptionType {
  10. ASYNC = 0;
  11. SYNC = 1;
  12. }
  13. string topic = 1;
  14. SubscriptionMode mode = 2;
  15. SubscriptionType type = 3;
  16. }
  17. repeated SubscriptionItem subscriptionItems = 3;
  18. string url = 4;
  19. }

Heartbeat

The heartbeat data model used by the heartbeat() API is defined as:

  1. message Heartbeat {
  2. enum ClientType {
  3. PUB = 0;
  4. SUB = 1;
  5. }
  6. RequestHeader header = 1;
  7. ClientType clientType = 2;
  8. string producerGroup = 3;
  9. string consumerGroup = 4;
  10. message HeartbeatItem {
  11. string topic = 1;
  12. string url = 2;
  13. }
  14. repeated HeartbeatItem heartbeatItems = 5;
  15. }

Service Definition

Event Publisher Service

  1. service PublisherService {
  2. // Async event publish
  3. rpc publish(SimpleMessage) returns (Response);
  4. // Sync event publish
  5. rpc requestReply(SimpleMessage) returns (Response);
  6. // Batch event publish
  7. rpc batchPublish(BatchMessage) returns (Response);
  8. }

Event Consumer Service

  1. service ConsumerService {
  2. // The subscribed event will be delivered by invoking the webhook url in the Subscription
  3. rpc subscribe(Subscription) returns (Response);
  4. // The subscribed event will be delivered through stream of Message
  5. rpc subscribeStream(Subscription) returns (stream SimpleMessage);
  6. rpc unsubscribe(Subscription) returns (Response);
  7. }

Client Hearthbeat Service

  1. service HeartbeatService {
  2. rpc heartbeat(Heartbeat) returns (Response);
  3. }