Esempio n. 1
0
    def connect(self, username=None, passcode=None, wait=False, headers={}, **keyword_headers):
        """
        Start a connection.

        :param username: the username to connect with
        :param passcode: the password used to authenticate with
        :param wait: if True, wait for the connection to be established/acknowledged
        :param headers: a map of any additional headers the broker requires
        :param keyword_headers: any additional headers the broker requires
        """
        cmd = CMD_CONNECT
        headers = utils.merge_headers([headers, keyword_headers])
        headers[HDR_ACCEPT_VERSION] = self.version

        if username is not None:
            headers[HDR_LOGIN] = username

        if passcode is not None:
            headers[HDR_PASSCODE] = passcode

        self.send_frame(cmd, headers)

        if wait:
            self.transport.wait_for_connection()
            if self.transport.connection_error:
                raise ConnectFailedException()
Esempio n. 2
0
    def connect(self,
                username=None,
                passcode=None,
                wait=False,
                headers={},
                **keyword_headers):
        cmd = CMD_STOMP
        headers = utils.merge_headers([headers, keyword_headers])
        headers[HDR_ACCEPT_VERSION] = self.version

        if self.transport.vhost:
            headers[HDR_HOST] = self.transport.vhost

        if username is not None:
            headers[HDR_LOGIN] = username

        if passcode is not None:
            headers[HDR_PASSCODE] = passcode

        self.send_frame(cmd, headers)

        if wait:
            self.transport.wait_for_connection()
            if self.transport.connection_error:
                raise ConnectFailedException()
Esempio n. 3
0
    def send(self,
             destination,
             body,
             content_type=None,
             headers=None,
             **keyword_headers):
        """
        Send a message to a destination in the messaging system (as per https://stomp.github.io/stomp-specification-1.2.html#SEND)

        :param str destination: the destination (such as a message queue - for example '/queue/test' - or a message topic)
        :param body: the content of the message
        :param str content_type: the MIME type of message
        :param dict headers: additional headers to send in the message frame
        :param keyword_headers: any additional headers the broker requires
        """
        assert destination is not None, "'destination' is required"
        assert body is not None, "'body' is required"
        headers = utils.merge_headers([headers, keyword_headers])
        headers[HDR_DESTINATION] = destination
        if content_type:
            headers[HDR_CONTENT_TYPE] = content_type
        body = encode(body)
        if self.auto_content_length and body and HDR_CONTENT_LENGTH not in headers:
            headers[HDR_CONTENT_LENGTH] = len(body)
        self.send_frame(CMD_SEND, headers, body)
Esempio n. 4
0
    def connect(self,
                username=None,
                passcode=None,
                wait=False,
                headers={},
                **keyword_headers):
        """
        Send a STOMP CONNECT frame. Differs from 1.0 and 1.1 versions in that the HOST header is enforced.
        \param username
            optionally specify the login user
        \param passcode
            optionally specify the user password
        \param wait
            wait for the connection to complete before returning
        """
        cmd = CMD_STOMP
        headers = utils.merge_headers([headers, keyword_headers])
        headers[HDR_ACCEPT_VERSION] = self.version
        headers[HDR_HOST] = self.transport.current_host_and_port[0]

        if self.transport.vhost:
            headers[HDR_HOST] = self.transport.vhost

        if username is not None:
            headers[HDR_LOGIN] = username

        if passcode is not None:
            headers[HDR_PASSCODE] = passcode

        self.send_frame(cmd, headers)

        if wait:
            self.transport.wait_for_connection()
            if self.transport.connection_error:
                raise ConnectFailedException()
