Skip to main content

Consuming Events from a Subscription

GET /subscriptions/{subscription-id}/events

Request

Events can be consumed by sending a GET request to the subscription's event resource /subscriptions/{subscription-id}/events.

note

The consumption of events is handled by your client application. If your client application is not able to process the format of the streaming notification, you may encounter a validation error.

For an example of how to handle a message with a validation error, see the consumeEvents class in the Streaming-API-Java-Sample-Client GitHub repository.

Sample Request

curl -v -X GET "https://TENANT_NAME.localhost:8889/api/v1/subscriptions/0691160a-b519-4595-b85c-a400fc73e963/events"

Response

The response is a stream that groups events into JSON batches separated by an endline (\n) character. The output can be seen in the right panel.

Each batch contains the following fields:

  • cursor: The cursor of the batch which should be used for committing the batch.
  • events: The array of events of this batch.
  • info: An optional field that can hold useful information (e.g. the reason why the stream was closed by Mambu).
note

When a stream is started, the client receives a header named X-Mambu-StreamId, which must be used when committing cursors. See Committing Cursors for more information.

Sample Response

HTTP/1.1 200 OK
X-Mambu-StreamId: 93ae5174-b863-4f8f-ba33-d274854d1f3d
Transfer-Encoding: chunked

{ "cursor" : { "partition": "1", "offset": "001-0001--1", "event_type": "mrn.event.demo_tenant.streamingapi.client_approved", "cursor_token": "1d23d044-daa1-414c-8ec4-a060ba03d77c" }, "info": { "debug": "Stream started" }}
{ "cursor" : { "partition": "1", "offset": "001-0001-000000000000000000", "event_type": "mrn.event.demo_tenant.streamingapi.client_approved", "cursor_token": "e8f6bc5d-65b7-4466-9d95-507da0e79d3c" }, "events": [ { "metadata": { "occurred_at": "2018-11-18T22:50:12.602Z", "eid": "fde622d5-f975-4786-8e1d-d328c29761f9", "event_type": "mrn.event.demo_tenant.streamingapi.client_approved", "partition": "1", "received_at": "2018-11-18T22:50:12.786Z", "flow_id": "jOK94UJFdtKsthWOgOJCwuGC", "version": "1.0.0" }, "occurred_at": "2018-11-18T22:50:12.602Z", "body": "Client was approved notification body", "content_type": "text/plain; charset=UTF-8", "template_name": "Demo Template 1", "category": "DATA" } ]}
{ "cursor" : { "partition": "1", "offset": "001-0001-000000000000000000", "event_type": "mrn.event.demo_tenant.streamingapi.client_approved", "cursor_token": "5fed7de4-86ec-464f-92f0-5d6103869385" }}