Example #1
0
    def __init__(self, topics=[], parent=None, name=None):
        self.parent = parent
        self.listeners = []
        self.topics = []
        self.name = __name__ if name is None else name
        self.participants = {}
        self.log = Log(self.name, self.do_log)
        if parent:
            parent.register(self, topics)
            return

        self.connection, self.exchange = messaging.open_connection()
        self.channel = self.connection.channel()
        self.channel.exchange_declare(exchange=self.exchange, type="direct")

        self.sender = Sender(self.channel, self.exchange)

        if len(topics) == 0:
            return

        self.register(topics=topics)
Example #2
0
	def __init__(self, topics=[], parent=None, name=None):
		self.parent = parent
		self.listeners = []
		self.topics = []
		self.name = __name__ if name is None else name
		self.participants = {}
		self.log = Log(self.name, self.do_log)
		if parent:
			parent.register(self, topics)
			return

		self.connection, self.exchange = messaging.open_connection()
		self.channel = self.connection.channel()
		self.channel.exchange_declare(exchange=self.exchange,
				type="direct")

		self.sender = Sender(self.channel, self.exchange)

		if len(topics) == 0:
			return

		self.register(topics=topics)
Example #3
0
#!/bin/python
# -*- coding: utf-8 -*-
# vim:set ts=8 sts=8 sw=8 tw=80 noet cc=80:

import sys
import json
from messaging import open_connection, ROUTING_KEY_SENDMUC

if __name__ == "__main__":
	connection, exchange = open_connection()
	channel = connection.channel()
	channel.exchange_declare(exchange=exchange, type="direct")

	result = channel.queue_declare(exclusive=True)
	queue_name = result.method.queue
	channel.queue_bind(exchange=exchange, queue=queue_name,
			routing_key=ROUTING_KEY_SENDMUC)

	def send(key, data):
		channel.basic_publish(exchange=exchange,
				routing_key=key,
				body=json.dumps(data).encode('utf-8'))

	def send_muc(msg):
		send(ROUTING_KEY_SENDMUC, msg)

	try:
		while True:
			sys.stdout.write('> ')
			sys.stdout.flush()
			line = sys.stdin.readline()
Example #4
0
							exchange=self.exchange,
							routing_key=msg['routing_key'],
							body=msg['body'])
				except Exception as e:
					log.error("Messaging error: %s" % e)
				self.queue.task_done() # fixme: retry
		t = threading.Thread(target=worker)
		t.daemon = True
		t.start()

xmpp = None
if __name__ == "__main__":
	logging.basicConfig(level=logging.INFO,
		                        format='%(levelname)-8s %(message)s')

	connection, exchange = open_connection()
	channel = connection.channel()
	channel.exchange_declare(exchange=exchange, type="direct")

	## ugly workaround because pika does not like multiple threads
	#send_connection, exchange = open_connection()
	#send_channel = send_connection.channel()
	sender = Sender(channel, exchange)
	sender.start()

	def send(key, data):
		sender.send(routing_key=key,
			body=json.dumps(data).encode('utf-8'))

	#def send(key, data):
	#	channel.basic_publish(exchange=exchange, routing_key=key,