class RpcRig(object): """ RpcRig encapsulates the objects necessary make RPCs to a single reaper. Service and controller are the properties you need to make a call: response = rpc_rig.service.{methodname}(rpc_rig.controller, request, callback) """ REPLY_QUEUE_NAME = 'reaperctl.reply' CONTROL_EXCHANGE_NAME = 'Control_Exchange' def __init__(self, target_uuid, timeout_ms=1000): self.messagebus = MessageBus() self.TARGET_QUEUE = "control.reaper.%s" % target_uuid self.messagebus.queue_declare(queue=self.REPLY_QUEUE_NAME, durable=False, auto_delete=True) self.messagebus.queue_bind(self.REPLY_QUEUE_NAME, self.CONTROL_EXCHANGE_NAME, routing_key=self.REPLY_QUEUE_NAME) self.rpc_channel = protocols.rpc_services.RpcChannel( self.CONTROL_EXCHANGE_NAME, self.REPLY_QUEUE_NAME, self.TARGET_QUEUE) self.service = protobuf.ReaperCommandService_Stub(self.rpc_channel) self.controller = protocols.rpc_services.AmqpRpcController( timeout_ms=timeout_ms) def __getattr__(self, name): ''' Delegate object access to the service stub ''' if hasattr(self, 'service'): return object.__getattribute__(self.service, name)
def __init__(self, target_uuid, timeout_ms=1000): self.messagebus = MessageBus() self.TARGET_QUEUE = "control.reaper.%s" % target_uuid self.messagebus.queue_declare(queue=self.REPLY_QUEUE_NAME, durable=False, auto_delete=True) self.messagebus.queue_bind(self.REPLY_QUEUE_NAME, self.CONTROL_EXCHANGE_NAME, routing_key=self.REPLY_QUEUE_NAME) self.rpc_channel = protocols.rpc_services.RpcChannel( self.CONTROL_EXCHANGE_NAME, self.REPLY_QUEUE_NAME, self.TARGET_QUEUE) self.service = protobuf.ReaperCommandService_Stub(self.rpc_channel) self.controller = protocols.rpc_services.AmqpRpcController( timeout_ms=timeout_ms)
def __init__(self, job_poll_interval = 10): self.reaper_id = uuid.uuid1().hex self.messagebus = MessageBus() self.chan = self.messagebus.channel self.is_registered = None self.JOB_POLL_INTERVAL = job_poll_interval self.CONTROL_QUEUE_NAME = "rpc.reaper.%s" % self.reaper_id self.REPLY_QUEUE_NAME = "reply.reaper.%s" % self.reaper_id # queue for RPC responses self.logger = logging.getLogger('reaper.%s' % self.reaper_id) #self.logger.setLevel(logging.DEBUG) # Accept control commands via the control exchange: self.chan.exchange_declare(self.CONTROL_EXCHANGE_NAME, type='direct') self.chan.queue_declare(queue=self.CONTROL_QUEUE_NAME, durable=False, auto_delete=True) self.chan.queue_bind(queue=self.CONTROL_QUEUE_NAME, exchange=self.CONTROL_EXCHANGE_NAME, routing_key=self.CONTROL_QUEUE_NAME) # RPC Service to dispatch self.dispatch = DispatchService(reply_queue=self.REPLY_QUEUE_NAME, ) # Init threads to handle message consumption self.shutdown_event = threading.Event() self.control_listener = ConsumptionThread(mode='GET', shutdown_event=self.shutdown_event, name="control_listener")