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)
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.
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)
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='atcg', listener=SubscriptionListener(self.handleFrame), headers={'ack': 'auto', 'id': 'required-for-STOMP-1.1'})
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)
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))
def run(self): client = Stomp(self.config) yield client.connect() headers = { StompSpec.ACK_HEADER: StompSpec.ACK_CLIENT_INDIVIDUAL, 'activemq.prefetchSize': '500' } client.subscribe(self.QUEUE_IN, headers, listener=SubscriptionListener( self.add, errorDestination=self.QUEUE_OUT))
def runrealtime(self): try: client = Stomp(CONFIG) yield client.connect() headers = { StompSpec.ACK_HEADER: StompSpec.ACK_AUTO, 'activemq.prefetchSize': '100', } client.subscribe(QUEUE, headers, listener=SubscriptionListener(self.consume)) except Exception, e: log.error(e) log.error(traceback.format_exc())
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)
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)
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) queue = '/queue/bla' try: client.subscribe( queue, listener=SubscriptionListener(self._on_message) ) # client is not connected, so it won't accept subscriptions except StompConnectionError: pass else: raise Exception('Unexpected successful subscribe.') 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, listener=SubscriptionListener(self._on_message)) try: yield client.disconnected # the callback handler has killed the broker connection except StompConnectionError: pass else: raise Exception('Unexpected clean disconnect.') 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() yield client.disconnected self.assertEquals( list(client.session.replay()), []) # after a clean disconnect, the subscriptions are forgotten.
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)
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 StompCancelledError: pass else: raise self.wait.callback(None)
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)
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)
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
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
def run(self): client = Stomp(StompConfig('tcp://'+config['queue.host']+':'+str(config['queue.port'])+'?startupMaxReconnectAttempts=-1,initialReconnectDelay=1000,maxReconnectAttempts=-1')) yield client.connect() headers = { StompSpec.ACK_HEADER: StompSpec.ACK_CLIENT_INDIVIDUAL } client.subscribe('/queue/Comets', headers, listener = SubscriptionListener(self.consume, errorDestination = '/queue/error'))
class CTIE_Queue_Manager(threading.Thread): def __init__(self, queue_config): threading.Thread.__init__ (self) self.queue_config = queue_config config = StompConfig('tcp://%s:%s' % (queue_config['activemq']['host'], queue_config['activemq']['port']), login=queue_config['activemq']['user'], passcode=queue_config['activemq']['password'], version='1.1') self.client = Stomp(config) @defer.inlineCallbacks def run(self): yield self.client.connect(host='mybroker') self.client.subscribe(self.queue_config['activemq']['ingress'], listener=SubscriptionListener(self.handle_frame), headers={'ack': 'auto', 'id': 'required-for-STOMP-1.1'}) @defer.inlineCallbacks def send_frame(self, message): print "send_frame" self.client.send(destination=self.queue_config['activemq']['egress'], body=message, headers={'persistent': 'false'}) @defer.inlineCallbacks def handle_frame(self, client, frame): print "handle_frame" print "Frame.body: " + frame.body try: data = json.loads(frame.body) except Exception as e: print type(e) print e.args print e print traceback.format_exc() data_payload = data["payload"] response = text2pcap_formatter(data_payload, 16) print "Packet payload: \n" + response payload_hex_file_path = write_payload(response) print "payload hex file path: \n" + payload_hex_file_path paths = generate_file_paths(payload_hex_file_path) pcap_file_path = paths[0] json_file_path = paths[1] print "pcap file path: \n" + pcap_file_path print "json file path: \n" + json_file_path command_text2pcap = ("./bin/text2pcap %s %s" % (payload_hex_file_path, pcap_file_path)).split() for line in run_command(command_text2pcap): print line command_nDPI = ("./bin/ndpiReader -i %s -j %s" % (pcap_file_path, json_file_path)).split() for line in run_command(command_nDPI): print line with open(json_file_path) as ndpi_json_file: response = json.load(ndpi_json_file) data["dpi_response"] = response self.send_frame(json.dumps(data)) ###################################### @defer.inlineCallbacks def stop(self, client): print 'Disconnecting. Waiting for RECEIPT frame ...' yield client.disconnect(receipt='bye') print 'ok'