import time
import sys
import os
import stomp
import Globals

user = os.getenv("STOMP_USER") or "admin"
password = os.getenv("STOMP_PASSWORD") or "password"
host = os.getenv("STOMP_HOST") or "localhost"
port = os.getenv("STOMP_PORT") or 61613
destination = sys.argv[1:2] or ["/topic/event"]
destination = destination[0]

class MyListener(object):
  
  def __init__(self, conn):
    self.conn = conn
  
  def on_error(self, headers, message):
    Globals.log.info('received an error ' + message)

  def on_message(self, headers, message):
    Globals.VIP=message
    Globals.log.info('New VIP: '+Globals.VIP)

conn = stomp.Connection(host_and_ports = [(host, port)])
conn.set_listener('', MyListener(conn))
conn.start()
conn.connect(login=user,passcode=password)
conn.subscribe(destination=destination, ack='auto')
print ('Waiting for messages...')
while True:
   time.sleep(1)