# Path: pygowave_rpc/amqp_client.py
# class AmqpMessageProcessor(object):
# 	purge_every = datetime.timedelta(minutes=10)
# 	conn_lifetime = datetime.timedelta(minutes=getattr(settings, "ACCESS_KEY_TIMEOUT_MINUTES", 2))
# 	
# 	def __init__(self, connection):
# 		self.pygo_mp = PyGoWaveClientMessageProcessor()
# 		self.consumer = Consumer(
# 			connection,
# 			queue="wavelet_rpc_singlethread",
# 			exchange="wavelet.topic",
# 			routing_key="#.#.clientop",
# 			exchange_type="topic",
# 			serializer="json",
# 			auto_ack=True,
# 		)
# 		self.consumer.register_callback(self.receive)
# 		self.publisher = Publisher(
# 			connection,
# 			exchange="wavelet.direct",
# 			exchange_type="direct",
# 			delivery_mode=1,
# 			serializer="json",
# 		)
# 		
# 		self.pygo_mp.purge_connections()
# 		self.next_purge = datetime.datetime.now() + self.purge_every
# 	
# 	def wait(self, limit=None):
# 		self.consumer.wait(limit)
# 	
# 	def send(self, routing_key, message_data):
# 		self.publisher.send(message_data, routing_key=routing_key, delivery_mode=1)
# 	
# 	def receive(self, message_data, message):
# 		routing_key = message.amqp_message.routing_key
# 		
# 		msg_dict = self.pygo_mp.process(routing_key, message_data)
# 		
# 		for out_rkey, messages in msg_dict.iteritems():
# 			self.send(out_rkey, messages)
# 		
# 		# Cleanup time?
# 		if datetime.datetime.now() > self.next_purge:
# 			self.pygo_mp.purge_connections()
# 			self.next_purge = datetime.datetime.now() + self.purge_every


import sys, os, logging
import pygowave_rpc.logger
import signal
	import traceback
from carrot.connection import AMQPConnection
from pygowave_rpc.amqp_client import AmqpMessageProcessor
from django.conf import settings
# Copyright 2009 Patrick Schneider <patrick.p2k.schneider@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# This is PyGoWave's RPC script used for client-to-server communication only
# through RabbitMQ. This may be slightly faster than it's twisted-based cousin.


sys.path.append(os.path.dirname(__file__))
if not os.environ.has_key("DJANGO_SETTINGS_MODULE"):
	os.environ["DJANGO_SETTINGS_MODULE"] = "settings"




logger = pygowave_rpc.logger.setupLogging()

if pygowave_rpc.logger.logMode() == "verbose":
	amqplogger = logging.getLogger("amqplib")

# Path: pygowave_rpc/amqp_client.py
# class AmqpMessageProcessor(object):
# 	purge_every = datetime.timedelta(minutes=10)
# 	conn_lifetime = datetime.timedelta(minutes=getattr(settings, "ACCESS_KEY_TIMEOUT_MINUTES", 2))
# 	
# 	def __init__(self, connection):
# 		self.pygo_mp = PyGoWaveClientMessageProcessor()
# 		self.consumer = Consumer(
# 			connection,
# 			queue="wavelet_rpc_singlethread",
# 			exchange="wavelet.topic",
# 			routing_key="#.#.clientop",
# 			exchange_type="topic",
# 			serializer="json",
# 			auto_ack=True,
# 		)
# 		self.consumer.register_callback(self.receive)
# 		self.publisher = Publisher(
# 			connection,
# 			exchange="wavelet.direct",
# 			exchange_type="direct",
# 			delivery_mode=1,
# 			serializer="json",
# 		)
# 		
# 		self.pygo_mp.purge_connections()
# 		self.next_purge = datetime.datetime.now() + self.purge_every
# 	
# 	def wait(self, limit=None):
# 		self.consumer.wait(limit)
# 	
# 	def send(self, routing_key, message_data):
# 		self.publisher.send(message_data, routing_key=routing_key, delivery_mode=1)
# 	
# 	def receive(self, message_data, message):
# 		routing_key = message.amqp_message.routing_key
# 		
# 		msg_dict = self.pygo_mp.process(routing_key, message_data)
# 		
# 		for out_rkey, messages in msg_dict.iteritems():
# 			self.send(out_rkey, messages)
# 		
# 		# Cleanup time?
# 		if datetime.datetime.now() > self.next_purge:
# 			self.pygo_mp.purge_connections()
# 			self.next_purge = datetime.datetime.now() + self.purge_every


# Path: amqp_rpc_server.py
import sys, os, logging
import pygowave_rpc.logger
import signal
	import traceback
from carrot.connection import AMQPConnection
from pygowave_rpc.amqp_client import AmqpMessageProcessor
from django.conf import settings

# Copyright 2009 Patrick Schneider <patrick.p2k.schneider@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# This is PyGoWave's RPC script used for client-to-server communication only
# through RabbitMQ. This may be slightly faster than it's twisted-based cousin.


sys.path.append(os.path.dirname(__file__))
if not os.environ.has_key("DJANGO_SETTINGS_MODULE"):
	os.environ["DJANGO_SETTINGS_MODULE"] = "settings"




logger = pygowave_rpc.logger.setupLogging()

if pygowave_rpc.logger.logMode() == "verbose":
	amqplogger = logging.getLogger("amqplib")

	amqplogger.setLevel(logging.DEBUG)