-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renamed to script-exchange, and generalised to support python etc as …
…well as js
- Loading branch information
Showing
13 changed files
with
246 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,6 +1,6 @@ | |||
This package, js-exchange, an exchange type plugin for use with | This package, script-exchange, an exchange type plugin for use with | ||
RabbitMQ, is licensed under the MPL. For the MPL, please see | RabbitMQ, is licensed under the MPL. For the MPL, please see | ||
LICENSE-MPL-js-exchange. | LICENSE-MPL-script-exchange. | ||
|
|
||
If you have any questions regarding licensing, please contact | If you have any questions regarding licensing, please contact | ||
info@rabbitmq.com. | info@rabbitmq.com. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,3 +1,4 @@ | |||
## RabbitMQ Javascript exchange plugin | ## RabbitMQ Script Exchange Plugin | ||
|
|
||
Requires Spidermonkey. I've been using version "1.8.0 pre-release 1 2007-10-03". | Requires Spidermonkey for Javascript support. I've been using version | ||
"1.8.0 pre-release 1 2007-10-03". |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
{application, rabbit_script_exchange, | |||
[{description, "RabbitMQ Script Exchange Plugin"}, | |||
{vsn, "0.01"}, | |||
{modules, [script_exchange, | |||
script_instance, | |||
script_instance_manager, | |||
script_manager_sup]}, | |||
{registered, []}, | |||
{env, [{languages, [{<<"text/javascript">>, [{command_line, "js js_exchange_boot.js"}]}, | |||
{<<"text/x-python">>, [{command_line, "python py_exchange_boot.py"}]}]}, | |||
{max_instance_count, 3}]}, | |||
{applications, [kernel, stdlib, rabbit, mnesia]}]}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,41 @@ | |||
#!/usr/bin/env python | |||
import sys | |||
sys.path.append('../pika') | |||
import pika | |||
import asyncore | |||
|
|||
conn = pika.AsyncoreConnection(pika.ConnectionParameters( | |||
'127.0.0.1', | |||
credentials=pika.PlainCredentials('guest', 'guest'))) | |||
|
|||
ch = conn.channel() | |||
|
|||
# try: | |||
# print ch.exchange_delete(exchange='x-script') | |||
# except pika.exceptions.ChannelClosed: | |||
# ch = conn.channel() | |||
|
|||
print ch.exchange_declare(exchange='x-script', type='x-script', arguments={ | |||
"type": "text/x-python", | |||
"definition": r""" | |||
counter = 0 | |||
def handler(msg): | |||
global counter | |||
msg.fanout() | |||
msg.direct("hi") | |||
msg.topic("x.y." + msg.routing_key) | |||
msg.properties['user_id'] = "THISISTHEUSER" | |||
msg.body = str(counter) + "\n" + msg.body | |||
counter = counter + 1 | |||
""" | |||
}) | |||
|
|||
print ch.queue_declare(queue='x-script-q', auto_delete=True) | |||
print ch.queue_bind(queue='x-script-q', exchange='x-script', routing_key='hi') | |||
print ch.queue_bind(queue='x-script-q', exchange='x-script', routing_key='*.y.#') | |||
print ch.queue_bind(queue='x-script-q', exchange='x-script', routing_key='x.#') | |||
print ch.basic_publish(exchange='x-script', routing_key='testrk', body='testbody', | |||
properties=pika.BasicProperties(content_type='text/plain')) | |||
|
|||
conn.close() | |||
asyncore.loop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,92 @@ | |||
import simplejson | |||
import sys | |||
|
|||
modules = {} | |||
|
|||
def send_obj(id, op, payload): | |||
print simplejson.dumps({'id': id, 'op': op, 'payload': payload}) | |||
sys.stdout.flush() | |||
|
|||
def dbg(v): | |||
send_obj(None, "cast", ["io", "format", ["~p~n", [v]]]) | |||
|
|||
def info(v): | |||
send_obj(None, "cast", ["error_logger", "info_report", [v]]) | |||
|
|||
def log_error(report): | |||
send_obj(None, "cast", ["error_logger", "error_report", [report]]) | |||
|
|||
def do_cast(payload): | |||
(m, f, a) = payload | |||
m = modules[m] | |||
f = getattr(m, f) | |||
return f(*a) | |||
|
|||
def mainloop1(): | |||
try: | |||
line = raw_input() | |||
except EOFError: | |||
return False | |||
req = simplejson.loads(line) | |||
return dispatch_request(req) | |||
|
|||
def dispatch_request(req): | |||
op = req['op'] | |||
if op == "call": | |||
send_obj(req['id'], "reply", do_cast(req['payload'])) | |||
elif op == "cast": | |||
do_cast(req['payload']) | |||
else: | |||
log_error({"message": "Invalid request sent to js instance", "req": req}) | |||
return True | |||
|
|||
def mainloop(): | |||
try: | |||
while mainloop1(): | |||
pass | |||
except: | |||
import traceback | |||
log_error({"message": "Exception in mainloop", "e": traceback.format_exc()}) | |||
|
|||
########################################################################### | |||
|
|||
class Message(object): | |||
def __init__(self, rk, props, body): | |||
self.routing_key = rk | |||
self.properties = props | |||
self.body = body | |||
self.routing_actions = [] | |||
|
|||
def fanout(self): | |||
self.routing_actions.append("fanout") | |||
|
|||
def direct(self, rk): | |||
self.routing_actions.append(["direct", rk]) | |||
|
|||
def topic(self, rk): | |||
self.routing_actions.append(["topic", rk]) | |||
|
|||
class Exchange: | |||
def __init__(self): | |||
self.handlers = {} | |||
|
|||
def validate(self, xname, args): | |||
if not 'definition' in args: | |||
return False | |||
return True | |||
|
|||
def create(self, xname, args): | |||
vars = {} | |||
exec args['definition'] in globals(), vars | |||
self.handlers[','.join(xname)] = vars['handler'] | |||
|
|||
def publish(self, xname, rk, props, body): | |||
handler = self.handlers[','.join(xname)] | |||
msg = Message(rk, props, body) | |||
handler(msg) | |||
return [msg.properties, msg.body, msg.routing_actions] | |||
|
|||
modules['Exchange'] = Exchange() | |||
|
|||
info("Python instance started OK") | |||
mainloop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.