当前位置: 首页>>代码示例>>Python>>正文


Python Stomp.send方法代码示例

本文整理汇总了Python中stompest.sync.Stomp.send方法的典型用法代码示例。如果您正苦于以下问题:Python Stomp.send方法的具体用法?Python Stomp.send怎么用?Python Stomp.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stompest.sync.Stomp的用法示例。


在下文中一共展示了Stomp.send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: call_route

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import send [as 别名]
def call_route(request_queue, response_queue, request):
    """
    """
    config = {
        "stomp": {
            "server": '192.168.0.3',
            "port": 61613,
            "timeout": 15,
        }
    }

    stomp_config = StompConfig("tcp://%s:%d" % (config['stomp']['server'], config['stomp']['port']), version=StompSpec.VERSION_1_0)
    stomp = Stomp(stomp_config)
    stomp.connect()
  
    jms_id = str(uuid4())
    token = stomp.subscribe(response_queue, {'JMSCorrelationID': jms_id})
    stomp.send(request_queue, json.dumps(request), {'JMSCorrelationID': jms_id})

    response = None
    if stomp.canRead(config['stomp']['timeout']):
        response = stomp.receiveFrame()
    
    stomp.unsubscribe(token)
    return response
开发者ID:siwells,项目名称:sandpit,代码行数:27,代码来源:stomptest.py

示例2: _test_4_integration_stomp

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import send [as 别名]
    def _test_4_integration_stomp(self, version):
        client = Stomp(self.getConfig(version))
        try:
            client.connect(host=VIRTUALHOST, versions=[version])
        except StompProtocolError as e:
            print('Broker does not support STOMP protocol %s. Skipping this test case. [%s]' % (e, version))
            return

        client.send(self.DESTINATION, b'test message 1')
        client.send(self.DESTINATION, b'test message 2')
        self.assertFalse(client.canRead(self.TIMEOUT))
        token = client.subscribe(self.DESTINATION, {StompSpec.ID_HEADER: 4711, StompSpec.ACK_HEADER: StompSpec.ACK_CLIENT_INDIVIDUAL})
        self.assertTrue(client.canRead(self.TIMEOUT))
        client.ack(client.receiveFrame())
        self.assertTrue(client.canRead(self.TIMEOUT))
        client.ack(client.receiveFrame())
        self.assertFalse(client.canRead(self.TIMEOUT))
        client.unsubscribe(token)
        client.send(self.DESTINATION, b'test message 3', receipt='4711')
        self.assertTrue(client.canRead(self.TIMEOUT))
        self.assertEqual(client.receiveFrame(), StompFrame(StompSpec.RECEIPT, {StompSpec.RECEIPT_ID_HEADER: '4711'}))
        self.assertFalse(client.canRead(self.TIMEOUT))
        client.subscribe(self.DESTINATION, {StompSpec.ID_HEADER: 4711, StompSpec.ACK_HEADER: StompSpec.ACK_CLIENT_INDIVIDUAL})
        self.assertTrue(client.canRead(self.TIMEOUT))
        client.ack(client.receiveFrame())
        self.assertFalse(client.canRead(self.TIMEOUT))
        client.disconnect(receipt='4712')
        self.assertEqual(client.receiveFrame(), StompFrame(StompSpec.RECEIPT, {StompSpec.RECEIPT_ID_HEADER: '4712'}))
        self.assertRaises(StompConnectionError, client.receiveFrame)
        client.connect(host=VIRTUALHOST)
        client.disconnect(receipt='4711')
        self.assertEqual(client.receiveFrame(), StompFrame(StompSpec.RECEIPT, {StompSpec.RECEIPT_ID_HEADER: '4711'}))
        client.close()
        self.assertRaises(StompConnectionError, client.canRead, 0)
开发者ID:nikipore,项目名称:stompest,代码行数:36,代码来源:sync_client_integration_test.py

