Retrieving the Latest Message

To retrieve only the latest message, use the "offsetType" parameter and specify the value as "highest." For example:

{
   "id": "1",
   "type": "subscribe",
   "payload": {
         "variables": {},
         "extensions": {},
         "operationName": null,
               "query": "subscription { newEvent(input: { chainCode: \"<CHAIN CODE>\" offsetType: \"highest\" } ) { metadata { offset } moduleName eventName detail { oldValue newValue elementName } } }"
   }
}

Streaming Scenario

Imagine the following scenario: A stream has produced 10 events over the previous 24 hours. A consumer has connected and consumed events 0 to 6 inclusive, and then disconnected again.

While the consumer is disconnected, events 7 to 10 occur.

If the consumer connects again without specifying an offset, then events 7 to 10 are sent to the caller followed by subsequent events.

If the consumer connects again and specifies an offset of 3, then events 3 to 10 are sent to the caller followed by subsequent events.

If the consumer connects with the offsetType highest, then only event 10 is sent, followed by subsequent events.


This figure shows earliest to the latest events in an event stream.

Therefore, only use the offsetType highest if you have no interest in historic events because you will no longer receive them. Similarly, you can never maintain the sequence of events if you use offsetType highest.

A good use case for offsetType highest is when a resource is changing rapidly, and you are only interested in the last state of the resource.

Note:

Do not use offsetType highest if you must synchronize an external system with OPERA Cloud as it would get (and remain) out of sync.