@qified/zeromq

ZeroMQ message provider for Qified.

This package implements a message provider backed by ZeroMQ using queues for publish and subscribe operations.

Table of Contents

Installation

pnpm add @qified/zeromq
    

Usage with Qified

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();
    

API

ZmqMessageProviderOptions

Configuration options for the ZeroMQ message provider.

defaultZmqUri

Default ZeroMQ connection string ("tcp://localhost:5555").

ZmqMessageProvider

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.

createQified(options?: ZmqMessageProviderOptions)

Convenience factory that returns a Qified instance configured with ZmqMessageProvider.

Contributing

Contributions are welcome! Please read the CONTRIBUTING.md and CODE_OF_CONDUCT.md for details on our process.

License

MIT © Jared Wray. See LICENSE for details.