예제 #1
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
예제 #2
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
예제 #3
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
예제 #4
0
    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'})
예제 #5
0
 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)
예제 #6
0
  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)
예제 #7
0
 def test_connection_timeout_after_failover(self):
     port = self.connections[0].getHost().port
     config = StompConfig(uri='failover:(tcp://nosuchhost:65535,tcp://localhost:%d)?startupMaxReconnectAttempts=2,initialReconnectDelay=0,randomize=false' % port)
     client = Stomp(config)
     try:
         yield client.connect(connectTimeout=self.TIMEOUT, connectedTimeout=self.TIMEOUT)
     except StompConnectTimeout:
         pass
     else:
         raise
예제 #8
0
 def test_stomp_protocol_error_on_connect(self):
     port = self.connections[0].getHost().port
     config = StompConfig(uri='tcp://localhost:%d' % port)
     client = Stomp(config)
     try:
         yield client.connect()
     except StompProtocolError:
         pass
     else:
         raise
예제 #9
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.')
예제 #10
0
 def test_stomp_protocol_error_on_connect(self):
     port = self.connections[0].getHost().port
     config = StompConfig(uri='tcp://localhost:%d' % port)
     client = Stomp(config)
     try:
         yield client.connect()
     except StompProtocolError:
         pass
     else:
         raise Exception('Expected a StompProtocolError, but nothing was raised.')
예제 #11
0
 def test_stomp_protocol_error_on_connect(self):
     port = self.connections[0].getHost().port
     config = StompConfig(uri="tcp://localhost:%d" % port)
     client = Stomp(config)
     try:
         yield client.connect()
     except StompProtocolError:
         pass
     else:
         raise
예제 #12
0
 def test_connected_timeout(self):
     port = self.connections[0].getHost().port
     config = StompConfig(uri='tcp://localhost:%d' % port)
     client = Stomp(config)
     try:
         yield client.connect(connectedTimeout=self.TIMEOUT)
     except StompCancelledError:
         pass
     else:
         raise Exception('Expected connected timeout, but connection was established.')
예제 #13
0
 def test_connection_timeout(self):
     port = self.connections[0].getHost().port
     config = StompConfig(uri="tcp://localhost:%d" % port)
     client = Stomp(config)
     try:
         yield client.connect(connectTimeout=self.TIMEOUT, connectedTimeout=self.TIMEOUT)
     except StompConnectTimeout:
         pass
     else:
         raise
예제 #14
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.')
예제 #15
0
 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))
예제 #16
0
 def test_connection_timeout(self):
     port = self.connections[0].getHost().port
     config = StompConfig(uri='tcp://localhost:%d' % port)
     client = Stomp(config)
     try:
         yield client.connect(connectTimeout=self.TIMEOUT,
                              connectedTimeout=self.TIMEOUT)
     except StompConnectTimeout:
         pass
     else:
         raise
예제 #17
0
 def test_connected_timeout(self):
     port = self.connections[0].getHost().port
     config = StompConfig(uri='tcp://localhost:%d' % port)
     client = Stomp(config)
     try:
         yield client.connect(connectedTimeout=self.TIMEOUT)
     except StompCancelledError:
         pass
     else:
         raise Exception(
             'Expected connected timeout, but connection was established.')
예제 #18
0
파일: mq_rcv.py 프로젝트: duyunhe/basic
 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))
예제 #19
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 as e:
            self.assertTrue(isinstance(e.frame, StompFrame))
        else:
            raise Exception('Expected a StompProtocolError, but nothing was raised.')
예제 #20
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
예제 #21
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
예제 #22
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
    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.
예제 #24
0
    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.')
예제 #25
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 as e:
            self.assertTrue(isinstance(e.frame, StompFrame))
        else:
            raise Exception(
                'Expected a StompProtocolError, but nothing was raised.')
예제 #26
0
 def test_connected_timeout_after_failover(self):
     port = self.connections[0].getHost().port
     config = StompConfig(
         uri=
         'failover:(tcp://nosuchhost:65535,tcp://localhost:%d)?startupMaxReconnectAttempts=2,initialReconnectDelay=0,randomize=false'
         % port)
     client = Stomp(config)
     try:
         yield client.connect(connectedTimeout=self.TIMEOUT)
     except StompCancelledError:
         pass
     else:
         raise Exception(
             'Expected connected timeout, but connection was established.')
예제 #27
0
 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)
예제 #29
0
 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')
예제 #31
0
    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
예제 #32
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)
예제 #33
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
예제 #34
0
    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 = yield Stomp(self.CONFIG[RequestProcessor.CONFIG]).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.CONFIG[RequestProcessor.NAME], headers, listener=SubscriptionListener(self.consume))
   client.add(listener=self)
예제 #36
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
예제 #37
0
 def run(self):
     client = yield Stomp(self.config).connect()
     client.add(ReceiptListener(1.0))
     for j in range(10):
         yield client.send(self.QUEUE,
                           json.dumps({'count': j}),
                           receipt='message-%d' % j)
     client.disconnect(receipt='bye')
     yield client.disconnected  # graceful disconnect: waits until all receipts have arrived
     reactor.stop()
예제 #38
0
    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.
예제 #39
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
예제 #40
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)
예제 #41
0
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')
예제 #42
0
    def run(self):
        client = yield Stomp(self.config).connect()
        client.add(ReceiptListener(1.0))

        i = 0

        # Send the header
        yield client.send(self.queue, json.dumps({'type': 'meta', 'name': self.name, 'lines': len(self.text)}), receipt='message-%d' % i)
        i += 1

        for line in self.text:
            yield client.send(self.queue, json.dumps({'type': 'line', 'name': self.name, 'line': i, 'content': line}), receipt='message-%d' % i)
            i += 1

        client.disconnect(receipt='bye')
        yield client.disconnected # graceful disconnect: waits until all receipts have arrived
        reactor.stop()
    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
예제 #44
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')
    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)
예제 #46
0
 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)
예제 #48
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_stomp_protocol_error_on_connect(self):
     port = self.connections[0].getHost().port
     config = StompConfig(uri='tcp://localhost:%d' % port)
     client = Stomp(config)
     return self.assertFailure(client.connect(), StompProtocolError)
예제 #50
0
 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'))
예제 #51
0
def get_stomp_client():
    conf = StompConfig(STOMP_SERVER,
                       login=STOMP_USERNAME,
                       passcode=STOMP_PASSWORD)  # , version='1.1')
    return Stomp(conf)
예제 #52
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
예제 #53
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'