本文整理汇总了Python中stomp.utils.merge_headers函数的典型用法代码示例。如果您正苦于以下问题:Python merge_headers函数的具体用法?Python merge_headers怎么用?Python merge_headers使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了merge_headers函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: begin
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
示例2: subscribe
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)
示例3: unsubscribe
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)
示例4: unsubscribe
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)
示例5: send
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)
示例6: abort
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)
示例7: disconnect
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)
示例8: subscribe
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)
示例9: begin
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
示例10: connect
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()
示例11: disconnect
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)
示例12: send
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)
示例13: send
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)
示例14: disconnect
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)
示例15: commit
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)