0

I'm working on django project that requires a real time communication, i found on google that best way to do is using MQTT protocol, in this way i need to write my own broker by subclassing HBMQTT broker , but it seems hard to run MQTT broker and django web server on the same service, also i found channels and ASGI application its very good at local using channel layers and redis, but i can't use redis on the web host 'some limitation in the host. Some solution told me to use channels with BACKEND channels.layers.InMemoryChannelLayer but according to their docs, its not for production.

is any idea? or better solution than using mqtt and channels? or i can mix HBMqtt.Broker with channels as any consumer? English is not my native language ,so I'm sorry for any errors.

  • can you use RabbitMQ? there is a channels layer for rabbitMQ http://github.com/CJWorkbench/channels_rabbitmq/ if not you might well be able to use this code as inspiration for writing your own MQTT layer. – Matthaus Woolard Feb 12 '20 at 01:58
  • is there any cacheable channels layer backend? i mean it uses drive storage to store there data? – Ahmed hamuda Feb 14 '20 at 07:14
  • Channels layers have the goal of sending messages to all the currently subscribed connections, they do not queue up messages to be sent later when a connection is made. So there is not use-case for persistence in a channel layer. – Matthaus Woolard Feb 14 '20 at 08:17
  • I don't need to queue up the messages, what i need is to send the same message to a group of users or all of them, channels uses channel-layer to group connections, and MQTT broker uses subscribed topics to send to the users. – Ahmed hamuda Feb 14 '20 at 18:33
  • so in channels you can send to a group, but you will only be able to send to users that are online when you send the msg. In channels a `topic` is considered a `channel_group` in your (HTTP or Websocket) Consumers you can subscribe to these. – Matthaus Woolard Feb 14 '20 at 21:02
  • I'm ok with this concept, channels uses redis database to store group name and messages, where i can't use it on my current host. i should upgrade, and will cost more. – Ahmed hamuda Feb 15 '20 at 23:43
  • unless my understanding about `channels` is wrong, but i don't assume that, because in the `channels`'s documentation they say if i used `InMemmoryChannelsLayer` i can't communicate between connectionss. – Ahmed hamuda Feb 15 '20 at 23:50
  • i'm very grateful for you help @MatthausWoolard – Ahmed hamuda Feb 15 '20 at 23:51
  • Yes that is correct, the `InMemmoryChannelsLayer` is for testing/development only and not to be used in production systems. What service are you using for the MQTT backbone? you might well be able to adapt the RabbitMQ layer to work with that since the MQTT protocol should have everything you need. – Matthaus Woolard Feb 16 '20 at 02:16
  • I used `HBmqtt` library to run my own MQTT server, because i need to use token base auth system with mqtt server, I'll try this solution. But it seems to have a server to run mqtt server. – Ahmed hamuda Feb 16 '20 at 21:40
  • yep you will need some type for queue/subscription service running for channels, if your re running multiple servers then that queue service will need to be accessible to all of them, so that regardless of the server the user connects to they can get messages. – Matthaus Woolard Feb 17 '20 at 00:20
  • I sorry i meant "But it seems to have another host to run mqtt server" not "But it seems to have a server to run mqtt server" – Ahmed hamuda Feb 19 '20 at 06:09
  • Thank you @MatthausWoolard, I decided to bay another host, now tell me how to close this question! (: :D – Ahmed hamuda Feb 19 '20 at 06:09

0 Answers0