示例#1
0
 def create_connection_obj(self,
                           version='1.0',
                           vhost='/',
                           heartbeats=(0, 0)):
     if version == '1.0':
         conn = stomp.StompConnection10(
             host_and_ports=[('localhost', int(os.environ["STOMP_PORT"]))])
         self.ack_id_source_header = 'message-id'
         self.ack_id_header = 'message-id'
     elif version == '1.1':
         conn = stomp.StompConnection11(host_and_ports=[
             ('localhost', int(os.environ["STOMP_PORT"]))
         ],
                                        vhost=vhost,
                                        heartbeats=heartbeats)
         self.ack_id_source_header = 'message-id'
         self.ack_id_header = 'message-id'
     elif version == '1.2':
         conn = stomp.StompConnection12(host_and_ports=[
             ('localhost', int(os.environ["STOMP_PORT"]))
         ],
                                        vhost=vhost,
                                        heartbeats=heartbeats)
         self.ack_id_source_header = 'ack'
         self.ack_id_header = 'id'
     else:
         conn = stomp.StompConnection12(host_and_ports=[
             ('localhost', int(os.environ["STOMP_PORT"]))
         ],
                                        vhost=vhost,
                                        heartbeats=heartbeats)
         conn.version = version
     return conn
示例#2
0
 def create_connection_obj(self,
                           version='1.0',
                           vhost='/',
                           heartbeats=(0, 0)):
     if version == '1.0':
         conn = stomp.StompConnection10()
         self.ack_id_source_header = 'message-id'
         self.ack_id_header = 'message-id'
     elif version == '1.1':
         conn = stomp.StompConnection11(vhost=vhost, heartbeats=heartbeats)
         self.ack_id_source_header = 'message-id'
         self.ack_id_header = 'message-id'
     elif version == '1.2':
         conn = stomp.StompConnection12(vhost=vhost, heartbeats=heartbeats)
         self.ack_id_source_header = 'ack'
         self.ack_id_header = 'id'
     else:
         conn = stomp.StompConnection12(vhost=vhost, heartbeats=heartbeats)
         conn.version = version
     return conn
示例#3
0
        print('received an error "%s"' % message)

    def on_message(self, headers, message):
        logger.info("inside on message ", type(message), message)
        message = json.loads(message)
        self.msg_received += 1
        msg = "{} messages received ".format(self.msg_received)
        print(msg)

        # add the logic to process based on message here

        sleep(0.1)


conn = stomp.StompConnection10([
    ('11.24.32.734', 6339),
])
listener = MsgListener()
conn.set_listener('', listener)
conn.connect('user', 'pass', wait=True)
conn.subscribe('/topic/path', headers={})
start = datetime.now()
msg = "{:%d, %b %Y-%Hhrs:%Mmins:%Ssecs} start consumer".format(start)
print(msg)

# def check_messages():
#     print("inside check_message")
#
#     time.sleep(1)
#     print("disconnecting")
#     conn.disconnect()