Esempio n. 5
0
    def send(self,
             destination,
             body,
             content_type=None,
             headers=None,
             **keyword_headers):
        """
        Send a message to a destination.

        :param str destination: the destination of the message (e.g. queue or topic name)
        :param body: the content of the message
        :param str content_type: the content type of the message
        :param dict headers: a map of any additional headers the broker requires
        :param keyword_headers: any additional headers the broker requires
        """
        assert destination is not None, "'destination' is required"
        assert body is not None, "'body' is required"
        headers = utils.merge_headers([headers, keyword_headers])
        headers[HDR_DESTINATION] = destination
        if content_type:
            headers[HDR_CONTENT_TYPE] = content_type
        body = encode(body)
        if self.auto_content_length and body and HDR_CONTENT_LENGTH not in headers:
            headers[HDR_CONTENT_LENGTH] = len(body)
        self.send_frame(CMD_SEND, headers, body)
Esempio n. 6
0
 def begin(self, transaction=None, headers={}, **keyword_headers):
     headers = utils.merge_headers([headers, keyword_headers])
     if not transaction:
         transaction = str(uuid.uuid4())
     headers[HDR_TRANSACTION] = transaction
     self.send_frame(CMD_BEGIN, headers)
     return transaction
Esempio n. 7
0
    def connect(self, username=None, passcode=None, wait=False, headers=None, **keyword_headers):
        """
        Send a STOMP CONNECT frame. Differs from 1.0 and 1.1 versions in that the HOST header is enforced.

        :param str username: optionally specify the login user
        :param str passcode: optionally specify the user password
        :param bool wait: wait for the connection to complete before returning
        :param dict headers: a map of any additional headers to send with the subscription
        :param keyword_headers: any additional headers to send with the subscription
        """
        cmd = CMD_STOMP
        headers = utils.merge_headers([headers, keyword_headers])
        headers[HDR_ACCEPT_VERSION] = self.version
        headers[HDR_HOST] = self.transport.current_host_and_port[0]

        if self.transport.vhost:
            headers[HDR_HOST] = self.transport.vhost

        if username is not None:
            headers[HDR_LOGIN] = username

        if passcode is not None:
            headers[HDR_PASSCODE] = passcode

        self.send_frame(cmd, headers)

        if wait:
            self.transport.wait_for_connection()
            if self.transport.connection_error:
                raise ConnectFailedException()
Esempio n. 8
0
 def begin(self, transaction=None, headers={}, **keyword_headers):
     headers = utils.merge_headers([headers, keyword_headers])
     if not transaction:
         transaction = str(uuid.uuid4())
     headers[HDR_TRANSACTION] = transaction
     self.send_frame(CMD_BEGIN, headers)
     return transaction
Esempio n. 9
0
    def connect(self, username=None, passcode=None, wait=False, headers=None, **keyword_headers):
        """
        Start a connection.

        :param str username: the username to connect with
        :param str passcode: the password used to authenticate with
        :param bool wait: if True, wait for the connection to be established/acknowledged
        :param dict headers: a map of any additional headers the broker requires
        :param keyword_headers: any additional headers the broker requires
        """
        cmd = CMD_CONNECT
        headers = utils.merge_headers([headers, keyword_headers])
        headers[HDR_ACCEPT_VERSION] = self.version

        if username is not None:
            headers[HDR_LOGIN] = username

        if passcode is not None:
            headers[HDR_PASSCODE] = passcode

        self.send_frame(cmd, headers)

        if wait:
            self.transport.wait_for_connection()
            if self.transport.connection_error:
                raise ConnectFailedException()
Esempio n. 10
0
 def subscribe(self, destination, id=None, ack='auto', headers={}, **keyword_headers):
     assert destination is not None, "'destination' is required"
     headers = utils.merge_headers([headers, keyword_headers])
     headers[HDR_DESTINATION] = destination
     if id:
         headers[HDR_ID] = id
     headers[HDR_ACK] = ack
     self.send_frame(CMD_SUBSCRIBE, headers)
Esempio n. 11
0
 def unsubscribe(self, destination=None, id=None, headers={}, **keyword_headers):
     assert id is not None or destination is not None, "'id' or 'destination' is required"
     headers = utils.merge_headers([headers, keyword_headers])
     if id:
         headers[HDR_ID] = id
     if destination:
         headers[HDR_DESTINATION] = destination
     self.send_frame(CMD_UNSUBSCRIBE, headers)
