Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hishnash/channelsmultiplexer
Channels v3 Multiplerxer
https://github.com/hishnash/channelsmultiplexer
channels django
Last synced: about 1 month ago
JSON representation
Channels v3 Multiplerxer
- Host: GitHub
- URL: https://github.com/hishnash/channelsmultiplexer
- Owner: hishnash
- License: mit
- Created: 2018-05-09T11:07:20.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-07-20T22:18:43.000Z (4 months ago)
- Last Synced: 2024-09-30T10:42:35.177Z (about 2 months ago)
- Topics: channels, django
- Language: Python
- Homepage:
- Size: 22.5 KB
- Stars: 33
- Watchers: 4
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
====================
Channels Multiplexer
====================Django Channels_ does not yet include a Multiplexing Consumer. This project aims to add such a multiplexer.
.. _Channels: https://github.com/django/channels
Version Compatibility
---------------------+--------------------+--------------------------------+
| Channels Version | Channels Multiplexer Version |
+====================+================================+
| v2 | `0.0.2` |
+--------------------+--------------------------------+
| v3 | `>=0.0.3` |
+--------------------+--------------------------------+.. image:: https://travis-ci.org/hishnash/channelsmultiplexer.svg?branch=master
:target: https://travis-ci.org/hishnash/channelsmultiplexerInstall
-------.. code-block:: bash
pip install channelsmultiplexer
Usage
-----to create a De-Multiplexer
.. code-block:: python
from channelsmultiplexer import AsyncJsonWebsocketDemultiplexerclass EchoDemultiplexerAsyncJson(AsyncJsonWebsocketDemultiplexer):
applications = {
"echostream": EchoTestConsumer.as_asgi(),
"altechostream": AltEchoTestConsumer.as_asgi(),
"closeafterfirst": EchoCloseAfterFirstTestConsumer.as_asgi(),
"neveraccept": NeverAcceptTestConsumer.as_asgi()
}When using this within our `application` you should reference it like this `EchoDemultiplexerAsyncJson.as_asgi()`.
or you can use the `AsyncJsonWebsocketDemultiplexer` type directly and pass the multiplexed upstream consumers as kwargs.
.. code-block:: python
application = ProtocolTypeRouter({
"websocket": URLRouter([
url(r"^ws/$", AsyncJsonWebsocketDemultiplexer.as_asgi(
echostream = EchoTestConsumer.as_asgi(),
altechostream = AltEchoTestConsumer.as_asgi(),
closeafterfirst = EchoCloseAfterFirstTestConsumer.as_asgi(),
neveraccept = NeverAcceptTestConsumer.as_asgi()
)),
]),
"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.
.. code-block:: json
{
"stream": "echostream",
"payload": {"hello": "world"}
}Messages being sent downstream from the Multiplexed consumers will be embedded within a similar style message.