AsyncJsonWebsocketConsumer and channel redis doesn't work
See original GitHub issueDjango==2.2.6
django-heroku==0.3.1
daphne==2.4.0
gunicorn==19.9.0
requests==2.22.0
channels==2.3.1
channels-redis==2.4.1
I have a simple consumer program that I am testing my redis server, but I don’t see the channel function executing.
from channels.generic.websocket import AsyncJsonWebsocketConsumer
class backEndConsumer(AsyncJsonWebsocketConsumer):
async def websocket_connect(self, type):
self.channel_name = "first"
await self.channel_layer.group_add("link", self.channel_name)
await self.accept()
async def websocket_disconnect(self, close_code):
await self.close()
await self.channel_layer.group_discard("link", self.channel_name)
# Called when the socket closes
async def websocket_receive(self, text_data=None, bytes_data=None):
await self.send("Connected")
await self.channel_layer.group_send(
"link",
{
"type": "link.send",
"message": "msg from websocket",
})
#channel layer functions
async def link_send(self, event):
print("got message: " + event["message"])
await self.send("triggered!")
my settings.py has this
redis_host = os.environ.get('REDIS_HOST', 'localhost')
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [(redis_host, 6379)],
},
},
}
I believe I followed most of the examples (including the multichat example). But my code doesn’t seem to work. I have found people with issues similar to mine and it seems like they found work arounds, but it didn’t apply to my code.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Django websockets and channels group_send not working
Problem is that My webclient will totally ignore this. recv method is never executed nor WebClient consumer will not show any activity on...
Read more >Consumers — Channels 4.0.0 documentation
RedisChannelLayer both support groups). If no channel layer is configured or the channel layer doesn't support groups, connecting to a WebsocketConsumer with a ......
Read more >Installing Django Channels 2 (Redis and WebSockets)
Watch the course: https://codingwithmitch.com/courses/real-time-chat-messenger/Installing django channels 2 into your django project.
Read more >Channels Documentation - Read the Docs
Channels is a project that takes Django and extends its abilities beyond HTTP - to handle WebSockets, chat protocols,.
Read more >Channels 2: Consumer running twice when two users ...
However, if there is only one participant in the channel, the message will run through the consumer once and save once as expected....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve moved my question to https://stackoverflow.com/questions/59886447/interactions-between-http-and-websocket-connections-in-django-channels
@hishnash I am trying to figure out a way to build an IOT device, with a http requests coming from DialogFlow and then using websocket to talk to my embedded device.
I still have questions about the inner workings of django-channels, I will probably reform my questions and put them on stackoverflow.
edit: I tried to put the 200 request in webhook_reg(), which gets called from websocket_reg(), it gets the same no handler for message type.