Example #1
0
    def _reconnect(self):
        # Si ya esta conectado no reconecta
        if self._isConnected:
            return

        self._reconnectionNumber = 0
        self._reconnectionTimer.reset()
        self._isConnected = False

        while True:
            try:
                loggerManager.get_endPoints_logger().debug(
                    "Conectando al host: %s", self._host)
                self._connect_point()
                break
            except ConnectionError as ex:
                loggerManager.get_endPoints_logger().error(
                    "Error al conectar: %s" % ex)
                if self._maxReconnections != Channel.INFINITE_RECONNECTIONS and self._reconnectionNumber >= self._maxReconnections:
                    loggerManager.get_endPoints_logger().error(
                        "Se ha alcanzado el maximo numero de reconexiones")
                    raise ConnectionError(
                        "Se ha alcanzado el maximo numero de reconexiones")
                else:
                    loggerManager.get_endPoints_logger().error(
                        "Intentado reconectar... %d" %
                        self._reconnectionNumber)
                    self._reconnectionNumber += 1
                    self._reconnectionTimer.wait()
        self._isConnected = True
Example #2
0
 def _connect_point(self):
     try:
         self._create_socket()
         self._socket.bind((self._server, self._port))
         self._socket.listen(self._maxConnectionRequests)
     except Exception as ex:
         loggerManager.get_endPoints_logger().error(
             "Error al conectar con el host %s:%i" %
             (self._server, self._port))
         loggerManager.get_endPoints_logger().error("Socket de mierda: %s" %
                                                    self._socket.fileno)
         raise ConnectionError(ex)
Example #3
0
 def _send(self, message):
     try:
         messageProperties = pika.BasicProperties(content_type='text/plain',
                                                  delivery_mode=1,
                                                  content_encoding='utf-8')
         return self._channel.basic_publish(
             exchange=self._exchange,
             routing_key=self._key,
             body=unicode(message).encode('utf-8'),
             properties=messageProperties)
     except ConnectionClosed as ex:
         loggerManager.get_endPoints_logger().error("Error: %s" % ex)
         raise ConnectionError(
             "Se ha perdido la conexcion con el servidor AMPQ")
     except Exception as ex:
         loggerManager.get_endPoints_logger().error("Error: %s" % ex)
         raise SendError('Error al enviar el elemento %s' % ex)
Example #4
0
    def _connect_point(self):
        try:
            self._connection = pika.BlockingConnection(self._connectionParams)
            self._channel = self._connection.channel()

            self._channel.exchange_declare(exchange=self._exchange,
                                           durable=True,
                                           passive=True)
            self._channel.queue_declare(queue=self._queue,
                                        durable=True,
                                        arguments={"x-ha-policy": "all"})
            self._channel.queue_bind(queue=self._queue,
                                     exchange=self._exchange,
                                     routing_key=self._key)

        except Exception as ex:
            raise ConnectionError(ex)
Example #5
0
 def _connect_point(self):
     try:
         self._create_socket()
         self._socket.connect((self._server, self._port))
     except socket.error, msg:
         raise ConnectionError(msg)
Example #6
0
 def _close_point(self):
     raise ConnectionError("Error de conexion, clase base")