Skip to content

Project 1 Events format

Madhavan K R edited this page Mar 2, 2022 · 4 revisions

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.

Event types

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


Sample Event

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
    }
}

Registry Microservice - Events

Add Application log request:

{
  "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
  }
}

References