def monitor_messages(connection, topic):
 def process_event(msg):
  body = msg['args']['data']
  if ('resource_id' in body):
   print ('%s: %s/%-15s: %s' % (body.get('timestamp'), body.get('resource_id'), body.get('event_type'), body.get('counter_volume')))
  else:
   print ('%s: %s' % (body.get('timestamp'), body.get('event_type')))
 connection.declare_topic_consumer(topic, process_event)
 try:
  connection.consume()
 except KeyboardInterrupt:
  pass

def monitor_messages ( connection , topic ) : def process_event ( msg ) : body = msg [ 'args' ] [ 'data' ] if ( 'resource_id' in body ) : print ( '%s: %s/%-15s: %s' % ( body . get ( 'timestamp' ) , body . get ( 'resource_id' ) , body . get ( 'event_type' ) , body . get ( 'counter_volume' ) ) ) else : print ( '%s: %s' % ( body . get ( 'timestamp' ) , body . get ( 'event_type' ) ) ) connection . declare_topic_consumer ( topic , process_event ) try : connection . consume ( ) except KeyboardInterrupt : pass
listen to notification .