Add echo channel and fix __str__ on redis backend

This commit is contained in:
Andrew Godwin 2015-11-06 08:12:51 -08:00
parent a41516fa6b
commit f3c3a239b9
2 changed files with 11 additions and 1 deletions

View File

@ -183,4 +183,4 @@ class RedisChannelBackend(BaseChannelBackend):
self.connection(self.consistent_hash(channel)).delete(key) self.connection(self.consistent_hash(channel)).delete(key)
def __str__(self): def __str__(self):
return "%s(host=%s, port=%s)" % (self.__class__.__name__, self.host, self.port) return "%s(hosts=%s)" % (self.__class__.__name__, self.hosts)

View File

@ -14,6 +14,8 @@ class ConsumerRegistry(object):
def __init__(self, routing=None): def __init__(self, routing=None):
self.consumers = {} self.consumers = {}
# Add basic internal consumers
self.add_consumer(self.echo_consumer, ["__channels__.echo"])
# Initialise with any routing that was passed in # Initialise with any routing that was passed in
if routing: if routing:
# If the routing was a string, import it # If the routing was a string, import it
@ -56,3 +58,11 @@ class ConsumerRegistry(object):
return self.consumers[channel] return self.consumers[channel]
except KeyError: except KeyError:
return None return None
def echo_consumer(self, message):
"""
Implements the echo message standard.
"""
message.reply_channel.send({
"content": message.content.get("content", None),
})