-
Notifications
You must be signed in to change notification settings - Fork 2
Project 1 Events format
We follow the standard cloud events spec for all communications between microservices. The spec can be found at Cloud Events JSON.
Following is a basic structure of events:
{
"specversion" : "1.0",
"type" : "com.example.someevent",
"source" : "/mycontext",
"subject": null,
"id" : "C234-1234-1234",
"time" : "2018-04-05T17:31:00Z",
"comexampleextension1" : "value",
"comexampleothervalue" : 5,
"datacontenttype" : "application/json",
"data" : {
"appinfoA" : "abc",
"appinfoB" : 123,
"appinfoC" : true
}
}
In the above sample event, the data field contains the actual payload consumed/produced by the microservice. The remaining fields act as metadata that provides information about the event type, origin, time, etc.
In an HTTP request, the "metadata" is sent as part of request/response headers while the "data" field is sent as the request/response body.
In the case of MQ communication, the entire JSON structure is sent as a message body.
Each microservice will have its own message type. However, they all derive from a common message type - elves.forecast
Following is the general format for message type:
elves.forecast..
Following are a list of microservices, their ids, and events:
- registry:
microservice-id: registry event ids: registerUserRequest, listUserRequest, userActionsRequest, logUserActionRequest registerUserResponse, listUserResponse, userActionsResponse, logUserActionResponse
- data ingestor:
microservice-id: ingestor event ids: fileRequest, fileResponse
An example event/message type can be from API Gateway to Registry requesting a list of all user activities for a given user. Represented by event: elves.forecast.registry.userActionsRequest The event might be framed as below:
{
"specversion" : "1.0",
"type" : "elves.forecast.registry.userActionsRequest",
"source" : "APIGateway",
"id" : "993abe4a-7ce0-11ec-90d6-0242ac120003",
"time" : "2018-04-05T17:31:00Z",
"datacontenttype" : "application/json",
"data" : {
"userId" : "madhkr",
"startTime" : 156247389,
"endTime" : 157247389
}
}
{
"specversion" : "1.0",
"type" : "com.example.someevent",
"source" : "/mycontext",
"subject": "sample",
"id" : "C234-1234-1234",
"time" : "2018-04-05T17:31:00Z",
"datacontenttype" : "application/json",
"data" : {
"userId" : "Madhavan",
"serviceId" : "ingestor",
"action" : "getdata",
"timestamp": "1646199394",
"comments": "successfully fetched",
"status": 0
}
}
- https://github.com/cloudevents/spec/blob/v1.0.1/json-format.md
- https://github.com/cloudevents/sdk-python/tree/705e8b41004dba4f9a2dda0993205f9d610c7161
- https://github.com/cloudevents/sdk-java
- https://github.com/cloudevents/sdk-go