Unable to route a consumer through an included path
See original GitHub issueI’m attempting to route a channel to a consumer to handle messages from both javascript and model changes via a post_save
signal. This works when I include
the routes without a path, but including WITH the path produces an error:
ERROR - worker - Could not find match for message on consumer! Check your routing
The error occurs on socket connection since I’m sending a message on connect from my javascript and also appears when I attempt to save my model.
It appears that something within the include
functionality is preventing Channel
routing if a path is provided. Either that or the documentation failed to mention how to properly set up channels to handle paths within the routes.
// javascript call
socket = new WebSocket("ws://" + window.location.host + "/mission");
socket.onmessage = function(e) {
alert(e.data);
}
socket.onopen = function() {
socket.send("hello world");
}
// Call onopen directly if socket is already open
if (socket.readyState == WebSocket.OPEN) socket.onopen();
# routing.py
from channels.routing import route, include
from vits.consumers import ws_connect, ws_message, ws_disconnect, msg_consumer
mission_routing = [
route("websocket.connect", ws_connect),
route("websocket.receive", ws_message),
route("websocket.disconnect", ws_disconnect),
route("consumer", msg_consumer),
]
routing = [
include(mission_routing, path=r"^/mission") # note: this is where the path is declared. Without path declaration routing works as expected, with path error from above is produced
]
# In consumers.py
from channels import Channel
from channels.sessions import channel_session
from channels import Group
# Connected to chat-messages
def msg_consumer(message):
print("Message Consumed")
Group("mission_listeners").send({
"text": message.content['message']
})
# Connected to websocket.connect
@channel_session
def ws_connect(message):
print("ws_connect")
# Work out room name from path (ignore slashes)
room = message.content['path'].strip("/")
# Save room in session and add us to the group
message.channel_session['room'] = room
Group("mission_listeners").add(message.reply_channel)
# Accept the connection request
message.reply_channel.send({"accept": True})
# Connected to websocket.receive
@channel_session
def ws_message(message):
# Stick the message onto the processing queue
print(message['text'])
Channel("consumer").send({
"message": message['text'],
})
# Connected to websocket.disconnect
@channel_session
def ws_disconnect(message):
Group("mission_listeners").discard(message.reply_channel)
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Angular 6 route path not working for direct url when deployed ...
Try using: const routes: Routes = [ { path: 'customers', loadChildren: '../app/customers/customers.module#CustomersModule' }, { path: ...
Read more >Troubleshoot Open Shortest Path First Route Database Issues
This document describes how to repair a problem with Open Shortest Path First (OSPF) when routes in the database are not in the...
Read more >Unable to correctly import an OpenAPI 3.0 to API Gateway v2
Trying to import an OpenAPI 3.0 definition generated by FastAPI. The API only gets imported partially, and these warnings are listed in the...
Read more >Working with routes for HTTP APIs - Amazon API Gateway
Routes direct incoming API requests to backend resources. Routes consist of two parts: an HTTP method and a resource path—for example, GET /pets...
Read more >SFG Failed Route Shows Blank Fields for Producer ... - IBM
Symptom. An apparent failed route In FileGateway shows the producer, consumer, mailbox path as blank fields, file size is zero.
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
It’s somewhat covered here: http://channels.readthedocs.io/en/latest/getting-started.html#routing
I will say we could probably specifically call this out, however. You’re not the first person to make this mistake by far.
Ah, well that’s because you don’t have a path key in your message - the routing isn’t magical, it just goes off of the contents of the message.
websocket.connect
andwebsocket.receive
messages include apath
key so they can be routed, whereas yours just has amessage
key.Given you have made a separate channel especially for this, there’s no need for the path routing unless you really want to distinguish it, in which case you should ensure a path is added to the message when it’s sent onto the channel.