Coder Social home page Coder Social logo

franciscoda / channels_zmq Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 31 KB

ZeroMQ Channels layer implementation

Home Page: https://pypi.org/project/channels-zmq/0.1.0/

License: GNU General Public License v3.0

Python 100.00%
channels django django-channels zeromq

channels_zmq's Introduction

channels_zmq

Tests status PyPI

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  |
+------------+   +------------+   +-------------+   +-------------+

channels_zmq's People

Contributors

franciscoda avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.