Ejemplo n.º 1
0
    def testtransactions(self):
        queuename = '/queue/test1-%s' % self.timestamp
        self.conn.subscribe(destination=queuename, id=1, ack='auto')

        trans_id = get_uuid()
        self.conn.begin(trans_id)

        self.conn.send(body='this is a test', transaction=trans_id, destination=queuename, receipt='123')

        time.sleep(1)

        self.assertTrue(self.listener.messages == 0, 'should not have received any messages')

        self.conn.commit(trans_id)

        self.listener.wait_on_receipt()

        self.assertTrue(self.listener.messages == 1, 'should have received 1 message')

        self.conn.begin(trans_id)

        self.conn.send(body='this is a test', transaction=trans_id, destination=queuename, receipt='124')

        self.conn.abort(trans_id)

        time.sleep(3)

        self.assertTrue(self.listener.messages == 1, 'should have only received 1 message')
Ejemplo n.º 2
0
    def testtransactions(self, conn):
        listener = conn.get_listener("testlistener")
        queuename = "/queue/test1-%s" % listener.timestamp
        conn.subscribe(destination=queuename, id=1, ack="auto")

        trans_id = get_uuid()
        conn.begin(trans_id)

        conn.send(body="this is a test", transaction=trans_id, destination=queuename, receipt="123")

        time.sleep(1)

        assert listener.messages == 0, "should not have received any messages"

        conn.commit(trans_id)

        listener.wait_on_receipt()

        assert listener.messages == 1, "should have received 1 message"

        conn.begin(trans_id)

        conn.send(body="this is a test", transaction=trans_id, destination=queuename, receipt="124")

        conn.abort(trans_id)

        time.sleep(3)

        assert listener.messages == 1, "should have only received 1 message"
Ejemplo n.º 3
0
 def do_sendrec(self, args):
     args = args.split()
     receipt_id = get_uuid()
     if len(args) < 2:
         self.__error('Expecting: sendrec <destination> <message>')
     elif not self.transaction_id:
         self.conn.send(args[0], ' '.join(args[1:]), receipt=receipt_id)
     else:
         self.conn.send(args[0],
                        ' '.join(args[1:]),
                        transaction=self.transaction_id,
                        receipt=receipt_id)
Ejemplo n.º 4
0
    def begin(self, transaction=None, headers=None, **keyword_headers):
        """
        Begin a transaction.

        :param str transaction: the identifier for the transaction (optional - if not specified
            a unique transaction id will be generated)
        :param dict headers: a map of any additional headers the broker requires
        :param keyword_headers: any additional headers the broker requires

        :return: the transaction id
        :rtype: str
        """
        headers = utils.merge_headers([headers, keyword_headers])
        if not transaction:
            transaction = utils.get_uuid()
        headers[HDR_TRANSACTION] = transaction
        self.send_frame(CMD_BEGIN, headers)
        return transaction
Ejemplo n.º 5
0
    def disconnect(self, receipt=None, headers=None, **keyword_headers):
        """
        Disconnect from the server.

        :param str receipt: the receipt to use (once the server acknowledges that receipt, we're
            officially disconnected; optional - if not specified a unique receipt id will
            be generated)
        :param dict headers: a map of any additional headers the broker requires
        :param keyword_headers: any additional headers the broker requires
        """
        if not self.transport.is_connected():
            logging.debug('Not sending disconnect, already disconnected')
            return
        headers = utils.merge_headers([headers, keyword_headers])
        rec = receipt or utils.get_uuid()
        headers[HDR_RECEIPT] = rec
        self.set_receipt(rec, CMD_DISCONNECT)
        self.send_frame(CMD_DISCONNECT, headers)
Ejemplo n.º 6
0
    def begin(self, transaction=None, headers=None, **keyword_headers):
        """
        Begin a transaction.

        :param str transaction: the identifier for the transaction (optional - if not specified
            a unique transaction id will be generated)
        :param dict headers: a map of any additional headers the broker requires
        :param keyword_headers: any additional headers the broker requires

        :return: the transaction id
        :rtype: str
        """
        headers = utils.merge_headers([headers, keyword_headers])
        if not transaction:
            transaction = utils.get_uuid()
        headers[HDR_TRANSACTION] = transaction
        self.send_frame(CMD_BEGIN, headers)
        return transaction
Ejemplo n.º 7
0
    def disconnect(self, receipt=None, headers=None, **keyword_headers):
        """
        Disconnect from the server.

        :param str receipt: the receipt to use (once the server acknowledges that receipt, we're
            officially disconnected; optional - if not specified a unique receipt id will
            be generated)
        :param dict headers: a map of any additional headers the broker requires
        :param keyword_headers: any additional headers the broker requires
        """
        if not self.transport.is_connected():
            log.debug('Not sending disconnect, already disconnected')
            return
        headers = utils.merge_headers([headers, keyword_headers])
        rec = receipt or utils.get_uuid()
        headers[HDR_RECEIPT] = rec
        self.set_receipt(rec, CMD_DISCONNECT)
        self.send_frame(CMD_DISCONNECT, headers)
Ejemplo n.º 8
0
 def __enter__(self):
     self.disconnect_receipt_id = get_uuid()
     self.disconnect_listener = WaitingListener(self.disconnect_receipt_id)
     self.set_listener("ZZZZZ-disconnect-listener",
                       self.disconnect_listener)
     return self
Ejemplo n.º 9
0
 def __enter__(self):
     self.disconnect_receipt_id = get_uuid()
     self.disconnect_listener = WaitingListener(self.disconnect_receipt_id)
     self.set_listener('ZZZZZ-disconnect-listener', self.disconnect_listener)
     return self