Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Polyglot

Medici

  • Java

  • C++

  • Python

      
    Code Block
    themeEmacs
    languagepy
    titleInstantiating the logger and starting the extractor
    def main():
     global logger
    
     # name of receiver
    receiver='ExamplePythonExtractor'
    
     # configure the logging system
    logging.basicConfig(format="%(asctime)-15s %(name)-10s %(levelname)-7s : %(message)s", level=logging.WARN)
    logger = logging.getLogger(receiver)
    logger.setLevel(logging.DEBUG)
     
     if len(sys.argv) != 4:
    logger.info("Input RabbitMQ username, followed by RabbitMQ password and Medici REST API key.")
    sys.exit()
     
     global playserverKey
    playserverKey = sys.argv[3]
    Code Block
    themeEmacs
    languagepy
    titleConnecting to RabbitMQ
    # connect to rabbitmq using input username and password 
    credentials = pika.PlainCredentials(sys.argv[1], sys.argv[2])
    parameters = pika.ConnectionParameters(credentials=credentials)
    connection = pika.BlockingConnection(parameters)
     
     # connect to channel
    channel = connection.channel()
    
     # declare the exchange
    channel.exchange_declare(exchange='medici', exchange_type='topic', durable=True)
    
     # declare the queue
    channel.queue_declare(queue=receiver, durable=True)
    
     # connect queue and exchange
    channel.queue_bind(queue=receiver, exchange='medici', routing_key='*.file.text.#')
    
     # create listener
    channel.basic_consume(on_message, queue=receiver, no_ack=False)
    
     # start listening
    logger.info("Waiting for messages. To exit press CTRL+C")
     try:
    channel.start_consuming()
     except KeyboardInterrupt:
    channel.stop_consuming()
    

...