ZeroMQ message provider for qified
npm install @qified/zeromqZeroMQ message provider for Qified.
This package implements a message provider backed by ZeroMQ using queues for publish and subscribe operations.
- Installation
- Usage with Qified
- API
- ZmqMessageProviderOptions
- defaultZmqUri
- ZmqMessageProvider
- constructor
- publish
- subscribe
- unsubscribe
- disconnect
- createQified
- Contributing
- License
``bash`
pnpm add @qified/zeromq
`ts
import { createQified } from "@qified/zeromq";
import type { Message } from "qified";
const qified = createQified({ uri: "tcp://localhost:5555" });
await qified.subscribe("example-topic", {
async handler(message: Message) {
console.log(message);
},
});
await qified.publish("example-topic", { id: "1", data: "Hello from ZeroMQ!" });
await qified.disconnect();
`
Configuration options for the ZeroMQ message provider.
- uri?: ZeroMQ connection URI. Defaults to defaultZmqUri.
Default ZeroMQ connection string ("tcp://localhost:5555").
Implements the MessageProvider interface using ZeroMQ queues.
#### constructor(options?: ZmqMessageProviderOptions)
Creates a new provider.
Options:
- uri: ZeroMQ connection URI (defaults to "tcp://localhost:5555").
#### publish(topic: string, message: Message)
Publishes a message to a topic.
#### subscribe(topic: string, handler: TopicHandler)
Subscribes a handler to a topic.
#### unsubscribe(topic: string, id?: string)
Unsubscribes a handler by id or all handlers for a topic.
#### disconnect()
Cancels all subscriptions and closes the underlying ZeroMQ Publisher/Subscriber.
Convenience factory that returns a Qified instance configured with ZmqMessageProvider`.
Contributions are welcome! Please read the CONTRIBUTING.md and CODE_OF_CONDUCT.md for details on our process.
MIT © Jared Wray. See LICENSE for details.