示例3: test_4_integration_stomp_1_1

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import send [as 别名]
    def test_4_integration_stomp_1_1(self):
        if StompSpec.VERSION_1_1 not in commands.versions(VERSION):
            print 'This broker does not support STOMP protocol version 1.1'
            return

        client = Stomp(self.getConfig(StompSpec.VERSION_1_1))
        client.connect(host=VIRTUALHOST)

        client.send(self.DESTINATION, 'test message 1')
        client.send(self.DESTINATION, 'test message 2')
        self.assertFalse(client.canRead(self.TIMEOUT))
        token = client.subscribe(self.DESTINATION, {StompSpec.ID_HEADER: 4711, StompSpec.ACK_HEADER: 'client-individual'})
        self.assertTrue(client.canRead(self.TIMEOUT))
        client.ack(client.receiveFrame())
        self.assertTrue(client.canRead(self.TIMEOUT))
        client.ack(client.receiveFrame())
        self.assertFalse(client.canRead(self.TIMEOUT))
        client.unsubscribe(token)
        client.send(self.DESTINATION, 'test message 3', receipt='4711')
        self.assertTrue(client.canRead(self.TIMEOUT))
        self.assertEquals(client.receiveFrame(), StompFrame(StompSpec.RECEIPT, {'receipt-id': '4711'}))
        self.assertFalse(client.canRead(self.TIMEOUT))
        client.subscribe(self.DESTINATION, {StompSpec.ID_HEADER: 4711, StompSpec.ACK_HEADER: 'client-individual'})
        self.assertTrue(client.canRead(self.TIMEOUT))
        client.ack(client.receiveFrame())
        self.assertFalse(client.canRead(self.TIMEOUT))
        client.disconnect(receipt='4712')
        self.assertEquals(client.receiveFrame(), StompFrame(StompSpec.RECEIPT, {'receipt-id': '4712'}))
        self.assertRaises(StompConnectionError, client.receiveFrame)
        client.connect(host=VIRTUALHOST)
        client.disconnect(receipt='4711')
        self.assertEquals(client.receiveFrame(), StompFrame(StompSpec.RECEIPT, {'receipt-id': '4711'}))
        client.close()
        self.assertRaises(StompConnectionError, client.canRead, 0)
开发者ID:irdetoakinavci,项目名称:AMQMessageProducer,代码行数:36,代码来源:sync_client_integration_test.py

示例4: test_6_integration_stomp_1_1_encoding_and_escaping_headers

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import send [as 别名]
    def test_6_integration_stomp_1_1_encoding_and_escaping_headers(self):
        if BROKER == 'rabbitmq':
            print('Broker does not support unicode characters. Skipping this test case.')
            return

        version = StompSpec.VERSION_1_1
        client = Stomp(self.getConfig(version))
        try:
            client.connect(host=VIRTUALHOST, versions=[version])
        except StompProtocolError as e:
            print('Broker does not support STOMP protocol %s. Skipping this test case. [%s]' % (e, version))
            return

        key = b'fen\xc3\xaatre'.decode('utf-8')
        value = b'\xc2\xbfqu\xc3\xa9 tal?'.decode('utf-8')
        headers = {key: value}
        client.send(self.DESTINATION, body=b'test message 1', headers=headers)
        self.assertFalse(client.canRead(self.TIMEOUT))
        token = client.subscribe(self.DESTINATION, {StompSpec.ID_HEADER: 4711, StompSpec.ACK_HEADER: StompSpec.ACK_CLIENT_INDIVIDUAL})
        self.assertTrue(client.canRead(self.TIMEOUT))
        frame = client.receiveFrame()
        client.ack(frame)
        self.assertEqual(frame.version, version)
        self.assertEqual(frame.headers[key], headers[key])
        self.assertFalse(client.canRead(self.TIMEOUT))
        client.unsubscribe(token)
        client.disconnect(receipt='4712')
开发者ID:nikipore,项目名称:stompest,代码行数:29,代码来源:sync_client_integration_test.py

示例5: writeJson

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import send [as 别名]
def writeJson(value,*argv):
    '''Writes the specified value to an output file
    Takes:
    value-> List or Dict
    *argv: Available options:
       'stomp'
       'post'
       'outfile'
    Returns:
    none
    '''
    outJson=json.dumps(value)
    print outJson
    if 'stomp' in argv:
        CONFIG = StompConfig(stomp_config.server, stomp_config.login,stomp_config.passcode)
        QUEUE = stomp_config.queue
        client = Stomp(CONFIG)
        client.connect()
        client.send(QUEUE, outJson)
        client.disconnect()
    elif 'outfile' in argv:
        with open(outfile,'w') as jsonFile:
            jsonFile.write(outJson)
    elif 'post' in argv:
        #TODO Post to php server
        pass
开发者ID:5inister,项目名称:onlines,代码行数:28,代码来源:controls.py

