def run(self, _): client = Stomp(self.config) yield client.connect() client.add(ReceiptListener(1.0)) for j in range(10): yield client.send(self.QUEUE, json.dumps({'count': j}).encode(), receipt='message-%d' % j) client.disconnect(receipt='bye') yield client.disconnected # graceful disconnect: waits until all receipts have arrived
def run(self, _): bt = clock() client = Stomp(self.config) yield client.connect() client.add(ReceiptListener(1.0)) for i in range(200000): yield client.send(self.QUEUE, "hello world qwertyuiopasdfghjklzxcvbnm") client.disconnect() et = clock() print et - bt yield client.disconnected
def run(self, _): client = Stomp(self.config) yield client.connect() client.add(ReceiptListener(1.0)) for j in range(10): yield client.send(self.QUEUE, json.dumps({ 'count': j }).encode(), receipt='message-%d' % j) client.disconnect(receipt='bye') yield client.disconnected # graceful disconnect: waits until all receipts have arrived
def toQueue(email, tokenId): # print "in toQueue" resp = "" try: qp = QueueProcessor(PRODUCT_NAME="LDlink Batch Processing Module", CONFIG_FILE=r"QueueConfig.ini", Q_NAME='queue.name', Q_URL='queue.url', Q_PORT='queue.port', Q_ERROR='queue.error.name', MAIL_HOST='mail.host', MAIL_ADMIN='mail.admin') batchFile = open(os.path.join('tmp', tokenId)) # print batchFile ts = time.strftime("%Y-%m-%d") data = json.dumps({ "filepath": batchFile.name, "token": tokenId, "timestamp": ts }) print "before client connect" print "Stomp( {0}, {1} )".format(qp.Q_URL, qp.Q_PORT) print type(qp.Q_URL) print type(qp.Q_PORT) client = Stomp("tcp://{0}:{1}".format(qp.Q_URL, qp.Q_PORT)) #opening connection to queue client.connect() client.send(qp.Q_NAME, data) client.disconnect() return jsonify({ "message": "The batch process has begun. The results will be emailed to " + email }) except Exception, e: errorType, error, traceback = sys.exc_info() print errorType print error print traceback print e.args[1:] resp = jsonify({"message": e.args}) resp.status_code = 400 return resp
def readCSV(): config = StompConfig('tcp://%s:%d' % (host, port), login=user, passcode=password, version='1.1') client = Stomp(config) yield client.connect(host='mybroker') count = 0 start = time.time() with open(desiredCSV, 'r') as readFile: csv_reader = csv.reader(readFile) for row in csv_reader: if row[4] != 'C' and row[4] != 'G': try: cursor.execute(sql.SQL("insert into {} values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)").format(sql.Identifier('getactivemq')), row) db_conn.commit() except: print "cannot insert into table" elif row[4] == 'C' or row[4] == 'G': rowDictionary = {"rowData" : row} jsonData = json.dumps(rowDictionary) client.send(destination='atcg', body=jsonData, headers={'persistent': 'false'}) else: print 'Error reading 5th column' diff = time.time() - start print 'Sent %s frames in %f seconds' % (count, diff) yield client.disconnect(receipt='bye')
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_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 run(): config = StompConfig('tcp://%s:%d' % (host, port), login=user, passcode=password, version='1.1') client = Stomp(config) yield client.connect(host='mybroker') count = 0 start = time.time() for _ in xrange(messages): client.send(destination=destination, body=data, headers={'persistent': 'false'}) count += 1 diff = time.time() - start print 'Sent %s frames in %f seconds' % (count, diff) yield client.disconnect(receipt='bye')
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 run(): config = StompConfig('tcp://%s:%d' % (host, port), login=user, passcode=password, version='1.1') client = Stomp(config) yield client.connect(host='mybroker') count = 0 start = time.time() for _ in xrange(messages): client.send(destination=destination, body=data, headers={'persistent': 'false'}) count += 1 diff = time.time() - start print 'Sent %s frames in %f seconds' % (count, diff) yield client.disconnect(receipt='bye')
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_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 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_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 run(self, _): client = Stomp(self.config) yield client.connect() client.add(ReceiptListener(1.0)) dd8 = [ { 'insureCarId': 3797, 'firstRegister': u'', 'cityCode': '32010000', 'vinNo': u'LVBV6PDC7AH017644', 'plateNumber': u'苏A90198', 'vehicleBrand': u'', 'companyId': ['12'], 'licenseType': '01', 'custName': u'\u9648\u7fe0\u7ea2', 'insuranceType': [ { u'carDamageBenchMarkPremium': u'1', # 车损险不计免赔 u'carDamagePremium': u'1', # 车损险 u'driverDutyPremium': { u'Amount': u'10000', u'isCheck': u'0' }, # 车上人员险(司机) u'driverDutyBenchMarkPremium': u'0', # 车上人员险(司机)不计免赔 u'passengerDutyPremium': { u'Amount': u'10000', u'isCheck': u'0' }, # 车上人员险(乘客) u'passengerBenchMarkPremium': u'0', # 车上人员险(乘客)不计免赔 u'carFirePremium': u'0', # 自燃险 u'carFireBrokenBenchMarkPremium': u'0', # 自燃险不计免赔 u'carTheftPremium': u'0', # 盗抢险 u'carTheftBenchMarkPremium': u'0', # 盗抢险不计免赔 u'otherHurtPremium': { u'Amount': u'1000000', u'isCheck': u'1' }, # 三者险 u'otherHurtBenchMarkPremium': u'1', # 三者险不计免赔 u'engineWadingPremium': u'0', # 涉水险 u'engineWadingBenchMarkPremium': u'0', # 涉水险不计免赔 u'carNickPremium': { u'Amount': u'2000', u'isCheck': u'0' }, # 划痕险 u'carNickBenchMarkPremium': u'0', # 划痕险不计免赔 u'nAggTax': u'1', u'insuranceTypeGroupId': u'183', u'glassBrokenPremium': u'0', # 玻璃破碎险 u'compulsoryInsurance': u'1', u'insuranceTypeGroup': u'1_11_110_12_2_20_3_30_4_5_50_6_8_20000_80_9' }, ], 'sessionId': u'2bbcd99cd95d9b8fdf98b29e163686f6bca30736', 'engineNo': u'0651004', 'NSeatNum': u'5', 'identitCard': u'320121197607280023', 'endDate': u'2017-04-7', 'isPhone': u'1' }, ] # yield client.send('/queue/COMPLETE_PLATE_NUMBER', json.dumps(dd8).encode()) # yield client.send('/queue/BATCH_ANCHENG_QUEUE', json.dumps(dd8).encode()) yield client.send('/queue/REAL_TIME_QUEUE', json.dumps(dd8).encode()) # yield client.send('/queue/BATCH_ANCHENG_QUEUE', json.dumps(dd8).encode()) # yield client.send('/queue/BATCH_PROCESS_QUEUE', json.dumps(dd8).encode()) client.disconnect() yield client.disconnected # graceful disconnect: waits until all receipts have arrived