Esempio n. 12
0
 def disconnect(self,
                receipt=str(uuid.uuid4()),
                headers={},
                **keyword_headers):
     headers = utils.merge_headers([headers, keyword_headers])
     if receipt:
         headers[HDR_RECEIPT] = receipt
     self.send_frame(CMD_DISCONNECT, headers)
Esempio n. 13
0
 def unsubscribe(self, id, headers={}, **keyword_headers):
     """
     Unsubscribe from a destination by its unique identifier
     
     :param id: the unique identifier to unsubscribe from
     :param headers: additional headers to send with the unsubscribe
     """
     assert id is not None, "'id' is required"
     headers = utils.merge_headers([headers, keyword_headers])
     headers[HDR_ID] = id
     self.send_frame(CMD_UNSUBSCRIBE, headers)
Esempio n. 14
0
 def unsubscribe(self, id, headers={}, **keyword_headers):
     """
     Unsubscribe from a destination by its unique identifier
     
     :param id: the unique identifier to unsubscribe from
     :param headers: additional headers to send with the unsubscribe
     """
     assert id is not None, "'id' is required"
     headers = utils.merge_headers([headers, keyword_headers])
     headers[HDR_ID] = id
     self.send_frame(CMD_UNSUBSCRIBE, headers)
Esempio n. 15
0
 def send(self, destination, body, content_type=None, headers={}, **keyword_headers):
     assert destination is not None, "'destination' is required"
     assert body is not None, "'body' is required"
     headers = utils.merge_headers([headers, keyword_headers])
     headers[HDR_DESTINATION] = destination
     if content_type:
         headers[HDR_CONTENT_TYPE] = content_type
     body = encode(body)
     #if HDR_CONTENT_LENGTH not in headers:
     #    headers[HDR_CONTENT_LENGTH] = len(body)
     self.send_frame(CMD_SEND, headers, body)
Esempio n. 16
0
    def abort(self, transaction, headers=None, **keyword_headers):
        """
        Abort a transaction.

        :param str transaction: the identifier of the transaction
        :param dict headers: a map of any additional headers the broker requires
        :param keyword_headers: any additional headers the broker requires
        """
        assert transaction is not None, "'transaction' is required"
        headers = utils.merge_headers([headers, keyword_headers])
        headers[HDR_TRANSACTION] = transaction
        self.send_frame(CMD_ABORT, headers)
Esempio n. 17
0
 def unsubscribe(self,
                 destination=None,
                 id=None,
                 headers={},
                 **keyword_headers):
     assert id is not None or destination is not None, "'id' or 'destination' is required"
     headers = utils.merge_headers([headers, keyword_headers])
     if id:
         headers[HDR_ID] = id
     if destination:
         headers[HDR_DESTINATION] = destination
     self.send_frame(CMD_UNSUBSCRIBE, headers)
    def abort(self, transaction, headers={}, **keyword_headers):
        """
        Abort a transaction.

        :param transaction: the identifier of the transaction
        :param headers: a map of any additional headers the broker requires
        :param keyword_headers: any additional headers the broker requires
        """
        assert transaction is not None, "'transaction' is required"
        headers = utils.merge_headers([headers, keyword_headers])
        headers[HDR_TRANSACTION] = transaction
        self.send_frame(CMD_ABORT, headers)
Esempio n. 19
0
    def commit(self, transaction=None, headers=None, **keyword_headers):
        """
        Commit a transaction.

        :param str transaction: the identifier for the transaction
        :param dict headers: a map of any additional headers the broker requires
        :param keyword_headers: any additional headers the broker requires
        """
        assert transaction is not None, "'transaction' is required"
        headers = utils.merge_headers([headers, keyword_headers])
        headers[HDR_TRANSACTION] = transaction
        self.send_frame(CMD_COMMIT, headers)
