function createMessagingHandler
Since 0.2.0
createMessagingHandler(
app: IApplication,
): MessagingHandler

Builds the handler an application exports as queue to consume messages.

The broker is resolved from the application's registry rather than passed in, so the subscriptions registered through IMessageBroker.subscribe anywhere in the application are the ones this handler delivers into — there is only ever one instance.

Resolution is lazy: the token is read on each invocation, not when this factory runs, so the export can be built before app.start() has registered anything.

Examples

Example 1

export default { fetch: app.fetch, queue: createMessagingHandler(app) };

Parameters

app: IApplication

The application whose registry carries the broker

optional
options: MessagingHandlerOptions

Which named broker instance to dispatch into

Return Type

The handler to assign to the Worker's queue export

Throws

CloudflareUnsupportedError

At invocation time, when the resolved token holds an IMessageBroker that is not a WorkersBroker — an in-memory or Redis broker has no batch to dispatch and would silently drop the delivery

Usage

import { createMessagingHandler } from "cloudflare-plugin/src/index.ts";