A map of topics to endpoints
A map of topics to subscribers.
This creates or uses an endpoint for a topic and returns it.
let endpoint = publisher.connect('*', async (msg: EndpointMessage): Promise<number> => {
return await conn.send(msg) // assume `conn` has a matching endpoint on the other side.
})
Topic that this endpoint should receive.
An endpoint instance or handler.
The endpoint
This creates an endpoint for a topic.
let endpoint = publisher.connect('*')
endpoint.outbound = async (msg: EndpointMessage): Promise<number> => {
return await conn.send(msg)
}
A new endpoint with a default handler.
This disconnects an endpoint from a topic.
publisher.disconnect('topic.*', endpoint)
The topic to disconnect from.
The endpoint
This disconnects an endpoint from all topics.
publisher.disconnect(endpoint)
Returns all endpoints for a given topic.
Returns all subscribers of a given topic, using minimatch.
Checks if the subscriber is subscribed to a particular topic.
For example, if a subscriber has been subscribed to topic.*
and topic.golang
is checked for, then this will return true.
The subscriber to check
The topic to check for
Whether or not the subscriber is subscribed to the topic
Sends a message to all subscribers and endpoints of a Topic
.
publisher.publish('topic.*', 'this is a message to subscribers of all topics')
publisher.publish('topic.golang', 'this is a message to subscribers of topic.golang (and topic.* subscribers!)')
The number of subscribers who received the message.
Publishes a message to all subscribers and endpoints on behalf of a subscriber. The topic must be one the subscriber is subscribed to. The received publish message will contain fromSubscriber
.
publisher.publish(subscriber, 'topic.golang', 'Greetings from a subscriber')
The subscriber to send on behalf of.
A topic the subscriber is subscribed to.
The message.
Sends a message to all subscribers and endpoints, excluding the provided endpoint.
publisher.publish(endpoint, message)
The endpoint to send on behalf of.
An EndpointMessage for forwarding. The endpoint will never see this message.
Subscribes a handler to a topic and returns a new, corresponding Subscriber.
publisher.subscribe('topic.golang', async ({topic, message}) => {
console.log('handled', topic, message)
})
A new subscriber containing the handler.
Subscribes a subscriber to a given topic.
let subscriber = publisher.subscribe('topic.golang')
publisher.subscribe('topic.unix', subscriber)
The subscriber passed in.
Creates a subscriber without a handler.
let subscriber = publisher.subscribe('topic.golang')
subscriber.handler = async ({topic, message}) => {
console.log(message)
}
Unsubscribes a subscriber from a specific Topic
pattern.
publisher.unsubscribe('topic.golang', subscriber) // unsubscribes from a single topic.
publisher.unsubscribe('topic.deno', handler)
The number of subscriptions unsubscribed.
Unsubscribes a subscriber from all topics it is subscribed to.
publisher.unsubscribe(subscriber) // unsubscribes a subsciber from all topics.
The number of subscriptions unsubscribed.
Generated using TypeDoc
Publisher provides a class for creating new publisher/subscriber relations.