def preparer_connexion(self):
        connection_parameters = {
            'host': self.configuration.mq_host,
            'port': self.configuration.mq_port,
            'virtual_host': self.configuration.idmg,
            'heartbeat': 300
        }

        credentials = {
            'username': self.configuration.mq_user,
            'password': self.configuration.mq_password,
            'erase_on_connect': True
        }
        connection_parameters['credentials'] = PlainCredentials(**credentials)

        if self.configuration.mq_ssl == 'on':
            # verify_mode = ssl.CERT_NONE
            # server_hostname = None
            ssl_options = {
                'ssl_version': ssl.PROTOCOL_TLSv1_2,
                'keyfile':
                '/usr/local/etc/millegrilles/certs/keys/think003.pivoine.mdugre.info.pem',
                'certfile':
                '/usr/local/etc/millegrilles/certs/think003.pivoine.mdugre.info.cert.pem',
                'ca_certs':
                '/usr/local/etc/millegrilles/certs/millegrilles.authority.pem',
                'cert_reqs': ssl.CERT_REQUIRED
            }

            connection_parameters['ssl'] = True
            connection_parameters['ssl_options'] = ssl_options

        return connection_parameters
Exemple #2
0
    def __init__(self,
                 host='localhost',
                 port=5672,
                 login='******',
                 password='******',
                 virtual_host='/',
                 loop=None,
                 **kwargs):

        self.loop = loop if loop else ioloop.IOLoop.current()
        self.future_store = common.FutureStore(loop=self.loop)

        self.__credentials = PlainCredentials(
            login, password) if login else ExternalCredentials()

        self.__connection_parameters = ConnectionParameters(
            host=host,
            port=port,
            credentials=self.__credentials,
            virtual_host=virtual_host,
            **kwargs)

        self._channels = dict()
        self._connection = None
        self.__closing = None
        self.__close_started = False
        self.__write_lock = locks.Lock()
Exemple #3
0
    def setup(self):
        self.queues = None
        self.conn = None
        self.channel = None

        self.username = self._config['sensor_config']['username']
        self.password = self._config['sensor_config']['password']
        self.queues = self._config['sensor_config']['queues']
        self.host = self._config['sensor_config']['host']
        self.deserialization_method = self._config['sensor_config'][
            'deserialization_method']

        supported_methods = DESERIALIZATION_FUNCTIONS.keys()
        if self.deserialization_method and self.deserialization_method not in supported_methods:
            raise ValueError('Invalid deserialization method specified: %s' %
                             (self.deserialization_method))

        if self.username and self.password:
            credentials = PlainCredentials(username=self.username,
                                           password=self.password)
            connection_params = pika.ConnectionParameters(
                host=self.host, credentials=credentials)
        else:
            connection_params = pika.ConnectionParameters(host=self.host)

        self.conn = pika.BlockingConnection(connection_params)
        self.channel = self.conn.channel()
        self.channel.basic_qos(prefetch_count=1)
    def __init__(self,
                 appname,
                 appclass,
                 host='localhost',
                 user='******',
                 password='******'):
        """Create a new instance of the consumer class, passing in the AMQP
        URL used to connect to RabbitMQ.

        """

        self._conn_params = pika.ConnectionParameters(
            host=host,
            credentials=PlainCredentials(user, password),
            heartbeat_interval=60)

        self.appname = appname
        self.appclass = appclass

        self.listen_callback = None

        self._connection = None
        self._channel = None
        self._closing = False
        self._consumer_tag = None
Exemple #5
0
    def __init__(self,
                 host: str = 'localhost',
                 port: int = 5672,
                 login: str = 'guest',
                 password: str = 'guest',
                 virtual_host: str = '/',
                 ssl: bool = False,
                 *,
                 loop=None,
                 **kwargs):

        self.loop = loop if loop else asyncio.get_event_loop()
        self.future_store = FutureStore(loop=self.loop)

        self.__credentials = PlainCredentials(login,
                                              password) if login else None

        self.__connection_parameters = ConnectionParameters(
            host=host,
            port=port,
            credentials=self.__credentials,
            virtual_host=virtual_host,
            ssl=ssl,
            **kwargs)

        self._channels = dict()
        self._connection = None
        self.__closing = None
        self.__write_lock = asyncio.Lock(loop=self.loop)
Exemple #6
0
    def __init__(self,
                 username: str = "",
                 password: str = "",
                 url: str = "",
                 prefetch_count: int = -2):
        if 'sphinx' in sys.modules:
            return  # don't load when sphinx is running
        if username == "":
            username = os.environ.get("RABBITMQ_DEFAULT_USER")
        if password == "":
            password = os.environ.get("RABBITMQ_DEFAULT_PASS")
        if url == "":
            url = os.environ.get("RABBITMQ_URL", "localhost")
        if prefetch_count == -2:
            self.prefetch_count = int(os.environ.get("PREFETCH_COUNT", 500))

        credentials = PlainCredentials(username=username, password=password)

        virtual_host = os.environ.get("RABBITMQ_DEFAULT_VHOST")
        params = pika.ConnectionParameters(host=url,
                                           port=5672,
                                           virtual_host=virtual_host,
                                           credentials=credentials,
                                           connection_attempts=10,
                                           retry_delay=10)

        self.connection = pika.BlockingConnection(parameters=params)
        self.channel = self.connection.channel()
Exemple #7
0
def main():
    args = get_arguments()

    credentials = None
    if args.username and args.password:
        credentials = PlainCredentials(args.username, args.password)

    parameters = ConnectionParameters(host=args.host,
                                      port=args.port,
                                      credentials=credentials)

    connection = BlockingConnection(parameters)
    channel = connection.channel()
    response = channel.queue_declare(exclusive=True, auto_delete=True)
    queue = response.method.queue

    channel.queue_bind(exchange=args.exchange,
                       queue=queue,
                       routing_key=args.routing_key)

    channel.basic_consume(on_message, queue)

    try:
        channel.start_consuming()
    except KeyboardInterrupt:
        channel.stop_consuming()
    connection.close()
Exemple #8
0
    def __init__(self):
        # create RabbitMQ broker
        self.broker = RabbitmqBroker(host=settings.MESSAGE_QUEUE_HOST,
                                     port=settings.MESSAGE_QUEUE_PORT,
                                     credentials=PlainCredentials(username=settings.MESSAGE_QUEUE_USERNAME,
                                                                  password=settings.MESSAGE_QUEUE_PASSWORD))

        # set the broker as default
        set_broker(self.broker)
 def __init__(self, config: ConsumerConfig):
     super(ParseConsumer, self).__init__(
         ConnectionParameters(
             host=config.host,
             port=config.port,
             credentials=PlainCredentials(config.user, config.password),
             connection_attempts=3,
             heartbeat_interval=20,
         ))
     self.config = config
Exemple #10
0
    def consume(self):
        connection = pika.BlockingConnection(
            pika.ConnectionParameters(host=self.host,
                                      port=self.port,
                                      credentials=PlainCredentials(
                                          self.username, self.password)))

        channel = connection.channel()
        channel.queue_declare(queue=self.queue, durable=True)
        channel.basic_consume(self.callback, self.queue)
        channel.start_consuming()
 def __init__(self, config: dict = None, ctx=None):
     self.context = ctx
     self.name = "RabbitMQ Service"
     self.retrycount = 1
     self.host = config["environment"]["rabbit"]["host"]
     credentials = PlainCredentials(
         config["environment"]["rabbit"]["username"],
         config["environment"]["rabbit"]["password"],
     )
     self.connection_params = pika.ConnectionParameters(
         host=self.host, credentials=credentials,
     )
Exemple #12
0
    def __init__(self, config: DumpConfig):
        self.EXCHANGE = config.queue
        self.QUEUE = config.queue
        self.ROUTING_KEY = config.queue

        super(Dumper, self).__init__(
            ConnectionParameters(
                host=config.host,
                port=config.port,
                credentials=PlainCredentials(config.user, config.password),
                connection_attempts=3,
                heartbeat_interval=60,
            ))
Exemple #13
0
    def get_channel():
        config = ConfigParser()
        config.read("python/configs/config.ini")

        connection = BlockingConnection(
            ConnectionParameters(host=config.get("RABBIT", "host"),
                                 port=config.get("RABBIT", "port"),
                                 credentials=PlainCredentials(
                                     username=config.get("RABBIT", "user"),
                                     password=config.get("RABBIT", "pass")),
                                 heartbeat=0))

        channel = connection.channel(1)
        channel.basic_qos(prefetch_count=1)

        return channel
Exemple #14
0
def create_publisher(host, port, username, password, exchange, exchange_type,
                     durable, auto_delete, routing_key):
    credentials = None
    if username and password:
        credentials = PlainCredentials(username, password)

    return RabbitMQPublisher(
        host=host,
        port=port,
        credentials=credentials,
        exchange=exchange,
        routing_key=routing_key,
        exchange_type=exchange_type,
        durable=durable,
        auto_delete=auto_delete
    )
Exemple #15
0
def make_node(connection_params=None, name=None, timeout=None):
    """
    Blocking construction and connection of node.

    @param connection_params  AMQP connection parameters. By default, uses CFG.server.amqp (most common use).
    """
    log.debug("In make_node")
    node = NodeB()
    connection_params = connection_params or CFG.server.amqp
    credentials = PlainCredentials(connection_params["username"], connection_params["password"])
    conn_parameters = ConnectionParameters(host=connection_params["host"], virtual_host=connection_params["vhost"], port=connection_params["port"], credentials=credentials)
    connection = PyonSelectConnection(conn_parameters , node.on_connection_open)
    ioloop_process = gevent.spawn(ioloop, connection, name=name)
    #ioloop_process = gevent.spawn(connection.ioloop.start)
    node.ready.wait(timeout=timeout)
    return node, ioloop_process
Exemple #16
0
 def __init__(self, state):
     self.state = state
     credentials = PlainCredentials(
         RabbitMQConfiguration().getRabbitMQProperty(
             "gameLogicServerUserName"),
         RabbitMQConfiguration().getRabbitMQProperty(
             "gameLogicServerUserName"))
     parameters = pika.ConnectionParameters(
         host=RabbitMQConfiguration().getRabbitMQProperty(
             "gameLogicServerBrokerHost"),
         virtual_host=self.state.vhost,
         credentials=credentials)
     # instantiate a connection
     logging.debug("GameLogicServer] WorkerChannel - Starting a connection")
     self.connection = pika.BlockingConnection(parameters=parameters)
     logging.debug("GameLogicServer] WorkerChannel - Creating a channel")
     self.channel = self.connection.channel()
Exemple #17
0
def check_integration(status):
    """
    Check the Integration MQ status
    :param status:
    :return:
    """
    conn = pika.BlockingConnection(
        pika.ConnectionParameters(
            host="ec2-18-197-180-1.eu-central-1.compute.amazonaws.com",
            virtual_host="vhost",
            credentials=PlainCredentials("rabbitmq", "rabbitmq")
        )
    )

    channel = conn.channel()

    status['mq-integration'] = channel.is_open
Exemple #18
0
    def __init__(self):
        self.uptime = 0
        self.index_count = 0

        self.connection = pika.BlockingConnection(
            pika.ConnectionParameters(
                host='localhost',
                port=5672,
                credentials=PlainCredentials(username='******',
                                             password='******')))

        self.channel = self.connection.channel()
        self.channel.queue_declare(queue='ipfs', durable=True)
        logging.info("Attached to queue ipfs")

        self.cache = redis.Redis(host='localhost', port=6379, db=10)
        logging.info("Connected to Redis")
Exemple #19
0
def send_message(host, port, vhost, username, password, exchange, routing_key, queue, topic_type, message):
    connection = pika.BlockingConnection(pika.ConnectionParameters(
        host=host,
        port=int(port),
        virtual_host=vhost,
        credentials=PlainCredentials(username, password)
    ))
    channel = connection.channel()
    if queue is not None and topic_type is not None:
        channel.exchange_declare(exchange=exchange,exchange_type=topic_type)
        channel.queue_declare(queue=queue, durable=True)
        channel.queue_bind(queue=queue, exchange=exchange, routing_key=routing_key)
    channel.basic_publish(exchange=exchange, routing_key=routing_key, body=message,
                          properties=pika.BasicProperties(delivery_mode=2))
    time.sleep(2)
    connection.close()
    logging.info("Message published to: " + exchange + "/" + routing_key)
Exemple #20
0
 def start(self):
     # parameters require for the AMQP connection: user name and password...
     credentials = PlainCredentials(
         RabbitMQConfiguration().getRabbitMQProperty(
             "gameLogicServerUserName"),
         RabbitMQConfiguration().getRabbitMQProperty(
             "gameLogicServerUserName"))
     parameters = pika.ConnectionParameters(
         host=RabbitMQConfiguration().getRabbitMQProperty(
             "gameLogicServerBrokerHost"),
         virtual_host=self.state.vhost,
         credentials=credentials)
     # instantiate a connection
     connection = SelectConnection(parameters=parameters,
                                   on_open_callback=self.on_connected)
     # required behavior on close
     connection.add_on_close_callback(self.on_close)
     # start the connection
     connection.ioloop.start()
Exemple #21
0
    def setup(self):
        if self.username and self.password:
            credentials = PlainCredentials(username=self.username, password=self.password)
            connection_params = pika.ConnectionParameters(host=self.host, credentials=credentials)
        else:
            connection_params = pika.ConnectionParameters(host=self.host)

        self.conn = pika.BlockingConnection(connection_params)
        self.channel = self.conn.channel()
        self.channel.basic_qos(prefetch_count=1)

        # Setup Qs for listening
        for queue in self.queues:
            self.channel.queue_declare(queue=queue, durable=True)

            def callback(ch, method, properties, body):
                self._dispatch_trigger(ch, method, properties, body, queue)

            self.channel.basic_consume(callback, queue=queue)
Exemple #22
0
 def __init__(self, host, port, username, password, exchange, topic_type,
              queue, routing_key):
     logging.info("Connecting to Rabbit MQ")
     self.connection = pika.BlockingConnection(
         pika.ConnectionParameters(host=host,
                                   port=port,
                                   credentials=PlainCredentials(
                                       username, password)))
     self.exchange = exchange
     self.routing_key = routing_key
     logging.info("Initiating Channel")
     self.connection_attempts = 50
     self.retry_delay = 10000
     self.channel = self.connection.channel()
     self.channel.exchange_declare(exchange=exchange, type=topic_type)
     self.channel.queue_declare(queue=queue)
     self.channel.queue_bind(queue=queue,
                             exchange=exchange,
                             routing_key=routing_key)
Exemple #23
0
def createLoggingServer(gameName, instanceName):
    logging.info("GameLogicServer] Creating Logging server for " + gameName +
                 " " + instanceName)
    vhost = RabbitMQConfiguration().getRabbitMQProperty(
        "virtualHostSeparator") + gameName + RabbitMQConfiguration(
        ).getRabbitMQProperty("virtualHostSeparator") + instanceName
    credentials = PlainCredentials(
        RabbitMQConfiguration().getRabbitMQProperty("loggingServerUserName"),
        RabbitMQConfiguration().getRabbitMQProperty("loggingServerUserName"))
    parameters = pika.ConnectionParameters(
        host=RabbitMQConfiguration().getRabbitMQProperty(
            "gameLogicServerBrokerHost"),
        virtual_host=vhost,
        credentials=credentials)
    logging.debug("LoggingServer] Starting a connection")
    connection = pika.BlockingConnection(parameters=parameters)
    logging.debug("LoggingServer] Creating a channel")
    channel = connection.channel()
    logging.debug(
        "LoggingServer] Declaring a queue " +
        RabbitMQConfiguration().getRabbitMQProperty("loggingServerQueueName"))
    channel.queue_declare(queue=RabbitMQConfiguration().getRabbitMQProperty(
        "loggingServerQueueName"),
                          exclusive=False,
                          durable=True)
    logging.debug(
        "LoggingServer] Binding the queue with the rooting key " +
        RabbitMQConfiguration().getRabbitMQProperty("loggingServerBindingKey"))
    channel.queue_bind(exchange=RabbitMQConfiguration().getRabbitMQProperty(
        "gameLogicServerExchangeName"),
                       queue=RabbitMQConfiguration().getRabbitMQProperty(
                           "loggingServerQueueName"),
                       routing_key=RabbitMQConfiguration().getRabbitMQProperty(
                           "loggingServerBindingKey"))
    channel.basic_consume(consumer_callback=handle_delivery_loggingserver,
                          queue=RabbitMQConfiguration().getRabbitMQProperty(
                              "loggingServerQueueName"),
                          no_ack=True)
    logging.info(" LoggingServer] Waiting for messages on " + vhost)
    channel.start_consuming()
    logging.info("LoggingServer] Process terminated")
Exemple #24
0
 def __init__(self,
              host,
              port=5672,
              user_name="admin",
              password="******",
              connection_attempts=3,
              heartbeat_interval=60 * 60,
              channel_max=200,
              virtual_host="/",
              ssl=False):
     """
     connect to rabbit mq
     :param str host: Hostname or IP Address to connect to
     :param int port: TCP port to connect to
     :param str user_name: default is guest
     :param str password:  default is guest
     :param int connection_attempts: Maximum number of retry attempts
     :param int heartbeat_interval: How often to send heartbeats.
                                   Min between this value and server's proposal
                                   will be used. Use 0 to deactivate heartbeats
                                   and None to accept server's proposal.
     :param int channel_max: Maximum number of channels to allow
     :param str virtual_host: RabbitMQ virtual host to use
     :param bool ssl: Enable SSL
     :return:
 """
     self.host = host
     self.port = port
     self.connection_attempts = connection_attempts
     self.channel_max = channel_max
     self.heartbeat_interval = heartbeat_interval
     self.credentials = PlainCredentials(username=user_name,
                                         password=password)
     self.virtual_host = virtual_host
     self.ssl = ssl
     self.__connection = self.__connection_rabbit()
     self.__channel_single = self.__connection.channel()
     self.__channel_work_queue = self.__connection.channel()
     self.__channel_subscribe = self.__connection.channel()
     self.__channel_routing = self.__connection.channel()
     self.__channel_topics = self.__connection.channel()
Exemple #25
0
    def _amqp_conn_params(self):

        vhost = self.def_amqp.virtual_host if 'virtual_host' in self.def_amqp else self.def_amqp.vhost
        if 'credentials' in self.def_amqp:
            username = self.def_amqp.credentials.username
            password = self.def_amqp.credentials.password
        else:
            username = self.def_amqp.username
            password = self.def_amqp.password

        params = ConnectionParameters(self.def_amqp.host,
                                      int(self.def_amqp.port),
                                      vhost,
                                      PlainCredentials(username, password),
                                      frame_max=int(self.def_amqp.frame_max))

        # heartbeat is an integer but ConnectionParameter.__init__ insists it
        # be a boolean.
        params.heartbeat = float(self.def_amqp.heartbeat)

        return params
Exemple #26
0
def check_mq(url, user, pw):
    """
    Check status of MQ server
    :param url:
    :return:
    """
    ret = {}
    conn = pika.BlockingConnection(
        pika.ConnectionParameters(
            host=url,
            virtual_host="vhost",
            credentials=PlainCredentials("rabbitmq", "rabbitmq")
        )
    )

    channel = conn.channel()

    ret['up'] = channel.is_open
    ret['waiting_count'] = channel.get_waiting_message_count()

    return ret
Exemple #27
0
    def connecter(self):
        self._cnmaria = None
        self._cnmaria = mysql.connector.connect(user='******', password='******',
                                        host='192.168.1.28',
                                        database='lectmeteo',
                                        autocommit=True)

        credentials = PlainCredentials(
            'cuisine',
            'jojCUSH1956o',
            erase_on_connect=True
        )
        self._connectionmq = pika.BlockingConnection(
            pika.ConnectionParameters(
                host='192.168.1.28',
                port=5671,
                credentials=credentials,
                ssl=True  # Mettre SSL lorsque ca fonctionnera avec RabbitMQ
            )
        )
        self._channel = self._connectionmq.channel()
Exemple #28
0
    def init_app(self,
                 app: Flask,
                 use_ssl: bool = False,
                 body_parser: Callable = None):
        self.app = app
        self.config = app.config
        self.exchange_name = os.getenv('MQ_EXCHANGE')
        self.body_parser = body_parser
        self.getConnection = lambda: BlockingConnection(
            ConnectionParameters(
                host=os.getenv('MQ_HOST'),
                port=os.getenv('MQ_PORT'),
                credentials=PlainCredentials(username=os.getenv('MQ_USER'),
                                             password=os.getenv('MQ_PASS')),
                ssl_options=SSLOptions(ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)),
                heartbeat=300,
                blocked_connection_timeout=150))

        # Run every consumer queue
        for consumer in self.consumers:
            consumer()
Exemple #29
0
    def __init__(self, config: ConsumerConfig):
        super(PlayConsumer, self).__init__(
            ConnectionParameters(
                host=config.host,
                port=config.port,
                credentials=PlainCredentials(config.user, config.password),
                connection_attempts=3,
                heartbeat_interval=60,
            ))

        self.result_dir = config.result_dir

        self.game_args = GameArgs()
        self.game_args.game_type = config.game_type
        self.game_args.game_speed = config.game_speed
        self.game_args.timeout = config.timeout
        self.game_args.bot_dir = config.bot_dir
        self.game_args.game_dir = config.game_dir
        self.game_args.map_dir = config.map_dir
        self.game_args.bwapi_data_bwta_dir = config.bwapi_data_bwta_dir
        self.game_args.bwapi_data_bwta2_dir = config.bwapi_data_bwta2_dir
        self.game_args.read_overwrite = config.read_overwrite
        self.game_args.docker_image = config.docker_image
        self.game_args.random_names = config.random_names

        self.game_args.opt = config.opt

        self.game_args.human = False
        self.game_args.headless = True
        self.game_args.vnc_host = "localhost"
        self.game_args.vnc_base_port = 5900
        self.game_args.allow_input = False
        self.game_args.auto_launch = False
        self.game_args.plot_realtime = False
        self.game_args.hide_names = False
        self.game_args.capture_movement = False
        self.game_args.show_all = False
Exemple #30
0
def make_node(connection_params=None, name=None, timeout=None):
    """
    Blocking construction and connection of node.

    @param connection_params  AMQP connection parameters. By default, uses CFG.server.amqp (most common use).
    @return tuple of node and ioloop greenlet
    """
    log.debug("In make_node")
    node = NodeB()
    connection_params = connection_params or CFG.get_safe("server.amqp")
    credentials = PlainCredentials(connection_params["username"],
                                   connection_params["password"])
    conn_parameters = ConnectionParameters(
        host=connection_params["host"],
        virtual_host=connection_params["vhost"],
        port=connection_params["port"],
        credentials=credentials)
    connection = PyonSelectConnection(conn_parameters, node.on_connection_open)

    ioloop_gl = gevent.spawn(ioloop, connection, name=name)
    ioloop_gl._glname = "ScionCC AMQP ioloop"
    node.ready.wait(timeout=timeout)

    return node, ioloop_gl