Skip to main content

channels_zmq

Tests status

A channel layer implementation using ZeroMQ PUB-SUB topology.

Installation

Install package from PyPI:

pip install channels-zmq

Usage

Configure the layer in your Django settings file. You can choose one of the two implementations described below:

Embedded layer
CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels_zmq.core.EmbeddedZmqChannelLayer",
        "CONFIG": {
            "pub_socket_address": "<SOME SOCKET ADDRESS>",
            "capacity": 100,
            "expiry": 60,
        },
    },
}

The embedded layer binds a ZeroMQ PUB socket inside the process that calls send or group_send. Consumers will connect their SUB sockets to the same socket.

While this is a very lightweight implementation, it only allows a single process to call send and group_send with the same layer.

If you need to send data created through other processes, you should create a different layer or use the dedicated layer.

               +----------------+
               |PRODUCER PROCESS|
               |----------------|
               |   PUB SOCKET   |
               +----------------+
                  ^     ^    ^
                  |     |    |
      +-----------+     |    +----------+
      |                 |               |
+------------+   +------------+   +------------+
| SUB SOCKET |   | SUB SOCKET |   | SUB SOCKET |
|------------|   |------------|   |------------|
| CONSUMER 1 |   | CONSUMER 2 |   | CONSUMER 3 |
+------------+   +------------+   +------------+
Dedicated layer
CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels_zmq.core.DedicatedZmqChannelLayer",
        "CONFIG": {
            "pull_socket_address": "<DAEMON PULL SOCKET ADDRESS>",
            "pub_socket_address": "<DAEMON PUB SOCKET ADDRESS",
            "capacity": 100,
            "expiry": 60,
        },
    },
}

The dedicated layer connects a ZeroMQ PUSH socket to a the configured PULL socket location when you call send or group_send. Consumers will connect to the configured PUB socket location instead.

While this implementation allows multiple processes to send messages over the same layer, it requires you to implement a daemon process that will read messages on the PULL socket and send them through the PUB socket.

                  +--------------------------+
                  |      DAEMON PROCESS      |
                  |--------------------------|
                  | PUB SOCKET | PULL SOCKET |
                  +--------------------------+
                      ^   ^           ^   ^
                      |   |           |   |
      +---------------+   |           |   +----------------+
      |                   |           |                    |
+------------+   +------------+   +-------------+   +-------------+
| SUB SOCKET |   | SUB SOCKET |   | PUSH SOCKET |   | PUSH SOCKET |
|------------|   |------------|   |-------------|   |-------------|
| CONSUMER 1 |   | CONSUMER 2 |   | PRODUCER 1  |   | PRODUCER 2  |
+------------+   +------------+   +-------------+   +-------------+

Metadata

Release files for channels-zmq 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for channels-zmq 0.1.0
File Size Uploaded
channels-zmq-0.1.0.tar.gz 24.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for channels-zmq 0.1.0
File Interpreter ABI Platform
channels_zmq-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 42.0 kB

Release files / channels-zmq-0.1.0.tar.gz

Download URL channels-zmq-0.1.0.tar.gz
Size 24.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a1c770470830dc59c4df369f5915d81079c1c733dd092469ccb7170be631416b
BLAKE2b-256 checksum
How to use checksums
8cc81a5cecd6396caa0688a7c1ae0a2bc861cdfb59b33ac4cafa85141946f183
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / channels_zmq-0.1.0-py3-none-any.whl

Download URL channels_zmq-0.1.0-py3-none-any.whl
Size 17.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
173e60ee52e1e9cb77a706d82a88563b03f5be7e8f6c4f14e2089f2d97fb330d
BLAKE2b-256 checksum
How to use checksums
a6b4141bc79c464899c0ac95273dbe04e962c60e0b1b3591efd57e6ddc232472
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page