示例6: test_6_integration_stomp_1_1_encoding_and_escaping_headers

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import send [as 别名]
    def test_6_integration_stomp_1_1_encoding_and_escaping_headers(self):
        if BROKER == 'rabbitmq':
            print 'Broker does not support unicode characters. Skipping this test case.'
            return

        version = StompSpec.VERSION_1_1
        client = Stomp(self.getConfig(version))
        try:
            client.connect(host=VIRTUALHOST, versions=[version])
        except StompProtocolError as e:
            print 'Broker does not support STOMP protocol %s. Skipping this test case. [%s]' % (e, version)
            return

        specialCharactersHeader = u'fen\xeatre:\r\n'
        headers = {specialCharactersHeader: u'\xbfqu\xe9 tal?, s\xfc\xdf'}
        client.send(self.DESTINATION, body='test message 1', headers=headers)
        self.assertFalse(client.canRead(self.TIMEOUT))
        token = client.subscribe(self.DESTINATION, {StompSpec.ID_HEADER: 4711, StompSpec.ACK_HEADER: StompSpec.ACK_CLIENT_INDIVIDUAL})
        self.assertTrue(client.canRead(self.TIMEOUT))
        frame = client.receiveFrame()
        client.ack(frame)
        self.assertEquals(frame.version, version)
        self.assertEquals(frame.headers[specialCharactersHeader], headers[specialCharactersHeader])
        self.assertFalse(client.canRead(self.TIMEOUT))
        client.unsubscribe(token)
        client.disconnect(receipt='4712')
开发者ID:anthony-cervantes,项目名称:stompest,代码行数:28,代码来源:sync_client_integration_test.py

示例7: main

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import send [as 别名]
def main():
    logging.basicConfig()
    logging.getLogger().setLevel(logging.WARN)

    client = Stomp(stomp_config)
    client.connect()
    client.send(stomp_queue, body=stomp_body)
    client.subscribe(stomp_queue, {StompSpec.ACK_HEADER: StompSpec.ACK_CLIENT, 'activemq.prefetchSize': 1})
    if client.canRead(timeout=5):
        frame = client.receiveFrame()
        print 'Got %s' % frame.info()
        client.ack(frame)
        frame_body = str(frame.body)
        if frame_body == stomp_body:
            print "OK: Message received"
            status = 'ok'
        else:
            print "WARNING: Incorrect message body; is %s, should be %s" % (frame_body, stomp_body)
            status = 'warning'
    else:
        print "CRITICAL: Timed out while trying to collect the message"
        status = 'critical'
    client.disconnect()
    client.close(flush=True)
    return exit_codes[status]
开发者ID:soalhn,项目名称:icinga-plugins-soal,代码行数:27,代码来源:check_activemq.py

示例8: test_1_integration

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import send [as 别名]
    def test_1_integration(self):
        config = self.getConfig(StompSpec.VERSION_1_0)
        client = Stomp(config)
        client.connect(host=VIRTUALHOST)

        client.send(self.DESTINATION, b'test message 1')
        client.send(self.DESTINATION, b'test message 2')
        self.assertFalse(client.canRead(self.TIMEOUT))
        client.subscribe(self.DESTINATION, {StompSpec.ACK_HEADER: StompSpec.ACK_CLIENT_INDIVIDUAL})
        self.assertTrue(client.canRead(self.TIMEOUT))
        client.ack(client.receiveFrame())
        self.assertTrue(client.canRead(self.TIMEOUT))
        client.ack(client.receiveFrame())
        self.assertFalse(client.canRead(self.TIMEOUT))
开发者ID:nikipore,项目名称:stompest,代码行数:16,代码来源:sync_client_integration_test.py

示例9: run

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import send [as 别名]
 def run(self):
     files = os.listdir(self.path)
     for queue_file in files:
         archive_file = '{0}/archive/{1}'.format(self.path, queue_file)
         if queue_file.startswith('archive'):
             pass
         else:
             with open("{0}/{1}".format(self.path, queue_file), 'r') as qf:
                 get_lines = list(qf)
                 for line in get_lines:
                     dts = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
                     client = Stomp(config=self.config)
                     client.connect()
                     print "Sending message {0} to queue {1}".format(line, queue_file)
                     with open(archive_file, 'a') as af:
                         af.write("{0} Sent message: {1} to queue {2}\n".format(dts, line, queue_file))
                     client.send(queue_file, json.dumps(line))
                     client.disconnect()
