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


Python Stomp.disconnect方法代码示例

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


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

示例1: _test_4_integration_stomp

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import disconnect [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

示例2: main

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import disconnect [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

示例3: test_6_integration_stomp_1_1_encoding_and_escaping_headers

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import disconnect [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

示例4: test_6_integration_stomp_1_1_encoding_and_escaping_headers

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import disconnect [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

示例5: test_4_integration_stomp_1_1

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import disconnect [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

示例6: main

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import disconnect [as 别名]
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-d", nargs=1, required=True, help="destination", metavar="dest")
    parser.add_argument("-e", action="store_true", default=False, help="persistent msgs flag")
    parser.add_argument("-m", nargs=1, required=True, help="msg", metavar="msg")
    parser.add_argument("-n", nargs=1, default=False, help="number of msgs", metavar="int")
    parser.add_argument("-p", nargs=1, default=False, help="msg prefix", metavar="msg prefix")
    parser.add_argument("-s", nargs=1, required=True, help="broker", metavar="broker")
    parser.add_argument("-t", nargs=1, default=False, help="send msg every sec", metavar="float")
    args = parser.parse_args()

    broker = "tcp://%s:6163" % (args.s[0])
    config = StompConfig(broker)
    client = Stomp(config)
    client.connect()

    rd = "".join(random.sample("abcdefghijklmno", 2))

    try:
        i = 0
        if args.n:
            while i < int(args.n[0]):
                send_msg(args, client, i, rd)
                i += 1
        else:
            while True:
                send_msg(args, client, i, rd)
                i += 1
    except KeyboardInterrupt:
        client.disconnect()
        raise SystemExit(1)
开发者ID:vrdel,项目名称:brokers-test,代码行数:33,代码来源:producer.py

示例7: writeJson

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import disconnect [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

示例8: recv_stomp

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import disconnect [as 别名]
def recv_stomp ():
    config = StompConfig (stomp_uri)
    client = Stomp (config)
    client.connect ()
    client.subscribe (stomp_source, {StompSpec.ACK_HEADER: StompSpec.ACK_CLIENT_INDIVIDUAL})
    frame = client.receiveFrame ()
    print "Received: {}".format (frame.info ())
    client.ack (frame)
    client.disconnect ()
开发者ID:jpbarto,项目名称:stomp_eval,代码行数:11,代码来源:stompest-test.py

示例9: main

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import disconnect [as 别名]
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-a', action='store_true', default=False, help='client ack')
    parser.add_argument('-b', action='store_true', default=False, help='write body only')
    parser.add_argument('-d', nargs=1, required=True, help='destination', metavar='dest')
    parser.add_argument('-f', nargs=1, required=True, help='file with recorded msgs', metavar='file')
    parser.add_argument('-n', nargs=1, default=False, help='number of msgs', metavar='int')
    parser.add_argument('-r', action='store_true', default=False, help='reconnect')
    parser.add_argument('-s', nargs=1, required=True, help='broker', metavar='broker')
    parser.add_argument('-t', nargs=1, default=False, help='recv msg every sec', metavar='float')
    args = parser.parse_args()

    broker = 'tcp://%s:6163' % (args.s[0])
    config = StompConfig(broker)

    client = Stomp(config)
    if not args.r:
        client.connect()
        if args.a:
            client.subscribe(args.d[0], {StompSpec.ACK_HEADER: StompSpec.ACK_CLIENT_INDIVIDUAL})
        else:
            client.subscribe(args.d[0], {StompSpec.ACK_HEADER: StompSpec.ACK_AUTO})
    try:
        consumed = 0
        while True:
            if args.r:
                client.connect()
                if args.a:
                    client.subscribe(args.d[0], {StompSpec.ACK_HEADER: StompSpec.ACK_CLIENT_INDIVIDUAL})
                else:
                    client.subscribe(args.d[0], {StompSpec.ACK_HEADER: StompSpec.ACK_AUTO})
            if args.t:
                time.sleep(float(args.t[0]))
            else:
                time.sleep(1)
            fo = open(args.f[0], 'a+')
            frame = client.receiveFrame()
            consumed += 1
            if args.b:
                fo.write(frame.body+'\n')
            else:
                fo.write(frame.info()+'\n')
            fo.close()
            if args.a:
                client.ack(frame)
            if args.r:
                client.disconnect()
            if args.n:
                if consumed == int(args.n[0]):
                    raise KeyboardInterrupt
    except KeyboardInterrupt:
        client.stop()
        client.disconnect()
        raise SystemExit(1)
    except stompest.error.StompProtocolError:
        pass
开发者ID:vrdel,项目名称:brokers-test,代码行数:58,代码来源:consumer.py

示例10: setUp

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import disconnect [as 别名]
 def setUp(self):
     config = self.getConfig(StompSpec.VERSION_1_0)
     client = Stomp(config)
     client.connect(host=VIRTUALHOST)
     client.subscribe(self.DESTINATION, {StompSpec.ACK_HEADER: StompSpec.ACK_AUTO})
     client.subscribe(self.DESTINATION, {StompSpec.ID_HEADER: 'bla', StompSpec.ACK_HEADER: StompSpec.ACK_AUTO})
     while client.canRead(self.TIMEOUT):
         frame = client.receiveFrame()
         self.log.debug('Dequeued old %s' % frame.info())
     client.disconnect()
开发者ID:nikipore,项目名称:stompest,代码行数:12,代码来源:sync_client_integration_test.py

示例11: main

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import disconnect [as 别名]
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('config_file')
    parser.add_argument('--debug', action='store_true')
    parser.add_argument('--logfile')
    parser.add_argument('--purge', action='store_true')
    parser.add_argument('--loadgen', action='store_true')
    parser.add_argument('--sessionid')
    parser.add_argument('--httpserver', action='store_true')
    args = parser.parse_args()

    if args.logfile:
        fh = FileHandler(args.logfile)
        formatter = logging.Formatter(FORMAT)
        fh.setFormatter(formatter)
        logger.addHandler(fh)

    if args.debug:
        logger.setLevel(logging.DEBUG)

    config = yaml.load(open(args.config_file))
    sessionmaker = config_to_db_session(config, Base)

    stomp_endpoint = config['stomp_endpoint']
    stomp_login = config['stomp_login']
    stomp_password = config['stomp_password']

    stomp_config = StompConfig(stomp_endpoint, login=stomp_login, passcode=stomp_password)

    if args.purge:
        purge_completed_jobs(sessionmaker())
        return
    elif args.loadgen:
        if not args.sessionid:
            raise ValueError('parameter sessionid is required for load generator')
        jm = StompSync(stomp_config)
        jm.connect()
        generate_load(jm, args.sessionid)
        jm.disconnect()
        return
    elif args.httpserver:
        from jobmanager.www import app
        app.config['DB'] = sessionmaker
        app.config['params'] = config
        app.run()
        return

    jm = JobManager(sessionmaker, config=stomp_config)
    jm.run()

    l = task.LoopingCall(jm.run_periodic_checks)
    l.start(PERIODIC_CHECK_INTERVAL)

    reactor.run()
开发者ID:CSC-IT-Center-for-Science,项目名称:chipster-job-manager,代码行数:56,代码来源:manager.py

示例12: test_3_timeout

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import disconnect [as 别名]
    def test_3_timeout(self):
        timeout = 0.2
        client = Stomp(StompConfig(uri='failover:(tcp://localhost:61610,tcp://localhost:61613)?startupMaxReconnectAttempts=1,randomize=false', login=LOGIN, passcode=PASSCODE, version=StompSpec.VERSION_1_0))
        client.connect(host=VIRTUALHOST, connectTimeout=timeout)
        client.disconnect()

        client = Stomp(StompConfig(uri='failover:(tcp://localhost:61610,tcp://localhost:61611)?startupMaxReconnectAttempts=1,backOffMultiplier=3', login=LOGIN, passcode=PASSCODE, version=StompSpec.VERSION_1_0))
        self.assertRaises(StompConnectionError, client.connect, host=VIRTUALHOST, connectTimeout=timeout)

        client = Stomp(StompConfig(uri='failover:(tcp://localhost:61610,tcp://localhost:61613)?randomize=false', login=LOGIN, passcode=PASSCODE, version=StompSpec.VERSION_1_0)) # default is startupMaxReconnectAttempts = 0
        self.assertRaises(StompConnectionError, client.connect, host=VIRTUALHOST, connectTimeout=timeout)
开发者ID:nikipore,项目名称:stompest,代码行数:13,代码来源:sync_client_integration_test.py

示例13: test_5_integration_stomp_1_1_heartbeat

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import disconnect [as 别名]
    def test_5_integration_stomp_1_1_heartbeat(self):
        version = StompSpec.VERSION_1_1
        if BROKER == 'apollo':
            print "Broker %s doesn't properly support heart-beating. Skipping test." % BROKER
            return

        port = 61612 if (BROKER == 'activemq') else PORT # stomp+nio on 61613 does not work properly, so use stomp on 61612
        client = Stomp(self.getConfig(StompSpec.VERSION_1_1, port))
        self.assertEquals(client.lastReceived, None)
        self.assertEquals(client.lastSent, None)

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

        self.assertTrue((time.time() - client.lastReceived) < 0.1)
        if not (client.serverHeartBeat and client.clientHeartBeat):
            print 'broker does not support heart-beating. disconnecting ...'
            client.disconnect()
            client.close()
            return

        serverHeartBeatInSeconds = client.serverHeartBeat / 1000.0
        clientHeartBeatInSeconds = client.clientHeartBeat / 1000.0

        start = time.time()
        while (time.time() - start) < (2.5 * max(serverHeartBeatInSeconds, clientHeartBeatInSeconds)):
            time.sleep(0.5 * min(serverHeartBeatInSeconds, clientHeartBeatInSeconds))
            client.canRead(0)
            self.assertTrue((time.time() - client.lastReceived) < (2.0 * serverHeartBeatInSeconds))
            if (time.time() - client.lastSent) > (0.5 * clientHeartBeatInSeconds):
                client.beat()
                self.assertTrue((time.time() - client.lastSent) < 0.1)

        start = time.time()
        try:
            while not client.canRead(0.5 * clientHeartBeatInSeconds):
                pass
        except StompConnectionError:
            self.assertTrue((time.time() - start) < (3.0 * clientHeartBeatInSeconds))
            self.assertTrue((time.time() - client.lastReceived) < (2.0 * serverHeartBeatInSeconds))
            self.assertTrue((time.time() - client.lastSent) > clientHeartBeatInSeconds)
        else:
            raise
        client.close()
开发者ID:anthony-cervantes,项目名称:stompest,代码行数:50,代码来源:sync_client_integration_test.py

示例14: test_2_transaction

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import disconnect [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

示例15: test_5_integration_stomp_1_1_heartbeat

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import disconnect [as 别名]
    def test_5_integration_stomp_1_1_heartbeat(self):
        version = StompSpec.VERSION_1_1

        client = Stomp(self.getConfig(StompSpec.VERSION_1_1))
        self.assertEqual(client.lastReceived, None)
        self.assertEqual(client.lastSent, None)

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

        self.assertTrue((time.time() - client.lastReceived) < 0.1)
        if not (client.serverHeartBeat and client.clientHeartBeat):
            print('broker does not support heart-beating. disconnecting ...')
            client.disconnect()
            client.close()
            return

        serverHeartBeatInSeconds = client.serverHeartBeat / 1000.0
        clientHeartBeatInSeconds = client.clientHeartBeat / 1000.0

        start = time.time()
        while (time.time() - start) < (2.5 * max(serverHeartBeatInSeconds, clientHeartBeatInSeconds)):
            time.sleep(0.5 * min(serverHeartBeatInSeconds, clientHeartBeatInSeconds))
            client.canRead(0)
            self.assertTrue((time.time() - client.lastReceived) < (2.0 * serverHeartBeatInSeconds))
            if (time.time() - client.lastSent) > (0.5 * clientHeartBeatInSeconds):
                client.beat()
                self.assertTrue((time.time() - client.lastSent) < 0.1)

        start = time.time()
        try:
            while not client.canRead(0.5 * clientHeartBeatInSeconds):
                pass
            if client.receiveFrame().command == StompSpec.ERROR:
                raise StompProtocolError()
        except (StompConnectionError, StompProtocolError):
            self.assertTrue((time.time() - start) < (3.0 * clientHeartBeatInSeconds))
            self.assertTrue((time.time() - client.lastReceived) < (2.0 * serverHeartBeatInSeconds))
            self.assertTrue((time.time() - client.lastSent) > clientHeartBeatInSeconds)
        else:
            raise
        client.close()
开发者ID:nikipore,项目名称:stompest,代码行数:48,代码来源:sync_client_integration_test.py


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