Added environment variable checking to test weather or not to skip RabbitMQ messaging
@@ -189,19 +189,41 @@ if __name__ == '__main__':
logger.info("Created message")
logger.info(decision)
+
+ # Get json message
+ message = json.dumps(decision)
+
+ # Get our "SKIP_RABBIT" environment variable with a default value of
+ # false
+ skip_rabbit = os.getenv("SKIP_RABBIT", False)
+
+ # Convert our string into a boolean
+ skip_rabbit = skip_rabbit.lower() in ["true", "t", "y", "1"]
+
+ logger.debug("SKIP_RABBIT set to: " + skip_rabbit)
+
+ if skip_rabbit:
+ # Rabbit settings
exchange = 'topic-poseidon-internal'
exchange_type = 'topic'
- connection = pika.BlockingConnection(pika.ConnectionParameters(
- host='rabbit'))
+
+ # Starting rabbit connection
+ connection = pika.BlockingConnection(
+ pika.ConnectionParameters(host='rabbit')
+ )
+
channel = connection.channel()
- channel.exchange_declare(exchange=exchange,
- exchange_type=exchange_type)
+ channel.exchange_declare(
+ exchange=exchange, exchange_type=exchange_type
+ )
routing_key = 'poseidon.algos.decider'
- message = json.dumps(decision)
channel.basic_publish(exchange=exchange,
routing_key=routing_key,
body=message)
- print("Routing key: " + routing_key)
- print("Exchange: " + exchange)
+ logger.debug("Routing key: " + routing_key)
+ logger.debug("Exchange: " + exchange)
connection.close()
+ else:
+ # Skipping rabbit. Printing to STDOUT
+ logger.info("Message: " + message)
