Connectum API Reference / @connectum/events / types / EventContext
Interface: EventContext ​
Defined in: packages/events/src/types.ts:169
Per-event context with explicit ack/nack control.
Passed to event handlers alongside the deserialized message. Supports explicit ack/nack control. If the handler completes without calling either, the event is automatically acknowledged.
Properties ​
attempt ​
readonlyattempt:number
Defined in: packages/events/src/types.ts:179
Delivery attempt number (1-based)
eventId ​
readonlyeventId:string
Defined in: packages/events/src/types.ts:173
Unique event identifier
eventType ​
readonlyeventType:string
Defined in: packages/events/src/types.ts:175
Event type / topic name
metadata ​
readonlymetadata:ReadonlyMap<string,string>
Defined in: packages/events/src/types.ts:181
Event metadata (headers)
publishedAt ​
readonlypublishedAt:Date
Defined in: packages/events/src/types.ts:177
When the event was published
signal ​
readonlysignal:AbortSignal
Defined in: packages/events/src/types.ts:171
Abort signal (aborted when server is shutting down)
Methods ​
ack() ​
ack():
Promise<void>
Defined in: packages/events/src/types.ts:183
Acknowledge successful processing
Returns ​
Promise<void>
nack() ​
nack(
requeue?):Promise<void>
Defined in: packages/events/src/types.ts:185
Negative acknowledge -- request redelivery or send to DLQ
Parameters ​
requeue? ​
boolean
Returns ​
Promise<void>
publish() ​
publish<
Desc>(schema,data,options?):Promise<void>
Defined in: packages/events/src/types.ts:204
Publish an event on behalf of this delivery: the way a relay handler (consume, transform, publish) hands its result on.
While the bus is stopping, bus.publish is refused, but this call is still admitted as long as the handler of this delivery has not returned and the drain has not been aborted, and stop() waits for it before the adapter is disconnected. The right belongs to this one delivery, this bus and this start/stop cycle: it ends when the handler's promise settles, when the drain is aborted, and when the bus stops; a call after that is rejected. Await the result inside the handler, so a failed publish fails the handler and the message is retried.
Handlers that publish through an injected bus instead of ctx keep being refused during stop(); rewrite them to use ctx.publish to relay during shutdown.
data is MessageInitShape of the schema: a plain object (nested messages and oneofs included) or an already built message, which is the same thing the runtime builds with create(schema, data) before serializing.
Type Parameters ​
Desc ​
Desc extends DescMessage
Parameters ​
schema ​
Desc
data ​
MessageInitShape<Desc>
options? ​
Returns ​
Promise<void>