subscribe(consumerName: string, handler: (payload: Payload[]) => Promise<boolean>, pollSpan?: number, payloadsToFetch?: number, subscriptionHandle?: string, readPending?: boolean): Promise<string>
Subscribes to stream to start receiving events when new payload arrives, this internally creates a polling system to check for new messages in stream. returns subscription name.
consumerName: Name of the consumer who is subscribing via the consumer group object.
handler: A callback function which will be invoked when new message a.k.a payload(s) arrive. Should be of signature (payload: Payload[]) => Promise<boolean>
should be async return from this function is ignored for now, look at Payload
class below for more details.
pollSpan: Number of millisecond to wait after completion of handler to check for next available message in stream. Defaulted to 1000 milliseconds.
payloadsToFetch: Maximum number of messages to fetch in one poll to server this is simillar to COUNT
command in redis, this is optional and defaulted to 2.
subscriptionHandle: Name for subscription handler this is what will be returned from the function, this is defaulted to unique shortid.
readPending: If set to true
will read all messages from start of the stream ie: Id = 0 which are in pending list of this consumer and group, once all pending are read it will automatically switch to latest messages from the stream. If set to false
it will always look for new message from the stream, this is defaulted to false
.