Skip to main content

Multiplexing Consumer for django Channels.

Project description

Django Channels does not yet include a Multiplexing Consumer. This project aims to add such a multiplexer.

Version Compatibility

Channels Version

Channels Multiplexer Version

v2

0.0.2

v3

>=0.0.3

https://travis-ci.org/hishnash/channelsmultiplexer.svg?branch=master

Install

pip install channelsmultiplexer

Usage

to create a De-Multiplexer

class EchoDemultiplexerAsyncJson(AsyncJsonWebsocketDemultiplexer):
    applications = {
        "echostream": EchoTestConsumer(),
        "altechostream": AltEchoTestConsumer(),
        "closeafterfirst": EchoCloseAfterFirstTestConsumer(),
        "neveraccept": NeverAcceptTestConsumer()
    }

or you can use the AsyncJsonWebsocketDemultiplexer type directly and pass the multiplexed upstream consumers as kwargs.

application = ProtocolTypeRouter({
                      "websocket": URLRouter([
                                      url(r"^ws/$", AsyncJsonWebsocketDemultiplexer(
                                              echostream = EchoTestConsumer(),
                                              altechostream = AltEchoTestConsumer(),
                                              closeafterfirst = EchoCloseAfterFirstTestConsumer(),
                                              neveraccept = NeverAcceptTestConsumer()
                                      )),
                      ]),
                      "telegram": ChattyBotConsumer.as_asgi(),
      })

This acts just as any other channels consumer, however it will route incoming (JSON) messages to the upstream Consumers.

It does this by reading the value of the stream attribute in the message body. It will then pass the value of the payload attribute upstream.

{
    "stream": "echostream",
    "payload": {"hello": "world"}
}

Messages being sent downstream from the Multiplexed consumers will be embedded within a similar style msg.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

channelsmultiplexer-0.0.3.tar.gz (6.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page