开发者ID:saxrussell,项目名称:activemq_tools,代码行数:20,代码来源:doomsday_recovery.py

示例10: test_3_socket_failure_and_replay

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import send [as 别名]
 def test_3_socket_failure_and_replay(self):
     client = Stomp(self.getConfig(StompSpec.VERSION_1_0))
     client.connect(host=VIRTUALHOST)
     headers = {StompSpec.ACK_HEADER: StompSpec.ACK_CLIENT_INDIVIDUAL}
     token = client.subscribe(self.DESTINATION, headers)
     client.sendFrame(StompFrame(StompSpec.DISCONNECT)) # DISCONNECT frame is out-of-band, as far as the session is concerned -> unexpected disconnect
     self.assertRaises(StompConnectionError, client.receiveFrame)
     client.connect(host=VIRTUALHOST)
     client.send(self.DESTINATION, b'test message 1')
     client.ack(client.receiveFrame())
     client.unsubscribe(token)
     headers = {StompSpec.ID_HEADER: 'bla', StompSpec.ACK_HEADER: StompSpec.ACK_CLIENT_INDIVIDUAL}
     client.subscribe(self.DESTINATION, headers)
     headers[StompSpec.DESTINATION_HEADER] = self.DESTINATION
     client.sendFrame(StompFrame(StompSpec.DISCONNECT)) # DISCONNECT frame is out-of-band, as far as the session is concerned -> unexpected disconnect
     self.assertRaises(StompConnectionError, client.receiveFrame)
     client.connect(host=VIRTUALHOST)
     client.send(self.DESTINATION, b'test message 2')
     client.ack(client.receiveFrame())
     client.unsubscribe((StompSpec.ID_HEADER, 'bla'))
     client.disconnect()
开发者ID:nikipore,项目名称:stompest,代码行数:23,代码来源:sync_client_integration_test.py

示例11: send_message

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import send [as 别名]
def send_message(messageBody, destination=None, queueName=None):
    
    client = None
    if destination != None:
        client = Stomp(StompConfig(destination))
    else:
        client = Stomp(StompConfig("tcp://localhost:61613"))
    
    QUEUE = None
    if queueName != None:
        QUEUE = queueName
    else:
        QUEUE = "pods2jbpm"
        
    #client = Stomp(CONFIG)
    client.connect()
    
    body = messageBody
    
    client.send(QUEUE, body)
    
    client.disconnect()
开发者ID:irdetoakinavci,项目名称:AMQMessageProducer,代码行数:24,代码来源:messageProducer.py

示例12: test_2_transaction

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import send [as 别名]
    def test_2_transaction(self):
        config = self.getConfig(StompSpec.VERSION_1_0)
        client = Stomp(config)
        client.connect(host=VIRTUALHOST)
        client.subscribe(self.DESTINATION, {StompSpec.ACK_HEADER: StompSpec.ACK_CLIENT_INDIVIDUAL})
        self.assertFalse(client.canRead(self.TIMEOUT))

        with client.transaction(4711) as transaction:
            self.assertEqual(transaction, '4711')
            client.send(self.DESTINATION, b'test message', {StompSpec.TRANSACTION_HEADER: transaction})
            self.assertFalse(client.canRead(0))
        self.assertTrue(client.canRead(self.TIMEOUT))
        frame = client.receiveFrame()
        self.assertEqual(frame.body, b'test message')
        client.ack(frame)

        with client.transaction(4713, receipt='4712') as transaction:
            self.assertEqual(transaction, '4713')
            self.assertEqual(client.receiveFrame(), StompFrame(StompSpec.RECEIPT, {StompSpec.RECEIPT_ID_HEADER: '4712-begin'}))
            client.send(self.DESTINATION, b'test message', {StompSpec.TRANSACTION_HEADER: transaction})
            client.send(self.DESTINATION, b'test message without transaction')
            self.assertTrue(client.canRead(self.TIMEOUT))
            frame = client.receiveFrame()
            self.assertEqual(frame.body, b'test message without transaction')
            client.ack(frame)
            self.assertFalse(client.canRead(0))
        frames = [client.receiveFrame() for _ in range(2)]
        frames = list(sorted(frames, key=lambda f: f.command))
        frame = frames[0]
        client.ack(frame)
        self.assertEqual(frame.body, b'test message')
        frame = frames[1]
        self.assertEqual(frame, StompFrame(StompSpec.RECEIPT, {StompSpec.RECEIPT_ID_HEADER: '4712-commit'}))

        try:
            with client.transaction(4714) as transaction:
                self.assertEqual(transaction, '4714')
                client.send(self.DESTINATION, b'test message', {StompSpec.TRANSACTION_HEADER: transaction})
                raise RuntimeError('poof')
        except RuntimeError as e:
            self.assertEqual(str(e), 'poof')
        else:
            raise
        self.assertFalse(client.canRead(self.TIMEOUT))

        client.disconnect()