Esempio n. 20
0
    def commit(self, transaction=None, headers={}, **keyword_headers):
        """
        Commit a transcation.

        :param transaction: the identifier for the transaction
        :param headers: a map of any additional headers the broker requires
        :param keyword_headers: any additional headers the broker requires
        """
        assert transaction is not None, "'transaction' is required"
        headers = utils.merge_headers([headers, keyword_headers])
        headers[HDR_TRANSACTION] = transaction
        self.send_frame(CMD_COMMIT, headers)
Esempio n. 21
0
 def subscribe(self,
               destination,
               id,
               ack='auto',
               headers={},
               **keyword_headers):
     assert destination is not None, "'destination' is required"
     assert id is not None, "'id' is required"
     headers = utils.merge_headers([headers, keyword_headers])
     headers[HDR_DESTINATION] = destination
     headers[HDR_ID] = id
     headers[HDR_ACK] = ack
     self.send_frame(CMD_SUBSCRIBE, headers)
Esempio n. 22
0
    def disconnect(self, receipt=str(uuid.uuid4()), headers={}, **keyword_headers):
        """
        Disconnect from the server.

        :param receipt: the receipt to use (once the server acknowledges that receipt, we're
            officially disconnected)
        :param headers: a map of any additional headers the broker requires
        :param keyword_headers: any additional headers the broker requires
        """
        headers = utils.merge_headers([headers, keyword_headers])
        if receipt:
            headers[HDR_RECEIPT] = receipt
        self.send_frame(CMD_DISCONNECT, headers)
    def disconnect(self, receipt=str(uuid.uuid4()), headers={}, **keyword_headers):
        """
        Disconnect from the server.

        :param receipt: the receipt to use (once the server acknowledges that receipt, we're
            officially disconnected)
        :param headers: a map of any additional headers the broker requires
        :param keyword_headers: any additional headers the broker requires
        """
        headers = utils.merge_headers([headers, keyword_headers])
        if receipt:
            headers[HDR_RECEIPT] = receipt
        self.send_frame(CMD_DISCONNECT, headers)
