Skip to main content
Version: v1.1.1

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.

public class Package {
private Header header;
private Object body;
}

public class Header {
private Command cmd;
private int code;
private String msg;
private String seq;
}

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

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), // Slient 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 message to server
REQUEST_TO_CLIENT(15), // Server push sync message to client(Consumer)
REQUEST_TO_CLIENT_ACK(16), // Client (Consumer) send ack of sync message to server
RESPONSE_TO_SERVER(17), // Client (Consumer) send reply message to server
RESPONSE_TO_CLIENT(18), // Server push reply message to client(Producer)
RESPONSE_TO_CLIENT_ACK(19), // Client (Producer) send acknowledgement of reply message 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
}

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.

public class EventMeshMessage {
private String bizSeqNo;

private String uniqueId;

private String topic;

private String content;

private Map<String, String> prop;

private final long createTime = System.currentTimeMillis();
}

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:

message RequestHeader {
string env = 1;
string region = 2;
string idc = 3;
string ip = 4;
string pid = 5;
string sys = 6;
string username = 7;
string password = 8;
string language = 9;
string protocolType = 10;
string protocolVersion = 11;
string protocolDesc = 12;
}

message SimpleMessage {
RequestHeader header = 1;
string producerGroup = 2;
string topic = 3;
string content = 4;
string ttl = 5;
string uniqueId = 6;
string seqNum = 7;
string tag = 8;
map<string, string> properties = 9;
}

message BatchMessage {
RequestHeader header = 1;
string producerGroup = 2;
string topic = 3;

message MessageItem {
string content = 1;
string ttl = 2;
string uniqueId = 3;
string seqNum = 4;
string tag = 5;
map<string, string> properties = 6;
}

repeated MessageItem messageItem = 4;
}

message Response {
string respCode = 1;
string respMsg = 2;
string respTime = 3;
}

Subscription

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

message Subscription {
RequestHeader header = 1;
string consumerGroup = 2;

message SubscriptionItem {
enum SubscriptionMode {
CLUSTERING = 0;
BROADCASTING = 1;
}

enum SubscriptionType {
ASYNC = 0;
SYNC = 1;
}

string topic = 1;
SubscriptionMode mode = 2;
SubscriptionType type = 3;
}

repeated SubscriptionItem subscriptionItems = 3;
string url = 4;
}

Heartbeat

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

message Heartbeat {
enum ClientType {
PUB = 0;
SUB = 1;
}

RequestHeader header = 1;
ClientType clientType = 2;
string producerGroup = 3;
string consumerGroup = 4;

message HeartbeatItem {
string topic = 1;
string url = 2;
}

repeated HeartbeatItem heartbeatItems = 5;
}

Service Definition

Event Publisher Service

service PublisherService {
// Async event publish
rpc publish(SimpleMessage) returns (Response);

// Sync event publish
rpc requestReply(SimpleMessage) returns (Response);

// Batch event publish
rpc batchPublish(BatchMessage) returns (Response);
}

Event Consumer Service

service ConsumerService {
// The subscribed event will be delivered by invoking the webhook url in the Subscription
rpc subscribe(Subscription) returns (Response);

// The subscribed event will be delivered through stream of Message
rpc subscribeStream(Subscription) returns (stream SimpleMessage);

rpc unsubscribe(Subscription) returns (Response);
}

Client Hearthbeat Service

service HeartbeatService {
rpc heartbeat(Heartbeat) returns (Response);
}