當前位置: 首頁>>代碼示例>>Python>>正文


Python Stomp.subscribe方法代碼示例

本文整理匯總了Python中stompest.Stomp.subscribe方法的典型用法代碼示例。如果您正苦於以下問題:Python Stomp.subscribe方法的具體用法?Python Stomp.subscribe怎麽用?Python Stomp.subscribe使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在stompest.Stomp的用法示例。


在下文中一共展示了Stomp.subscribe方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_replay_after_failover

# 需要導入模塊: from stompest import Stomp [as 別名]
# 或者: from stompest.Stomp import subscribe [as 別名]
    def test_replay_after_failover(self):
        ports = tuple(c.getHost().port for c in self.connections)
        config = StompConfig(uri='failover:(tcp://localhost:%d)?startupMaxReconnectAttempts=0,initialReconnectDelay=0,maxReconnectAttempts=1' % ports)
        client = Stomp(config)
        try:
            client.subscribe('/queue/bla', self._on_message) # client is not connected, so it won't accept subscriptions
        except StompConnectionError:
            pass
        else:
            raise

        self.assertEquals(client.session._subscriptions, {}) # check that no subscriptions have been accepted
        yield client.connect()

        self.shutdown = True # the callback handler will kill the broker connection ... 
        client.subscribe('/queue/bla', self._on_message)
        try:
            client = yield client.disconnected # the callback handler has killed the broker connection
        except StompConnectionError:
            pass
        else:
            raise

        self.shutdown = False # the callback handler will not kill the broker connection, but callback self._got_message
        self._got_message = defer.Deferred()

        yield client.connect()
        self.assertNotEquals(client.session._subscriptions, []) # the subscriptions have been replayed ...

        result = yield self._got_message
        self.assertEquals(result, None) # ... and the message comes back

        yield client.disconnect()
        self.assertEquals(list(client.session.replay()), []) # after a clean disconnect, the subscriptions are forgotten.
開發者ID:irdetoakinavci,項目名稱:AMQMessageProducer,代碼行數:36,代碼來源:async_client_test.py

示例2: test_disconnect_connection_lost_unexpectedly

# 需要導入模塊: from stompest import Stomp [as 別名]
# 或者: from stompest.Stomp import subscribe [as 別名]
    def test_disconnect_connection_lost_unexpectedly(self):
        port = self.connections[0].getHost().port
        config = StompConfig(uri="tcp://localhost:%d" % port, version="1.1")
        client = Stomp(config)

        yield client.connect()

        self._got_message = defer.Deferred()
        client.subscribe(
            "/queue/bla",
            headers={StompSpec.ID_HEADER: 4711},
            listener=SubscriptionListener(self._on_message, ack=False),
        )  # we're acking the frames ourselves
        yield self._got_message

        disconnected = client.disconnected
        client.send("/queue/fake", "shutdown")  # tell the broker to drop the connection
        try:
            yield disconnected
        except StompConnectionError:
            pass
        else:
            raise

        self.wait.callback(None)
開發者ID:hhamalai,項目名稱:stompest,代碼行數:27,代碼來源:async_client_test.py

示例3: run

# 需要導入模塊: from stompest import Stomp [as 別名]
# 或者: from stompest.Stomp import subscribe [as 別名]
 def run(self):
     config = StompConfig('tcp://%s:%d' % (host, port), login=user, passcode=password, version='1.1')
     client = Stomp(config)
     yield client.connect(host='mybroker')
     
     self.count = 0
     self.start = time.time()
     client.subscribe(destination, self.handleFrame, headers={'ack': 'auto', 'id': 'required-for-STOMP-1.1'}, ack=False)
開發者ID:AlexAdamenko,項目名稱:SWATask3,代碼行數:10,代碼來源:listener.py

示例4: run

# 需要導入模塊: from stompest import Stomp [as 別名]
# 或者: from stompest.Stomp import subscribe [as 別名]
 def run(self):
     client = Stomp(self.config)
     yield client.connect()
     headers = {
         # client-individual mode is necessary for concurrent processing
         # (requires ActiveMQ >= 5.2)
         StompSpec.ACK_HEADER: StompSpec.ACK_CLIENT_INDIVIDUAL,
         # the maximal number of messages the broker will let you work on at the same time
         'activemq.prefetchSize': '100',
     }
     client.subscribe(self.QUEUE, headers, listener=SubscriptionListener(self.consume, errorDestination=self.ERROR_QUEUE))
開發者ID:nikipore,項目名稱:stompest,代碼行數:13,代碼來源:consumer.py

示例5: test_disconnect_timeout

# 需要導入模塊: from stompest import Stomp [as 別名]
# 或者: from stompest.Stomp import subscribe [as 別名]
 def test_disconnect_timeout(self):
     port = self.connections[0].getHost().port
     config = StompConfig(uri='tcp://localhost:%d' % port, version='1.1')
     client = Stomp(config)
     yield client.connect()
     self._got_message = defer.Deferred()
     client.subscribe('/queue/bla', self._on_message, headers={'id': 4711}, ack=False) # we're acking the frames ourselves
     yield self._got_message
     try:
         yield client.disconnect(timeout=0.02)
     except StompCancelledError:
         pass
     else:
         raise
     self.wait.callback(None)
