From f3c3a239b9b8d937a00b01ac451a4b113f341bb2 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Fri, 6 Nov 2015 08:12:51 -0800 Subject: [PATCH] Add echo channel and fix __str__ on redis backend --- channels/backends/redis_py.py | 2 +- channels/consumer_registry.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/channels/backends/redis_py.py b/channels/backends/redis_py.py index 8c263a7..a4f22d0 100644 --- a/channels/backends/redis_py.py +++ b/channels/backends/redis_py.py @@ -183,4 +183,4 @@ class RedisChannelBackend(BaseChannelBackend): self.connection(self.consistent_hash(channel)).delete(key) 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) diff --git a/channels/consumer_registry.py b/channels/consumer_registry.py index cefe4c6..baf1945 100644 --- a/channels/consumer_registry.py +++ b/channels/consumer_registry.py @@ -14,6 +14,8 @@ class ConsumerRegistry(object): def __init__(self, routing=None): self.consumers = {} + # Add basic internal consumers + self.add_consumer(self.echo_consumer, ["__channels__.echo"]) # Initialise with any routing that was passed in if routing: # If the routing was a string, import it @@ -56,3 +58,11 @@ class ConsumerRegistry(object): return self.consumers[channel] except KeyError: return None + + def echo_consumer(self, message): + """ + Implements the echo message standard. + """ + message.reply_channel.send({ + "content": message.content.get("content", None), + })