mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
Send Tornado callback notifications via RabbitMQ
(imported from commit 83814d8c6b78fe725aedea9d98fb588ed31123e7)
This commit is contained in:
@@ -11,6 +11,7 @@ from tornado import ioloop
|
|||||||
from zephyr.lib.debug import interactive_debug_listen
|
from zephyr.lib.debug import interactive_debug_listen
|
||||||
from zephyr.lib.response import json_response
|
from zephyr.lib.response import json_response
|
||||||
from zephyr.lib.queue import TornadoQueueClient
|
from zephyr.lib.queue import TornadoQueueClient
|
||||||
|
from zephyr import tornado_callbacks
|
||||||
|
|
||||||
# A hack to keep track of how much time we spend working, versus sleeping in
|
# A hack to keep track of how much time we spend working, versus sleeping in
|
||||||
# the event loop.
|
# the event loop.
|
||||||
@@ -124,11 +125,14 @@ class Command(BaseCommand):
|
|||||||
print "Quit the server with %s." % quit_command
|
print "Quit the server with %s." % quit_command
|
||||||
|
|
||||||
if settings.USING_RABBITMQ:
|
if settings.USING_RABBITMQ:
|
||||||
|
# Process notifications received via RabbitMQ
|
||||||
queue_client = TornadoQueueClient()
|
queue_client = TornadoQueueClient()
|
||||||
while not queue_client.ready():
|
while not queue_client.ready():
|
||||||
step_tornado_ioloop()
|
step_tornado_ioloop()
|
||||||
|
|
||||||
# FIXME: Register consumer callbacks here
|
def process_notification(chan, method, props, data):
|
||||||
|
tornado_callbacks.process_notification(data)
|
||||||
|
queue_client.register_json_consumer('notify_tornado', process_notification)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Application is an instance of Django's standard wsgi handler.
|
# Application is an instance of Django's standard wsgi handler.
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from zephyr.models import Message, UserProfile, UserMessage, \
|
|||||||
|
|
||||||
from zephyr.decorator import JsonableError
|
from zephyr.decorator import JsonableError
|
||||||
from zephyr.lib.cache_helpers import cache_get_message
|
from zephyr.lib.cache_helpers import cache_get_message
|
||||||
|
from zephyr.lib.queue import SimpleQueueClient
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
@@ -247,7 +248,17 @@ def process_notification(data):
|
|||||||
#
|
#
|
||||||
# We use JSON rather than bare form parameters, so that we can represent
|
# We use JSON rather than bare form parameters, so that we can represent
|
||||||
# different types and for compatibility with non-HTTP transports.
|
# different types and for compatibility with non-HTTP transports.
|
||||||
def send_notification(data):
|
|
||||||
|
def send_notification_http(data):
|
||||||
requests.post(settings.TORNADO_SERVER + '/notify_tornado', data=dict(
|
requests.post(settings.TORNADO_SERVER + '/notify_tornado', data=dict(
|
||||||
data = simplejson.dumps(data),
|
data = simplejson.dumps(data),
|
||||||
secret = settings.SHARED_SECRET))
|
secret = settings.SHARED_SECRET))
|
||||||
|
|
||||||
|
def send_notification_rabbitmq(data):
|
||||||
|
notification_queue.json_publish('notify_tornado', data)
|
||||||
|
|
||||||
|
if settings.USING_RABBITMQ:
|
||||||
|
notification_queue = SimpleQueueClient()
|
||||||
|
send_notification = send_notification_rabbitmq
|
||||||
|
else:
|
||||||
|
send_notification = send_notification_http
|
||||||
|
|||||||
Reference in New Issue
Block a user