Esempio n. 24
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
        """
        headers = utils.merge_headers([headers, keyword_headers])
        headers[HDR_RECEIPT] = receipt or str(uuid.uuid4())
        self.send_frame(CMD_DISCONNECT, headers)
Esempio n. 25
0
    def disconnect(self, receipt=None, headers={}, **keyword_headers):
        """
        Disconnect from the server.

        :param 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 headers: a map of any additional headers the broker requires
        :param keyword_headers: any additional headers the broker requires
        """
        headers = utils.merge_headers([headers, keyword_headers])
        headers[HDR_RECEIPT] = receipt or str(uuid.uuid4())
        self.send_frame(CMD_DISCONNECT, headers)
Esempio n. 26
0
    def unsubscribe(self, destination=None, id=None, headers={}, **keyword_headers):
        """
        Unsubscribe from a destination by either id or the destination name.

        :param destination: the name of the topic or queue to unsubscribe from
        :param id: the unique identifier of the topic or queue to unsubscribe from
        :param headers: a map of any additional headers the broker requires
        :param keyword_headers: any additional headers the broker requires
        """
        assert id is not None or destination is not None, "'id' or 'destination' is required"
        headers = utils.merge_headers([headers, keyword_headers])
        if id:
            headers[HDR_ID] = id
        if destination:
            headers[HDR_DESTINATION] = destination
        self.send_frame(CMD_UNSUBSCRIBE, headers)
Esempio n. 27
0
    def unsubscribe(self, destination=None, id=None, headers=None, **keyword_headers):
        """
        Unsubscribe from a destination by either id or the destination name.

        :param str destination: the name of the topic or queue to unsubscribe from
        :param str id: the unique identifier of the topic or queue to unsubscribe from
        :param dict headers: a map of any additional headers the broker requires
        :param keyword_headers: any additional headers the broker requires
        """
        assert id is not None or destination is not None, "'id' or 'destination' is required"
        headers = utils.merge_headers([headers, keyword_headers])
        if id:
            headers[HDR_ID] = id
        if destination:
            headers[HDR_DESTINATION] = destination
        self.send_frame(CMD_UNSUBSCRIBE, headers)
Esempio n. 28
0
 def subscribe(self, destination, id, ack='auto', headers={}, **keyword_headers):
     """
     Subscribe to a destination
     
     :param destination: the topic or queue to subscribe to
     :param id: the identifier to uniquely identify the subscription
     :param ack: either auto, client or client-individual (see https://stomp.github.io/stomp-specification-1.2.html#SUBSCRIBE for more info)
     :param headers: any additional headers to send with the subscription
     """
     assert destination is not None, "'destination' is required"
     assert id is not None, "'id' is required"
     headers = utils.merge_headers([headers, keyword_headers])
     headers[HDR_DESTINATION] = destination
     headers[HDR_ID] = id
     headers[HDR_ACK] = ack
     self.send_frame(CMD_SUBSCRIBE, headers)
Esempio n. 29
0
 def send(self,
          destination,
          body,
          content_type=None,
          headers={},
          **keyword_headers):
     assert destination is not None, "'destination' is required"
     assert body is not None, "'body' is required"
     headers = utils.merge_headers([headers, keyword_headers])
     headers[HDR_DESTINATION] = destination
     if content_type:
         headers[HDR_CONTENT_TYPE] = content_type
     body = encode(body)
     if body and HDR_CONTENT_LENGTH not in headers:
         headers[HDR_CONTENT_LENGTH] = len(body)
     self.send_frame(CMD_SEND, headers, body)
Esempio n. 30
0
    def connect(self, username=None, passcode=None, wait=False, headers={}, **keyword_headers):
        cmd = CMD_CONNECT
        headers = utils.merge_headers([headers, keyword_headers])
        headers[HDR_ACCEPT_VERSION] = self.version

        if username is not None:
            headers[HDR_LOGIN] = username

        if passcode is not None:
            headers[HDR_PASSCODE] = passcode

        self.send_frame(cmd, headers)

        if wait:
            self.transport.wait_for_connection()
            if self.transport.connection_error:
                raise ConnectFailedException()
Esempio n. 31
0
    def nack(self, id, transaction=None, receipt=None, **keyword_headers):
        """
        Let the server know that a message was not consumed.

        :param str id: the unique id of the message to nack
        :param str transaction: include this nack in a named transaction
        :param str receipt: the receipt id
        :param keyword_headers: any additional headers to send with the nack command
        """
        assert id is not None, "'id' is required"
        headers = {HDR_ID: id}
        headers = utils.merge_headers([headers, keyword_headers])
        if transaction:
            headers[HDR_TRANSACTION] = transaction
        if receipt:
            headers[HDR_RECEIPT] = receipt
        self.send_frame(CMD_NACK, headers)
    def begin(self, transaction=None, headers={}, **keyword_headers):
        """
        Begin a transaction.

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

        :return: the transaction id
        """
        headers = utils.merge_headers([headers, keyword_headers])
        if not transaction:
            transaction = str(uuid.uuid4())
        headers[HDR_TRANSACTION] = transaction
        self.send_frame(CMD_BEGIN, headers)
        return transaction
Esempio n. 33
0
    def begin(self, transaction=None, headers={}, **keyword_headers):
        """
        Begin a transaction.

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

        :return: the transaction id
        """
        headers = utils.merge_headers([headers, keyword_headers])
        if not transaction:
            transaction = str(uuid.uuid4())
        headers[HDR_TRANSACTION] = transaction
        self.send_frame(CMD_BEGIN, headers)
        return transaction
Esempio n. 34
0
    def subscribe(self, destination, id, ack='auto', headers={}, **keyword_headers):
        """
        Subscribe to a destination

        :param destination: the topic or queue to subscribe to
        :param id: the identifier to uniquely identify the subscription
        :param ack: either auto, client or client-individual (see https://stomp.github.io/stomp-specification-1.2.html#SUBSCRIBE for more info)
        :param headers: a map of any additional headers to send with the subscription
        :param keyword_headers: any additional headers to send with the subscription
        """
        assert destination is not None, "'destination' is required"
        assert id is not None, "'id' is required"
        headers = utils.merge_headers([headers, keyword_headers])
        headers[HDR_DESTINATION] = destination
        headers[HDR_ID] = id
        headers[HDR_ACK] = ack
        self.send_frame(CMD_SUBSCRIBE, headers)
Esempio n. 35
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 str(uuid.uuid4())
        headers[HDR_RECEIPT] = rec
        self.set_receipt(rec, CMD_DISCONNECT)
        self.send_frame(CMD_DISCONNECT, headers)
Esempio n. 36
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)
Esempio n. 37
0
 def send(self, destination, body, content_type=None, headers={}, **keyword_headers):
     """
     Send a message to a destination in the messaging system (as per https://stomp.github.io/stomp-specification-1.2.html#SEND)
     
     :param destination: the destination (such as a message queue - for example '/queue/test' - or a message topic)
     :param body: the content of the message
     :param content_type: the MIME type of message 
     :param headers: additional headers to send in the message frame
     """
     assert destination is not None, "'destination' is required"
     assert body is not None, "'body' is required"
     headers = utils.merge_headers([headers, keyword_headers])
     headers[HDR_DESTINATION] = destination
     if content_type:
         headers[HDR_CONTENT_TYPE] = content_type
     body = encode(body)
     if body and HDR_CONTENT_LENGTH not in headers:
         headers[HDR_CONTENT_LENGTH] = len(body)
     self.send_frame(CMD_SEND, headers, body)
Esempio n. 38
0
    def send(self, destination, body, content_type=None, headers=None, **keyword_headers):
        """
        Send a message to a destination.

        :param str destination: the destination of the message (e.g. queue or topic name)
        :param body: the content of the message
        :param str content_type: the content type of the message
        :param dict headers: a map of any additional headers the broker requires
        :param keyword_headers: any additional headers the broker requires
        """
        assert destination is not None, "'destination' is required"
        assert body is not None, "'body' is required"
        headers = utils.merge_headers([headers, keyword_headers])
        headers[HDR_DESTINATION] = destination
        if content_type:
            headers[HDR_CONTENT_TYPE] = content_type
        if self.auto_content_length and body and HDR_CONTENT_LENGTH not in headers:
            headers[HDR_CONTENT_LENGTH] = len(body)
        self.send_frame(CMD_SEND, headers, body)
Esempio n. 39
0
    def subscribe(self, destination, id=None, ack='auto', headers={}, **keyword_headers):
        """
        Subscribe to a destination.

        :param destination: the topic or queue to subscribe to
        :param id: a unique id to represent the subscription
        :param ack: acknowledgement mode, either auto, client, or client-individual
            (see http://stomp.github.io/stomp-specification-1.2.html#SUBSCRIBE_ack_Header)
            for more information
        :param headers: a map of any additional headers the broker requires
        :param keyword_headers: any additional headers the broker requires
        """
        assert destination is not None, "'destination' is required"
        headers = utils.merge_headers([headers, keyword_headers])
        headers[HDR_DESTINATION] = destination
        if id:
            headers[HDR_ID] = id
        headers[HDR_ACK] = ack
        self.send_frame(CMD_SUBSCRIBE, headers)
Esempio n. 40
0
    def subscribe(self, destination, id=None, ack='auto', headers=None, **keyword_headers):
        """
        Subscribe to a destination.

        :param str destination: the topic or queue to subscribe to
        :param str id: a unique id to represent the subscription
        :param str ack: acknowledgement mode, either auto, client, or client-individual
            (see http://stomp.github.io/stomp-specification-1.2.html#SUBSCRIBE_ack_Header)
            for more information
        :param dict headers: a map of any additional headers the broker requires
        :param keyword_headers: any additional headers the broker requires
        """
        assert destination is not None, "'destination' is required"
        headers = utils.merge_headers([headers, keyword_headers])
        headers[HDR_DESTINATION] = destination
        if id:
            headers[HDR_ID] = id
        headers[HDR_ACK] = ack
        self.send_frame(CMD_SUBSCRIBE, headers)
Esempio n. 41
0
    def connect(self,
                username=None,
                passcode=None,
                wait=False,
                timeout=None,
                headers=None,
                **keyword_headers):
        """
        Send a STOMP CONNECT frame. Differs from 1.0 and 1.1 versions in that the HOST header is enforced.

        :param str username: optionally specify the login user
        :param str passcode: optionally specify the user password
        :param bool wait: wait for the connection to complete before returning
        :param dict headers: a map of any additional headers to send with the subscription
        :param keyword_headers: any additional headers to send with the subscription
        """
        #        cmd = CMD_STOMP
        cmd = CMD_CONNECT
        headers = utils.merge_headers([headers, keyword_headers])
        headers[HDR_ACCEPT_VERSION] = self.version
        headers[HDR_HOST] = self.transport.current_host_and_port[0]

        if self.transport.vhost:
            headers[HDR_HOST] = self.transport.vhost

        if username is not None:
            headers[HDR_LOGIN] = username

        if passcode is not None:
            headers[HDR_PASSCODE] = passcode

        self.send_frame(cmd, headers)

        if wait:
            self.transport.wait_for_connection(timeout=timeout)
            if self.transport.connection_error:
                raise ConnectFailedException()
Esempio n. 42
0
 def abort(self, transaction, headers={}, **keyword_headers):
     assert transaction is not None, "'transaction' is required"
     headers = utils.merge_headers([headers, keyword_headers])
     headers[HDR_TRANSACTION] = transaction
     self.send_frame(CMD_ABORT, headers)
Esempio n. 43
0
 def commit(self, transaction=None, headers={}, **keyword_headers):
     assert transaction is not None, "'transaction' is required"
     headers = utils.merge_headers([headers, keyword_headers])
     headers[HDR_TRANSACTION] = transaction
     self.send_frame('COMMIT', headers)
Esempio n. 44
0
 def disconnect(self, receipt=str(uuid.uuid4()), headers={}, **keyword_headers):
     headers = utils.merge_headers([headers, keyword_headers])
     if receipt:
         headers[HDR_RECEIPT] = receipt
     self.send_frame(CMD_DISCONNECT, headers)
Esempio n. 45
0
 def unsubscribe(self, id, headers={}, **keyword_headers):
     assert id is not None, "'id' is required"
     headers = utils.merge_headers([headers, keyword_headers])
     headers[HDR_ID] = id
     self.send_frame(CMD_UNSUBSCRIBE, headers)
Esempio n. 46
0
 def abort(self, transaction, headers={}, **keyword_headers):
     assert transaction is not None, "'transaction' is required"
     headers = utils.merge_headers([headers, keyword_headers])
     headers[HDR_TRANSACTION] = transaction
     self.send_frame(CMD_ABORT, headers)
Esempio n. 47
0
 def unsubscribe(self, id, headers={}, **keyword_headers):
     assert id is not None, "'id' is required"
     headers = utils.merge_headers([headers, keyword_headers])
     headers[HDR_ID] = id
     self.send_frame(CMD_UNSUBSCRIBE, headers)
Esempio n. 48
0
 def commit(self, transaction=None, headers={}, **keyword_headers):
     assert transaction is not None, "'transaction' is required"
     headers = utils.merge_headers([headers, keyword_headers])
     headers[HDR_TRANSACTION] = transaction
     self.send_frame('COMMIT', headers)