Beispiel #1
0
    def perspective_connector_add(self, ClientConfig):
        """This will add a new connector to self.connectors
        and get a listener on submit.sm.%cid queue, this listener will be
        started and stopped when the connector will get started and stopped
        through this API"""

        c = pickle.loads(ClientConfig)

        self.log.debug('Adding a new connector %s', c.id)

        if self.getConnector(c.id) is not None:
            self.log.error(
                'Trying to add a new connector with an already existant cid: %s',
                c.id)
            defer.returnValue(False)
        if self.amqpBroker is None:
            self.log.error('AMQP Broker is not added')
            defer.returnValue(False)
        if self.amqpBroker.connected == False:
            self.log.error('AMQP Broker channel is not yet ready')
            defer.returnValue(False)

        # Declare queues
        # First declare the messaging exchange
        yield self.amqpBroker.chan.exchange_declare(exchange='messaging',
                                                    type='topic')
        # submit.sm queue declaration and binding
        routing_key_submit_sm = 'submit.sm.%s' % c.id
        self.log.info('Declaring submit_sm queue to listen to: %s',
                      routing_key_submit_sm)
        yield self.amqpBroker.named_queue_declare(queue=routing_key_submit_sm)
        yield self.amqpBroker.chan.queue_bind(
            queue=routing_key_submit_sm,
            exchange="messaging",
            routing_key=routing_key_submit_sm)
        # submit.sm.resp queue declaration and binding
        routing_key_submit_sm_resp = 'submit.sm.resp.%s' % c.id
        self.log.info('Declaring submit_sm_resp queue to publish to: %s',
                      routing_key_submit_sm_resp)
        yield self.amqpBroker.named_queue_declare(
            queue=routing_key_submit_sm_resp)
        yield self.amqpBroker.chan.queue_bind(
            queue=routing_key_submit_sm_resp,
            exchange="messaging",
            routing_key=routing_key_submit_sm_resp)
        # deliver.sm queue declaration and binding
        routing_key_deliver_sm = 'deliver.sm.%s' % c.id
        self.log.info('Declaring deliver_sm queue to publish to: %s',
                      routing_key_deliver_sm)
        yield self.amqpBroker.named_queue_declare(queue=routing_key_deliver_sm)
        yield self.amqpBroker.chan.queue_bind(
            queue=routing_key_deliver_sm,
            exchange="messaging",
            routing_key=routing_key_deliver_sm)
        # dlr queue declaration and binding
        routing_key_dlr = 'dlr.%s' % c.id
        self.log.info('Declaring dlr queue to publish to: %s', routing_key_dlr)
        yield self.amqpBroker.named_queue_declare(queue=routing_key_dlr)
        yield self.amqpBroker.chan.queue_bind(queue=routing_key_dlr,
                                              exchange="messaging",
                                              routing_key=routing_key_dlr)

        # Instanciate smpp client service manager
        serviceManager = SMPPClientService(c, self.config)

        # Instanciate a SM listener
        smListener = SMPPClientSMListener(
            SMPPClientSMListenerConfig(self.config.config_file),
            serviceManager.SMPPClientFactory, self.amqpBroker,
            self.redisClient)

        # Deliver_sm are sent to smListener's deliver_sm callback method
        serviceManager.SMPPClientFactory.msgHandler = smListener.deliver_sm_event

        self.connectors.append({
            'id': c.id,
            'config': c,
            'service': serviceManager,
            'consumer_tag': None,
            'submit_sm_q': None,
            'sm_listener': smListener,
        })

        self.log.info('Added a new connector: %s', c.id)

        # Set persistance state to False (pending for persistance)
        self.persisted = False

        defer.returnValue(True)
Beispiel #2
0
    def perspective_connector_add(self, ClientConfig):
        """This will add a new connector to self.connectors
        and get a listener on submit.sm.%cid queue, this listener will be
        started and stopped when the connector will get started and stopped
        through this API"""

        c = pickle.loads(ClientConfig)

        self.log.debug('Adding a new connector %s', c.id)

        if self.getConnector(c.id) is not None:
            self.log.error(
                'Trying to add a new connector with an already existant cid: %s',
                c.id)
            defer.returnValue(False)
        if self.amqpBroker is None:
            self.log.error('AMQP Broker is not added')
            defer.returnValue(False)
        if self.amqpBroker.connected == False:
            self.log.error('AMQP Broker channel is not yet ready')
            defer.returnValue(False)

        # Declare queues
        # First declare the messaging exchange (has no effect if its already declared)
        yield self.amqpBroker.chan.exchange_declare(exchange='messaging',
                                                    type='topic',
                                                    durable='true',
                                                    arguments=arguments)
        # submit.sm queue declaration and binding
        submit_sm_queue = 'submit.sm.%s' % c.id
        routing_key = 'submit.sm.%s' % c.id
        self.log.info('Binding %s queue to %s route_key', submit_sm_queue,
                      routing_key)
        yield self.amqpBroker.named_queue_declare(queue=submit_sm_queue,
                                                  durable='true',
                                                  arguments=arguments)
        yield self.amqpBroker.chan.queue_bind(queue=submit_sm_queue,
                                              exchange="messaging",
                                              routing_key=routing_key)

        # Instanciate smpp client service manager
        serviceManager = SMPPClientService(c, self.config)

        # Instanciate a SM listener
        smListener = SMPPClientSMListener(
            config=SMPPClientSMListenerConfig(self.config.config_file),
            SMPPClientFactory=serviceManager.SMPPClientFactory,
            amqpBroker=self.amqpBroker,
            redisClient=self.redisClient,
            RouterPB=self.RouterPB,
            interceptorpb_client=self.interceptorpb_client)

        # Deliver_sm are sent to smListener's deliver_sm callback method
        serviceManager.SMPPClientFactory.msgHandler = smListener.deliver_sm_event_interceptor

        self.connectors.append({
            'id': c.id,
            'config': c,
            'service': serviceManager,
            'consumer_tag': None,
            'submit_sm_q': None,
            'sm_listener': smListener
        })

        self.log.info('Added a new connector: %s', c.id)

        # Set persistance state to False (pending for persistance)
        self.persisted = False

        defer.returnValue(True)