def test_failover_on_connection_lost(self):
        ports = tuple(c.getHost().port for c in self.connections)
        config = StompConfig(
            uri=
            'failover:(tcp://localhost:%d,tcp://localhost:%d)?startupMaxReconnectAttempts=0,initialReconnectDelay=0,randomize=false,maxReconnectAttempts=1'
            % ports)
        client = Stomp(config)

        yield client.connect()
        self.connections[0].stopListening()
        queue = '/queue/fake'
        client.send(queue, b'shutdown')
        try:
            yield client.disconnected
        except StompConnectionError:
            yield client.connect()
        else:
            raise Exception('Unexpected clean disconnect.')
        client.send(queue, b'fake message')

        try:
            yield client.disconnected
        except StompProtocolError:
            pass
        else:
            raise Exception('Unexpected clean disconnect.')
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_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)
示例#4
0
    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 test_disconnect_on_stomp_protocol_error(self):
        port = self.connections[0].getHost().port
        config = StompConfig(uri='tcp://localhost:%d' % port)
        client = Stomp(config)

        yield client.connect()
        client.send('/queue/fake', 'fake message')
        try:
            yield client.disconnected
        except StompProtocolError:
            pass
        else:
            raise
示例#6
0
    def test_disconnect_on_stomp_protocol_error(self):
        port = self.connections[0].getHost().port
        config = StompConfig(uri='tcp://localhost:%d' % port)
        client = Stomp(config)

        yield client.connect()
        client.send('/queue/fake', b'fake message')
        try:
            yield client.disconnected
        except StompProtocolError:
            pass
        else:
            raise Exception('Expected a StompProtocolError, but nothing was raised.')
示例#7
0
    def test_disconnect_on_stomp_protocol_error(self):
        port = self.connections[0].getHost().port
        config = StompConfig(uri="tcp://localhost:%d" % port)
        client = Stomp(config)

        yield client.connect()
        client.send("/queue/fake", "fake message")
        try:
            yield client.disconnected
        except StompProtocolError:
            pass
        else:
            raise
示例#8
0
    def test_disconnect_on_stomp_protocol_error(self):
        port = self.connections[0].getHost().port
        config = StompConfig(uri='failover:(tcp://nosuchhost:65535,tcp://localhost:%d)?startupMaxReconnectAttempts=1,initialReconnectDelay=0,randomize=false' % port)
        client = Stomp(config)

        yield client.connect()
        client.send('/queue/fake', 'fake message')
        try:
            yield client.disconnected
        except StompProtocolError:
            pass
        else:
            raise
    def test_disconnect_on_stomp_protocol_error(self):
        port = self.connections[0].getHost().port
        config = StompConfig(uri='tcp://localhost:%d' % port)
        client = Stomp(config)

        yield client.connect()
        client.send('/queue/fake', b'fake message')
        try:
            yield client.disconnected
        except StompProtocolError as e:
            self.assertTrue(isinstance(e.frame, StompFrame))
        else:
            raise Exception(
                'Expected a StompProtocolError, but nothing was raised.')
示例#10
0
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 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')
示例#12
0
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')
示例#13
0
 def test_not_connected(self):
     port = self.connections[0].getHost().port
     config = StompConfig(uri='tcp://localhost:%d' % port)
     client = Stomp(config)
     try:
         yield client.send('/queue/fake')
     except (StompConnectionError, AlreadyCancelled):
         pass
示例#14
0
 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
示例#15
0
 def test_not_connected(self):
     port = self.connections[0].getHost().port
     config = StompConfig(uri="tcp://localhost:%d" % port)
     client = Stomp(config)
     try:
         yield client.send("/queue/fake")
     except StompConnectionError:
         pass
 def test_not_connected(self):
     port = self.connections[0].getHost().port
     config = StompConfig(uri='tcp://localhost:%d' % port)
     client = Stomp(config)
     try:
         yield client.send('/queue/fake')
     except StompConnectionError:
         pass
    def test_failover_on_connection_lost(self):
        ports = tuple(c.getHost().port for c in self.connections)
        config = StompConfig(uri='failover:(tcp://localhost:%d,tcp://localhost:%d)?startupMaxReconnectAttempts=0,initialReconnectDelay=0,randomize=false,maxReconnectAttempts=1' % ports)
        client = Stomp(config)

        yield client.connect()
        self.connections[0].stopListening()
        client.send('/queue/fake', 'shutdown')
        try:
            client = yield client.disconnected
        except StompConnectionError:
            yield client.connect()
        client.send('/queue/fake', 'fake message')

        try:
            yield client.disconnected
        except StompProtocolError:
            pass
示例#18
0
 def test_not_connected(self):
     port = self.connections[0].getHost().port
     config = StompConfig(uri='tcp://localhost:%d' % port)
     client = Stomp(config)
     try:
         yield client.send('/queue/fake')
     except StompConnectionError:
         pass
     else:
         raise Exception('Expected connection error, but nothing frame could be sent.')
 def test_not_connected(self):
     port = self.connections[0].getHost().port
     config = StompConfig(uri='tcp://localhost:%d' % port)
     client = Stomp(config)
     try:
         yield client.send('/queue/fake')
     except StompConnectionError:
         pass
     else:
         raise Exception(
             'Expected connection error, but nothing frame could be sent.')
示例#20
0
 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
示例#21
0
文件: mq_unit.py 项目: duyunhe/basic
 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
示例#22
0
    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_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)
示例#24
0
    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
示例#25
0
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'