開發者ID:irdetoakinavci,項目名稱:AMQMessageProducer,代碼行數:17,代碼來源:async_client_test.py

示例6: test_disconnect_timeout

# 需要導入模塊: from stompest import Stomp [as 別名]
# 或者: from stompest.Stomp import subscribe [as 別名]
 def test_disconnect_timeout(self):
     port = self.connections[0].getHost().port
     config = StompConfig(uri='tcp://localhost:%d' % port, version='1.1')
     client = Stomp(config)
     yield client.connect()
     self._got_message = defer.Deferred()
     client.subscribe('/queue/bla', headers={StompSpec.ID_HEADER: 4711}, listener=SubscriptionListener(self._on_message, ack=False)) # we're acking the frames ourselves
     yield self._got_message
     yield client.disconnect(timeout=0.02)
     try:
         yield client.disconnected
     except StompConnectionError:
         pass
     else:
         raise
     self.wait.callback(None)
開發者ID:IngoScholtes,項目名稱:stompest,代碼行數:18,代碼來源:async_client_test.py

示例7: run

# 需要導入模塊: from stompest import Stomp [as 別名]
# 或者: from stompest.Stomp import subscribe [as 別名]
    def run(self):
        ''' Initializes the stompest async client '''
        queue_url = self.config['queue']['url']
        queue_name = self.config['queue']['name']
        error_queue_name = self.config['queue']['error_name']

        client = Stomp(StompConfig(queue_url))
        yield client.connect()

        client.subscribe(
            queue_name,  # must begin with leading slash (eg: /queue/)
            headers={StompSpec.ACK_HEADER: StompSpec.ACK_CLIENT_INDIVIDUAL},
            listener=SubscriptionListener(
                self.consume,
                errorDestination=error_queue_name
            )
        )

        client.add(self)
開發者ID:CBIIT,項目名稱:nci-webtools-dceg-classification,代碼行數:21,代碼來源:soccerProcessor.py

示例8: test_disconnect_connection_lost_unexpectedly

# 需要導入模塊: from stompest import Stomp [as 別名]
# 或者: from stompest.Stomp import subscribe [as 別名]
    def test_disconnect_connection_lost_unexpectedly(self):
        port = self.connections[0].getHost().port
        config = StompConfig(uri='tcp://localhost:%d' % port, version='1.1')
        client = Stomp(config)

        yield client.connect()

        self._got_message = defer.Deferred()
        client.subscribe('/queue/bla', headers={StompSpec.ID_HEADER: 4711}, listener=SubscriptionListener(self._on_message, ack=False)) # we're acking the frames ourselves
        yield self._got_message

        disconnected = client.disconnected
        client.send('/queue/fake', b'shutdown') # tell the broker to drop the connection
        try:
            yield disconnected
        except StompConnectionError:
            pass
        else:
            raise Exception('Expected unexpected loss of connection, but disconnect went gracefully.')

        self.wait.callback(None)
開發者ID:nikipore,項目名稱:stompest,代碼行數:23,代碼來源:async_client_test.py

示例9: test_disconnect_connection_lost_unexpectedly

# 需要導入模塊: from stompest import Stomp [as 別名]
# 或者: from stompest.Stomp import subscribe [as 別名]
    def test_disconnect_connection_lost_unexpectedly(self):
        port = self.connections[0].getHost().port
        config = StompConfig(uri='tcp://localhost:%d' % port, version='1.1')
        client = Stomp(config)

        yield client.connect()

        self._got_message = defer.Deferred()
        client.subscribe('/queue/bla', self._on_message, headers={'id': 4711}, ack=False) # we're acking the frames ourselves
        yield self._got_message

        disconnected = client.disconnected
        client.send('/queue/fake', 'shutdown') # tell the broker to drop the connection
        try:
            yield disconnected
        except StompConnectionError:
            pass
        else:
            raise

        self.wait.callback(None)
開發者ID:irdetoakinavci,項目名稱:AMQMessageProducer,代碼行數:23,代碼來源:async_client_test.py

示例10: test_multi_subscriptions

# 需要導入模塊: from stompest import Stomp [as 別名]
# 或者: from stompest.Stomp import subscribe [as 別名]
    def test_multi_subscriptions(self):
        port = self.connections[0].getHost().port
        config = StompConfig(uri="tcp://localhost:%d" % port)
        client = Stomp(config)
        yield client.connect()

        listeners = []
        for j in range(2):
            listener = SubscriptionListener(self._on_message)
            yield client.subscribe("/queue/%d" % j, headers={"bla": j}, listener=listener)
            listeners.append(listener)

        for (j, listener) in enumerate(listeners):
            self.assertEquals(listener._headers["bla"], j)

        yield client.disconnect()
        yield client.disconnected
開發者ID:hhamalai,項目名稱:stompest,代碼行數:19,代碼來源:async_client_test.py


注:本文中的stompest.Stomp.subscribe方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。