开发者ID:nikipore,项目名称:stompest,代码行数:48,代码来源:sync_client_integration_test.py

示例13: send

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import send [as 别名]
    def send(self):

        """
            Create a new stomp configuration client, connect and
            then serializes message by message posting
            them to your consumers in TOPIC standard
            and disconnect.
        """

        try:

            configuration = StompConfig(uri=self._broker_uri)
            client = Stomp(configuration)
            client.connect(connectTimeout=self._broker_timeout)

            for message in self._queue:
                serialized_message = json.dumps(message, ensure_ascii=False)
                client.send(self._queue_destination, serialized_message)

            client.disconnect()

        except Exception, e:
            self.log.error(u"QueueManagerError - Error on sending objects from queue.")
            self.log.debug(e)
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:26,代码来源:queue_manager.py

示例14: StompConfig

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import send [as 别名]
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)

from stompest.config import StompConfig
from stompest.sync import Stomp

CONFIG = StompConfig('tcp://localhost:7777', version='1.2')

if __name__ == '__main__':
    client = Stomp(CONFIG)
    client.connect(connectedTimeout=4)

    ID = 'bingo'

    client.send('/my/test/destination',       # destination 
                'THIS-IS-A-SEND-BODY',        # body
                headers={'receipt': ID})      # headers

    answer = client.receiveFrame()

    receiptID = answer.headers["receipt-id"] 
    returnValue = 0

    if receiptID != ID:
        print "Receipt header wrong:" + receiptID 
        returnValue = 1
    else:
        print "Correct receipt id received: " + receiptID

    client.disconnect()
    sys.exit(returnValue)
开发者ID:ms140569,项目名称:ghost,代码行数:33,代码来源:receipt.py

示例15: JMSClient

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import send [as 别名]

#.........这里部分代码省略.........

    def disconnect(self):
        """Method disconnects from server 

        Args:   
           none       

        Returns:
           bool: result

        """

        try:

            self._mh.demsg('htk_on_debug_info', self._mh._trn.msg(
                'htk_jms_disconnecting'), self._mh.fromhere())

            if (not self._is_connected):
                self._mh.demsg('htk_on_warning', self._mh._trn.msg(
                    'htk_jms_not_connected'), self._mh.fromhere())
                return False
            else:
                self._client.disconnect()
                self._client.close()
                self._is_connected = False
                self._mh.demsg('htk_on_debug_info', self._mh._trn.msg(
                    'htk_jms_disconnected'), self._mh.fromhere())
                return True

        except StompError as ex:
            self._mh.demsg('htk_on_error', ex, self._mh.fromhere())
            return False

    def send(self, destination_name, message, destination_type='queue', headers={}):
        """Method sends message

        JMS headers - JMSCorrelationID, JMSExpiration, JMSDeliveryMode, JMSPriority,
                      JMSReplyTo, JMSType

        Args:
           destination_name (str): queue|topic name
           message (str): message
           destination_type (str): queue|topic
           headers (dict): JMS headers, key - title, value - string

        Returns:
           bool: result

        Raises:
           event: jms_before_send
           event: jms_after_send             

        """

        try:

            msg = 'destination_name:{0}, message:{1}, destination_type:{2}, headers:{3}'.format(
                destination_name, message, destination_type, headers)
            self._mh.demsg('htk_on_debug_info', self._mh._trn.msg(
                'htk_jms_sending_msg', msg), self._mh.fromhere())

            if (not self._is_connected):
                self._mh.demsg('htk_on_warning', self._mh._trn.msg(
                    'htk_jms_not_connected'), self._mh.fromhere())
                return False
开发者ID:hydratk,项目名称:hydratk-lib-network,代码行数:69,代码来源:stomp_client.py


注:本文中的stompest.sync.Stomp.send方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。