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


Python Stomp.connect方法代码示例

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


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

示例1: writeJson

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

示例2: test_6_integration_stomp_1_1_encoding_and_escaping_headers

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

示例3: _test_4_integration_stomp

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

示例4: test_4_integration_stomp_1_1

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

示例5: call_route

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

示例6: main

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

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

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

示例9: configureClient

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import connect [as 别名]
    def configureClient(self, _login, _passcode):
        CONFIG = StompConfig("tcp://datafeeds.networkrail.co.uk:61618", login=_login, passcode=_passcode)

        client = Stomp(CONFIG)
        client.connect()
        client.subscribe("/topic/TD_KENT_MCC_SIG_AREA")

        self._client = client
开发者ID:sparky18,项目名称:networkrail,代码行数:10,代码来源:watch.py

示例10: recv_stomp

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

示例11: main

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

示例12: _conn

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import connect [as 别名]
def _conn(cfg_uri, queue, _info):
    from stompest.config import StompConfig
    from stompest.sync import Stomp

    _info("Init Stomp obj: [%s-%s]" % (cfg_uri, queue))
    client = Stomp(StompConfig(cfg_uri))
    _info("connecting... %s" % cfg_uri)
    client.connect()
    _info("connected %s" % cfg_uri)
    return client
开发者ID:yankaics,项目名称:xtls,代码行数:12,代码来源:mqwrapper.py

示例13: setUp

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

示例14: main

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

示例15: run

# 需要导入模块: from stompest.sync import Stomp [as 别名]
# 或者: from stompest.sync.Stomp import connect [as 别名]
    def run(self):
        if(processgid > 0): os.setgid(processgid)
        if(processuid > 0): os.setuid(processuid)
        config = StompConfig('tcp://%(HOST)s:%(PORT)s' % ActiveMQ)
        topic = "/topic/%(FILESYNCTOPIC)s" % ActiveMQ
        client = Stomp(config)
        self.logger = logging.getLogger('nfssync') 
        self.logger.setLevel(logging.DEBUG)
        handler = TimedRotatingFileHandler(LOGFILE, when='midnight', interval=1, backupCount=30)
        formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        handler.setFormatter(formatter)
        self.logger.addHandler(handler)

        try:
            client.connect()
            client.subscribe(topic, {StompSpec.ACK_HEADER: StompSpec.ACK_CLIENT_INDIVIDUAL})

            while True:
                frame = client.receiveFrame()
                subdir = frame.body

                srcpath = os.path.join(ActiveMQ['SRCDIR'], subdir)
                dstpath = os.path.dirname(os.path.join(ActiveMQ['DSTDIR'], subdir))
                self.logger.info("Syncing %s to %s" % (srcpath,dstpath))
                if(not os.path.exists(srcpath)):
                    msg = "Source %s does not exist" % srcpath
                    self.logger.error(msg)
                    proxy_email(email_subject_error, msg)
                    client.ack(frame)
                    continue
                elif(not os.path.isdir(srcpath)):
                    msg = "Source %s is not a directory" % srcpath
                    self.logger.error(msg)
                    proxy_email(email_subject_error, msg)
                    client.ack(frame)
                    continue
                elif(not os.path.exists(dstpath)):
                    msg = "Destination %s does not exist" % dstpath
                    self.logger.warning(msg)
                    proxy_email(email_subject_warning, msg)
                    os.umask(0)
                    os.makedirs(dstpath, 0777)
                cmd = "rsync -avzq --delete %s %s" % (srcpath,dstpath)
                if(call(cmd, shell=True) > 0):
                    msg = "Sync %s failed" % cmd
                    self.logger.error(msg)
                    proxy_email(email_subject, msg)
                client.ack(frame)
                    
        except Exception, e:
            msg = "Exception in %s: %s" % (sys.argv[0], str(e))
            self.logger.error(msg)
            proxy_email(email_subject_error, msg)
            exit(1)
开发者ID:itay-moav,项目名称:talis,代码行数:56,代码来源:nfssync.py


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