Created
January 15, 2010 22:42
-
-
Save deleted/278486 to your computer and use it in GitHub Desktop.
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
class AmqpServiceWrapper(object): | |
''' | |
A wrapper class that takes care of the business of initialization: | |
- Creates an RpcChannel with the given parameters | |
- Instantiates a protobuf service of the given class | |
- Delegats further attribute access to the Service instance. | |
''' | |
class ParameterMissing(Exception): | |
pass | |
def __init__(self, | |
pb_service_class=None, | |
amqp_channel=None, | |
exchange='Control_Exchange', | |
request_routing_key=None, | |
reply_queue=None, | |
timeout_ms=5000, | |
max_retries=3): | |
self.amqp_channel = ampq_channel or MessageBus().channel | |
self.exchange = exchange | |
# Required parameters: | |
for param in ('pb_service_class', 'reply_queue', 'request_routing_key'): | |
if locals()[param]: | |
setattr(self, param, locals(param)) | |
else: | |
raise ParameterMissing("%s is a required parameter." % param) | |
self.rpc_channel = RpcChannel(self.CONTROL_EXCHANGE_NAME, self.REPLY_QUEUE_NAME, 'dispatch', max_retries=3, timeout_ms=timeout_ms) | |
self.rpc_service = service_stub_class(self.rpc_channel) | |
#self.amqp_rpc_controller = AmqpRpcController() | |
# Delegate other attribute access to protobuf rpc_service instance | |
def __getattr__(self, name): | |
return object.__getattribute__(self.rpc_service, name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment