Exemplo n.º 1
0
import pika
import os
import logging
import random
import time
import config_resolver
import rabbitmq_api_utils

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

config = config_resolver.ConfigResolver(logger)
server_config = config.load_server_config()

logger.info("Parse URL (fallback to localhost)...")
url = os.environ.get(
    'URL', 'amqp://{}:{}@{}:{}/{}'.format(server_config['user'],
                                          server_config['password'],
                                          server_config['host'],
                                          server_config['amqp-port'],
                                          server_config['vhost']))
logger.info(url)
params = pika.URLParameters(url)
params.socket_timeout = 5

# Connect to CloudAMQP
connection = pika.BlockingConnection(params)

# start a channel
channel = connection.channel()
Exemplo n.º 2
0
import os
import logging
import json
import rabbitmq_api_utils
import config_resolver

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

blue_config = config_resolver.ConfigResolver(logger)
blue_server_config = blue_config.load_server_config('blue')

blue_url = os.environ.get(
    'URL', 'amqp://{}:{}@{}:{}'.format(blue_server_config['user'],
                                       blue_server_config['password'],
                                       blue_server_config['host'],
                                       blue_server_config['amqp-port']))

logger.info("Blue URL: {}".format(blue_url))

green_config = config_resolver.ConfigResolver(logger)
green_server_config = green_config.load_server_config('green')

green_url = os.environ.get(
    'URL', 'amqp://{}:{}@{}:{}'.format(green_server_config['user'],
                                       green_server_config['password'],
                                       green_server_config['host'],
                                       green_server_config['amqp-port']))

logger.info("Green URL: {}".format(green_url))