def on_start(self): super(TransformDataProcess,self).on_start() if dot.isEnabledFor(logging.INFO): pubsub_cli = PubsubManagementServiceProcessClient(process=self) self.streams = self.CFG.get_safe('process.publish_streams',{}) for k,v in self.streams.iteritems(): stream_route = pubsub_cli.read_stream_route(v) queue_name = re.sub(r'[ -]', '_', self.queue_name) dot.info(' %s -> %s' %( queue_name, stream_route.routing_key.strip('.stream')))
def on_start(self): super(TransformDataProcess, self).on_start() if dot.isEnabledFor(logging.INFO): pubsub_cli = PubsubManagementServiceProcessClient(process=self) self.streams = self.CFG.get_safe('process.publish_streams', {}) for k, v in self.streams.iteritems(): stream_route = pubsub_cli.read_stream_route(v) queue_name = re.sub(r'[ -]', '_', self.queue_name) dot.info( ' %s -> %s' % (queue_name, stream_route.routing_key[:-len('.stream')]))
def __init__(self, process=None, stream_id='', stream_route=None, exchange_point='', routing_key=''): ''' Creates a StreamPublisher which publishes to the specified stream by default and is attached to the specified process. @param process The process which the subscriber is to be attached. @param stream_id Stream identifier for the publishing stream. @param stream_route A StreamRoute corresponding to the stream_id @param exchange_point The name of the exchange point, to be used in lieu of stream_route or stream_id @param routing_key The routing key to be used in lieu of stream_route or stream_id ''' super(StreamPublisher, self).__init__() validate_is_instance(process, BaseService, 'No valid process provided.') #-------------------------------------------------------------------------------- # The important part of publishing is the stream_route and there are three ways # to the stream route # - The Route is obtained from Pubsub Management with a stream id. # - The Route is obtained by combining exchange_point and the routing_key # but all other information is lost (credentials, etc.) # - The Route is obtained by being provided directly to __init__ #-------------------------------------------------------------------------------- self.stream_id = stream_id if stream_id: # Regardless of what's passed in for stream_route look it up, prevents mismatching pubsub_cli = PubsubManagementServiceProcessClient(process=process, node=process.container.node) self.stream_route = pubsub_cli.read_stream_route(stream_id) elif not stream_route: self.stream_route = None if exchange_point and routing_key: self.stream_route = StreamRoute(exchange_point=exchange_point, routing_key=routing_key) else: pubsub_cli = PubsubManagementServiceProcessClient(process=process, node=process.container.node) stream_id, stream_route = pubsub_cli.create_stream(process.id, exchange_point=exchange_point or 'void') self.stream_id = stream_id self.stream_route = stream_route else: self.stream_route = stream_route validate_is_instance(self.stream_route, StreamRoute, 'No valid stream route provided to publisher.') self.container = process.container self.xp = self.container.ex_manager.create_xp(self.stream_route.exchange_point) self.xp_route = self.xp.create_route(self.stream_route.routing_key)