Skip to main content

PubSub

@klotho::pubsub

Specified on a Node.js event emitter to enable asynchronous message passing between more publisher and subscriber execution units in the cloud.

Directives

DirectiveTypeDescription
idstring(Required) The identifier of the underlying PubSub resource that this pubsub declaration is bound to.

Supported operations

OperationNotes
onFully supported
emitFully supported
caution

Attempting to invoke any unsupported methods or access properties on an EventEmitter annotated with @klotho::pubsub will fail at run-time in the Klotho-compiled version of your application.

Examples

Declaring a New PubSub Capability
const events = require("events");

/** @klotho::pubsub {
* id = "my-pubsub"
* }
*/
const pubsubEmitter = new events.EventEmitter();
Subscribing to an Event
pubsubEmitter.on("my-event", (e) => {
console.log(`handling my-event: ${JSON.stringify(e)}`);
});
Publishing an Event
pubsubEmitter.emit("my-event", myEvent);

Providers

Currently, only SNS is supported as the broker.

Directives

note

This capability does not currently have any provider-specific directives.