Пример #1
0
    def eBindBlockingListener(self, sQueueName, lBindingKeys=None):
        """
        """
        if self.oListenerChannel is None:
            if lBindingKeys is None:
                lBindingKeys = ['#']
            self.oCreateConnection()
            oChannel = self.oConnection.channel()

            oChannel.exchange_declare(exchange=self.sExchangeName,
                                      passive=False,
                                      # auto_delete=True,
                                      type='topic')
            # oResult = oChannel.queue_declare(exclusive=True)
            # self.oListenerQueueName = oResult.method.queue
            # I don't think we want exclusive here:
            # we could have more than one listener,
            # and we could have one listening for retvals...
            oResult = oChannel.queue_declare(queue=sQueueName,
                                             exclusive=False)
            self.oListenerQueueName = sQueueName
            for sBindingKey in lBindingKeys:
                oChannel.queue_bind(exchange=self.sExchangeName,
                                    queue=sQueueName,
                                    routing_key=sBindingKey,
                                    )
            time.sleep(0.1)
            self.oListenerChannel = oChannel
            vDebug("Bound listener channel " +str(id(oChannel)))
Пример #2
0
    def eBindBlockingListener(self, sQueueName, lBindingKeys=None):
        """
        """
        if self.oListenerChannel is None:
            if lBindingKeys is None:
                lBindingKeys = ['#']
            self.oCreateConnection()
            oChannel = self.oConnection.channel()

            oChannel.exchange_declare(
                exchange=self.sExchangeName,
                passive=False,
                # auto_delete=True,
                type='topic')
            # oResult = oChannel.queue_declare(exclusive=True)
            # self.oListenerQueueName = oResult.method.queue
            # I don't think we want exclusive here:
            # we could have more than one listener,
            # and we could have one listening for retvals...
            oResult = oChannel.queue_declare(queue=sQueueName, exclusive=False)
            self.oListenerQueueName = sQueueName
            for sBindingKey in lBindingKeys:
                oChannel.queue_bind(
                    exchange=self.sExchangeName,
                    queue=sQueueName,
                    routing_key=sBindingKey,
                )
            time.sleep(0.1)
            self.oListenerChannel = oChannel
            vDebug("Bound listener channel " + str(id(oChannel)))
Пример #3
0
    def oCreateConnection(self):
        import pika
        global oCONNECTION
        if not self.oConnection:
            try:
                oConnection = pika.BlockingConnection(self.oParameters)
                assert oConnection, "oCreateConnection: no oConnection created"
                self.oConnection = oConnection
                oCONNECTION = oConnection
                vDebug("Created connection " +str(id(oConnection)))
            except Exception as e:
                #     raise exceptions.ProbableAuthenticationError
                oLOG.exception("Error in oCreateConnection " + str(e))
                raise

        return self.oConnection
Пример #4
0
    def oCreateConnection(self):
        import pika
        global oCONNECTION
        if not self.oConnection:
            try:
                oConnection = pika.BlockingConnection(self.oParameters)
                assert oConnection, "oCreateConnection: no oConnection created"
                self.oConnection = oConnection
                oCONNECTION = oConnection
                vDebug("Created connection " + str(id(oConnection)))
            except Exception as e:
                #     raise exceptions.ProbableAuthenticationError
                oLOG.exception("Error in oCreateConnection " + str(e))
                raise

        return self.oConnection
Пример #5
0
    def eBindBlockingSpeaker(self):
        """
        We are going to use our Speaker channel as a broadcast
        channel for ticks, so we will set it up as a "topic".
        """
        if self.oSpeakerChannel is None:
            self.oCreateConnection()
            oChannel = self.oConnection.channel()

            oChannel.exchange_declare(exchange=self.sExchangeName,
                                      passive=False,
                                      # auto_delete=True,
                                      type='topic')

            time.sleep(0.1)
            self.oSpeakerChannel = oChannel
            vDebug("Bound speaker channel " +str(id(oChannel)))
Пример #6
0
    def eBindBlockingSpeaker(self):
        """
        We are going to use our Speaker channel as a broadcast
        channel for ticks, so we will set it up as a "topic".
        """
        if self.oSpeakerChannel is None:
            self.oCreateConnection()
            oChannel = self.oConnection.channel()

            oChannel.exchange_declare(
                exchange=self.sExchangeName,
                passive=False,
                # auto_delete=True,
                type='topic')

            time.sleep(0.1)
            self.oSpeakerChannel = oChannel
            vDebug("Bound speaker channel " + str(id(oChannel)))
Пример #7
0
    def sPushToPending(self, sMark, sRequest, sType, oOptions):
        """
        We push our requests onto a queue because some of them will be
        answered immediately (exec) and some of them will have the answer
        come back on a retval topic in the subcription.
        """
        global dPENDING

        dPENDING[sMark] = sRequest
        #
        #
        sRequest = sType +"|" +oOptions.sChartId +"|" +"0" +"|" +sMark +"|" +sRequest
        # , zmq.NOBLOCK
        self.oReqRepSocket.send(sRequest)
        i = 1
        if oOptions and oOptions.iDebugLevel >= 1:
            iLen = len(sRequest)
            vDebug("%d Sent request of length %d: %s" % (i, iLen, sRequest))
        return ""
Пример #8
0
    def eSendOnSpeaker(self, sType, sMess):
        if sType not in lKNOWN_TOPICS:
            sRetval = "eSendOnSpeaker: oSpeakerChannel unhandled topic " +sMess
            vError(sRetval)
            return sRetval
        if self.oSpeakerChannel is None:
            self.eBindBlockingSpeaker()

        assert self.oSpeakerChannel, "eSendOnSpeaker: oSpeakerChannel is null"
        assert self.oConnection, "eSendOnSpeaker: oConnection is null"

        # we will break the sChartId up into dots from the underscores
        # That way the end consumer can look at the feed selectively
        sPublishingKey = sType + '.' + self.sChartId.replace('_', '.')

        self.oSpeakerChannel.basic_publish(exchange=self.sExchangeName,
                                           routing_key=sPublishingKey,
                                           body=sMess,
                                           mandatory=False, immediate=False,
                                           properties=self.oProperties)
        vDebug("eSendOnSpeaker: sent " + sMess)
        return ""
Пример #9
0
    def eSendOnSpeaker(self, sType, sMess):
        if sType not in lKNOWN_TOPICS:
            sRetval = "eSendOnSpeaker: oSpeakerChannel unhandled topic " + sMess
            vError(sRetval)
            return sRetval
        if self.oSpeakerChannel is None:
            self.eBindBlockingSpeaker()

        assert self.oSpeakerChannel, "eSendOnSpeaker: oSpeakerChannel is null"
        assert self.oConnection, "eSendOnSpeaker: oConnection is null"

        # we will break the sChartId up into dots from the underscores
        # That way the end consumer can look at the feed selectively
        sPublishingKey = sType + '.' + self.sChartId.replace('_', '.')

        self.oSpeakerChannel.basic_publish(exchange=self.sExchangeName,
                                           routing_key=sPublishingKey,
                                           body=sMess,
                                           mandatory=False,
                                           immediate=False,
                                           properties=self.oProperties)
        vDebug("eSendOnSpeaker: sent " + sMess)
        return ""