Would the chat demo work with multiple front-ends?

17 views
Skip to first unread message

Todd Williams

unread,
May 28, 2010, 3:06:06 AM5/28/10
to Tornado Web Server
I may be misunderstanding the logic. Would the chat demo work with
multiple front-ends? If a user sends a message and one front-end
receives it, while the person listening for messages is connected to a
different front-end, wouldn't that be a problem?

If so, how would this type of issue be resolved?

杰米

unread,
May 28, 2010, 4:45:16 AM5/28/10
to python-...@googlegroups.com
is Broadcasting?

Grigory Fateyev

unread,
May 28, 2010, 7:14:55 AM5/28/10
to python-...@googlegroups.com
Hello Todd Williams!

I use for that stompserver. For example: lets you have three frontends.
In asynchronous function before self.write([message]) I send message to
stompserver via stom_sender function:

def stomp_sender(queue, message):
hosts = [(settings.STOMP_HOST, settings.STOMP_PORT)]
try:
conn = stomp.Connection(host_and_ports=hosts)
conn.start()
conn.connect()
# send the message
conn.send(message, destination=queue)
message = json.loads(message)
logging.info("Message with ID %s was send to stomp server",
message["id"]) conn.disconnect()
except socket.error, e:
logging.error("Message was not send, error is: %s", e)

On all frontends I have such class, that listen stomp and send messages
to each frontend:

class MainListener(ConnectionListener, PostMixin):
def __init__(self, event_id=None):
if event_id:
self.event_id = event_id
self.queues = []

def on_error(self, headers, message):
logging.error("Recieved an error for message %s", message)

def on_message(self, headers, message):
message = json.loads(message)
logging.info("Recieved message with ID: %s", message["id"])
self.new_messages([message])

And main() function that start this listener via tornado start:

def main():
tornado.options.parse_command_line()
#Start Stomp listener
try:
conn = stomp.Connection(host_and_ports=[(options.stomp_host,
options.stomp_port)]) conn.set_listener('', MainListener())
conn.start()
conn.connect()
#FIXME: Destinations should be taken from DB
conn.subscribe(destination='/blog/updates', ack='auto')
except socket.error:
logging.error("Listeer can't start, connection error is: %s",
socket.error)
tornado.locale.load_gettext_translations(os.path.join(os.path.dirname(__file__),
"translations"), 'liveblog') #Start Tornado
http_server = tornado.httpserver.HTTPServer(app.Application())
http_server.listen(options.port)
...

I hope this helps you.
--
Всего наилучшего!

Alex Michael

unread,
Jun 9, 2010, 6:14:35 AM6/9/10
to Tornado Web Server
Hi

I am wokprking on a chat project as well and I ran into the same
issues.

I was thinking of using RPC from the front ends to a central Tornado
instance which keeps track of the async callbacks and sends the
messages.

Anyone has any insights on whether that would be an efficient
solution?

Thanks

On May 28, 8:06 am, Todd Williams <to...@media1designs.com> wrote:
> I may be misunderstanding the logic. Would the chat demo work withmultiplefront-ends? If a user sends a message and onefront-end
> receives it, while the person listening for messages is connected to a
> differentfront-end, wouldn't that be a problem?

Stanislav

unread,
Jun 9, 2010, 4:38:19 PM6/9/10
to Tornado Web Server
We use Redis to keep track of which instance any user is connected to
at any given time, and since all messages are handled through a queue
(Beanstalkd). The workers of the queue simply ask Redis which machine
they need to RPC to, to deliver a message.

On Jun 9, 3:14 am, Alex Michael <alexandros.mich...@googlemail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages