コード例 #1
0
ファイル: __init__.py プロジェクト: kibora/geoburkin
    def ready(self):
        super(MessagingAppConfig, self).ready()

        from kombu import pools
        from kombu import BrokerConnection

        global connections
        global producers
        global url
        global task_serializer
        global broker_transport_options
        global broker_socket_timeout
        global connection

        connections = pools.Connections(limit=100)
        producers = pools.Producers(limit=connections.limit)

        # run in-memory if broker is not available
        # see producer code for synchronous queue
        url = getattr(settings, 'BROKER_URL', 'memory://')
        task_serializer = getattr(settings, 'CELERY_TASK_SERIALIZER', 'pickle')
        broker_transport_options = getattr(settings,
                                           'BROKER_TRANSPORT_OPTIONS',
                                           {'socket_timeout': 10})
        broker_socket_timeout = getattr(broker_transport_options,
                                        'socket_timeout', 10)
        connection = BrokerConnection(url,
                                      connect_timeout=broker_socket_timeout)
コード例 #2
0
    def setUpClass(cls):

        amqp_conf = Configuration.load(os.path.join('etc', 'amqp.conf'), Ini)
        cls.amqp_uri = 'amqp://{}:{}@{}:{}/{}'.format(
            amqp_conf['master']['userid'],
            amqp_conf['master']['password'],
            amqp_conf['master']['host'],
            amqp_conf['master']['port'],
            amqp_conf['master']['virtual_host']
        )

        cls.conn = Connection(cls.amqp_uri)
        cls.producers = pools.Producers(limit=1)
        cls.exchange_name = "canopsis"

        cls.amqp = Amqp(logging_level='INFO',
                        logging_name='Amqp')
        cls.amqp.producers = cls.producers
        cls.amqp.conn = cls.conn

        cls.event = {
            'connector': 'test_amqp',
            'connector_name': 'test_amqp',
            'source_type': 'resource',
            'event_type': 'check',
            'component': 'test',
            'resource': 'test'
        }
コード例 #3
0
    def connect(self):
        """
        Create the connection
        Inits the producers
        Init the only channel
        Declares exchanges
        """
        if not self.connected:
            self.logger.info("Connect to AMQP Broker (%s:%s)" %
                             (self.host, self.port))

            self.conn = Connection(self.amqp_uri)

            try:
                self.logger.debug(" + Connect")
                self.conn.connect()
                self.logger.info("Connected to AMQP Broker.")
                self.producers = pools.Producers(limit=10)
                self.connected = True
            except Exception as err:
                self.conn.release()
                self.logger.error("Impossible to connect ({})".format(err))

            if self.connected:
                self.logger.debug(" + Open channel")
                try:
                    self.chan = self.conn.channel()

                    self.logger.info("Channel openned. Ready to send messages")

                    try:
                        # Declare exchange
                        self.logger.debug("Declare exchanges")
                        for exchange_name in self.exchanges:
                            self.logger.debug(" + {}".format(exchange_name))
                            self.exchanges[exchange_name](self.chan).declare()
                    except Exception as err:
                        self.logger.error(
                            "Impossible to declare exchange ({})".format(err))

                except Exception as err:
                    self.logger.error(err)
        else:
            self.logger.debug("Already connected")
コード例 #4
0
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################
from django.conf import settings
from kombu import pools
from kombu import BrokerConnection

connections = pools.Connections(limit=100)
producers = pools.Producers(limit=connections.limit)

# run in-memory if broker is not available
# see producer code for synchronous queue
url = getattr(settings, 'BROKER_URL', 'memory://')
task_serializer = getattr(settings, 'CELERY_TASK_SERIALIZER', 'pickle')
broker_transport_options = getattr(settings, 'BROKER_TRANSPORT_OPTIONS',
                                   {'socket_timeout': 10})
broker_socket_timeout = getattr(broker_transport_options, 'socket_timeout', 10)
connection = BrokerConnection(url, connect_timeout=broker_socket_timeout)