def main():
    import gites.calendar.scripts
    parseZCML(gites.calendar.scripts, 'calendar_import.zcml')
    pg = getUtility(IDatabase, 'postgres')
    pg.session
    initialize_declarative_mappers(DeclarativeBase, pg.metadata)
    initialize_defered_mappers(pg.metadata)
    WalhebConsumingServer('walhebcalendar', '')
    connect_all()
    asyncore.loop()
示例#2
0
    def testNoQueues(self):
        from collective.zamqp import connection
        connection.connect_all()

        from zope.testing.loggingsupport import InstalledHandler
        handler = InstalledHandler("collective.zamqp")

        import asyncore
        asyncore.loop(timeout=1, count=10)
        for record in handler.records: print record.getMessage()

        rabbitctl = self.layer['rabbitctl']
        self.assertIn("my.queue\t0", rabbitctl('list_queues')[0].split("\n"))
示例#3
0
def connect_all_without_reload(self):
    """Connect all IBrokerConnections when sauna.reload is disabled"""
    if not reload_paths:
        connect_all()
示例#4
0
def connect_all_with_reload(self):
    """Connect all IBrokerConnections when sauna.reload is enabled"""
    if reload_paths:
        connect_all()
示例#5
0
    def setUp(self):

        # Enable trace
        if self.trace_on:
            self['rabbitctl']('trace_on')

        # Define dummy request handler to replace ZPublisher

        def handler(app, request, response):
            from zope.event import notify
            from zope.component import createObject
            message = request.environ.get('AMQP_MESSAGE')
            event = createObject('AMQPMessageArrivedEvent', message)
            notify(event)

        # Define ZPublisher-based request handler to be used with zserver

        def zserver_handler(app, request, response):
            from ZPublisher import publish_module
            publish_module(app, request=request, response=response)

        # Create connections and consuming servers for registered
        # producers and consumers

        from zope.interface import Interface
        from zope.component import getSiteManager
        from collective.zamqp.interfaces import (IBrokerConnection, IProducer,
                                                 IConsumer,
                                                 IMessageArrivedEvent)
        from collective.zamqp.connection import BrokerConnection
        from collective.zamqp.server import ConsumingServer
        from collective.zamqp.producer import Producer
        from collective.zamqp.consumer import Consumer

        sm = getSiteManager()

        connections = []
        consuming_servers = []

        for producer in sm.getAllUtilitiesRegisteredFor(IProducer):
            if not producer.connection_id in connections:
                connection = BrokerConnection(producer.connection_id,
                                              port=self['rabbit'].config.port)
                sm.registerUtility(connection,
                                   provided=IBrokerConnection,
                                   name=connection.connection_id)
                connections.append(connection.connection_id)

                # generate default producer with the name of the connection
                producer = Producer(connection.connection_id,
                                    exchange="",
                                    routing_key="",
                                    durable=False,
                                    auto_declare=False)
                sm.registerUtility(producer,
                                   provided=IProducer,
                                   name=connection.connection_id)

        # Register Firehose
        if self.trace_on:

            class IFirehoseMessage(Interface):
                """Marker interface for firehose message"""

            def handleFirehoseMessage(message, event):
                print message.method_frame
                print message.header_frame
                print message.body
                message.ack()

            consumer = Consumer("amq.rabbitmq.trace",
                                exchange="amq.rabbitmq.trace",
                                queue="",
                                routing_key="#",
                                durable=False,
                                auto_declare=True,
                                marker=IFirehoseMessage)

            sm.registerUtility(consumer,
                               provided=IConsumer,
                               name="amq.rabbitmq.trace")

            sm.registerHandler(handleFirehoseMessage,
                               (IFirehoseMessage, IMessageArrivedEvent))

        for consumer in sm.getAllUtilitiesRegisteredFor(IConsumer):
            if not consumer.connection_id in connections:
                connection = BrokerConnection(consumer.connection_id,
                                              port=self['rabbit'].config.port)
                sm.registerUtility(connection,
                                   provided=IBrokerConnection,
                                   name=connection.connection_id)
                connections.append(connection.connection_id)

                # generate default producer with the name of the connection
                producer = Producer(connection.connection_id,
                                    exchange="",
                                    routing_key="",
                                    durable=False,
                                    auto_declare=False)
                sm.registerUtility(producer,
                                   provided=IProducer,
                                   name=connection.connection_id)

            if not consumer.connection_id in consuming_servers:
                if self.zserver:
                    ConsumingServer(
                        consumer.connection_id,
                        'plone',
                        user_id=self.user_id,
                        handler=zserver_handler,
                        hostname='nohost',  # taken from z2.Startup
                        port=80,
                        use_vhm=False)
                else:
                    ConsumingServer(consumer.connection_id,
                                    'plone',
                                    user_id=self.user_id,
                                    handler=handler,
                                    use_vhm=False)
                consuming_servers.append(consumer.connection_id)

            # generate default producer with the name of the connection
            producer = Producer(connection.connection_id,
                                exchange="",
                                routing_key="",
                                durable=False,
                                auto_declare=False)
            sm.registerUtility(producer,
                               provided=IProducer,
                               name=connection.connection_id)

        # Connect all connections

        from collective.zamqp import connection
        connection.connect_all()
示例#6
0
    def setUp(self):

        # Enable trace
        if self.trace_on:
            self['rabbitctl']('trace_on')

        # Define dummy request handler to replace ZPublisher

        def handler(app, request, response):
            from zope.event import notify
            from zope.component import createObject
            message = request.environ.get('AMQP_MESSAGE')
            event = createObject('AMQPMessageArrivedEvent', message)
            notify(event)

        # Define ZPublisher-based request handler to be used with zserver

        def zserver_handler(app, request, response):
            from ZPublisher import publish_module
            publish_module(app, request=request, response=response)

        # Create connections and consuming servers for registered
        # producers and consumers

        from zope.interface import Interface
        from zope.component import getSiteManager
        from collective.zamqp.interfaces import (
            IBrokerConnection,
            IProducer,
            IConsumer,
            IMessageArrivedEvent
        )
        from collective.zamqp.connection import BrokerConnection
        from collective.zamqp.server import ConsumingServer
        from collective.zamqp.producer import Producer
        from collective.zamqp.consumer import Consumer

        sm = getSiteManager()

        connections = []
        consuming_servers = []

        for producer in sm.getAllUtilitiesRegisteredFor(IProducer):
            if not producer.connection_id in connections:
                connection = BrokerConnection(producer.connection_id,
                                              port=self['rabbit'].config.port)
                sm.registerUtility(connection, provided=IBrokerConnection,
                                   name=connection.connection_id)
                connections.append(connection.connection_id)

                # generate default producer with the name of the connection
                producer = Producer(connection.connection_id, exchange="",
                                    routing_key="", durable=False,
                                    auto_declare=False)
                sm.registerUtility(producer, provided=IProducer,
                                   name=connection.connection_id)

        # Register Firehose
        if self.trace_on:
            class IFirehoseMessage(Interface):
                """Marker interface for firehose message"""

            def handleFirehoseMessage(message, event):
                print message.method_frame
                print message.header_frame
                print message.body
                message.ack()

            consumer = Consumer("amq.rabbitmq.trace",
                                exchange="amq.rabbitmq.trace",
                                queue="", routing_key="#", durable=False,
                                auto_declare=True, marker=IFirehoseMessage)

            sm.registerUtility(consumer, provided=IConsumer,
                               name="amq.rabbitmq.trace")

            sm.registerHandler(
                handleFirehoseMessage,
                (IFirehoseMessage, IMessageArrivedEvent))

        for consumer in sm.getAllUtilitiesRegisteredFor(IConsumer):
            if not consumer.connection_id in connections:
                connection = BrokerConnection(consumer.connection_id,
                                              port=self['rabbit'].config.port)
                sm.registerUtility(connection, provided=IBrokerConnection,
                                   name=connection.connection_id)
                connections.append(connection.connection_id)

                # generate default producer with the name of the connection
                producer = Producer(connection.connection_id, exchange="",
                                    routing_key="", durable=False,
                                    auto_declare=False)
                sm.registerUtility(producer, provided=IProducer,
                                   name=connection.connection_id)

            if not consumer.connection_id in consuming_servers:
                if self.zserver:
                    ConsumingServer(consumer.connection_id, 'plone',
                                    user_id=self.user_id,
                                    handler=zserver_handler,
                                    hostname='nohost',  # taken from z2.Startup
                                    port=80,
                                    use_vhm=False)
                else:
                    ConsumingServer(consumer.connection_id, 'plone',
                                    user_id=self.user_id,
                                    handler=handler,
                                    use_vhm=False)
                consuming_servers.append(consumer.connection_id)

        # Connect all connections

        from collective.zamqp import connection
        connection.connect_all()
示例#7
0
    def setUpZope(self, app, configurationContext):
        # Load ZCML
        import edeposit.policy
        import edeposit.user
        import edeposit.content
        import plone.app.versioningbehavior
        import collective.oaiintercom
        xmlconfig.file('configure.zcml',
                       edeposit.content,
                       context=configurationContext)
        xmlconfig.file('configure.zcml',
                       edeposit.user,
                       context=configurationContext)
        xmlconfig.file('configure.zcml',
                       edeposit.policy,
                       context=configurationContext)
        xmlconfig.file('configure.zcml',
                       plone.app.versioningbehavior,
                       context=configurationContext)
        xmlconfig.file('configure.zcml',
                       collective.oaiintercom,
                       context=configurationContext)

        # import collective.pfg.dexterity
        # self.loadZCML(package=collective.pfg.dexterity)
        # z2.installProduct(app, "Products.PloneFormGen")
        # z2.installProduct(app, "Products.DataGridField")
        # z2.installProduct(app, "collective.pfg.dexterity")

        # Define dummy request handler to replace ZPublisher

        def handler(app, request, response):
            from zope.event import notify
            from zope.component import createObject
            message = request.environ.get('AMQP_MESSAGE')
            event = createObject('AMQPMessageArrivedEvent', message)
            notify(event)

        # Define ZPublisher-based request handler to be used with zserver

        def zserver_handler(app, request, response):
            from ZPublisher import publish_module
            publish_module(app, request=request, response=response)

        # Create connections and consuming servers for registered
        # producers and consumers
        sm = getSiteManager()

        connections = []
        consuming_servers = []

        for producer in sm.getAllUtilitiesRegisteredFor(IProducer):
            if not producer.connection_id in connections:
                connection = BrokerConnection(
                    producer.connection_id,
                    virtual_host=producer.connection_id,
                )
                sm.registerUtility(connection,
                                   provided=IBrokerConnection,
                                   name=connection.connection_id)
                connections.append(connection.connection_id)

        for consumer in sm.getAllUtilitiesRegisteredFor(IConsumer):
            if not consumer.connection_id in connections:
                connection = BrokerConnection(
                    consumer.connection_id, virtual_host=consumer.consumer_id)
                sm.registerUtility(connection,
                                   provided=IBrokerConnection,
                                   name=connection.connection_id)
                connections.append(connection.connection_id)

            if not consumer.connection_id in consuming_servers:
                if self.zserver:
                    ConsumingServer(
                        consumer.connection_id,
                        'plone',
                        user_id=self.user_id,
                        handler=zserver_handler,
                        hostname='nohost',  # taken from z2.Startup
                        port=80,
                        use_vhm=False)
                else:
                    ConsumingServer(consumer.connection_id,
                                    'plone',
                                    user_id=self.user_id,
                                    handler=handler,
                                    use_vhm=False)
                consuming_servers.append(consumer.connection_id)

        # Connect all connections

        from collective.zamqp import connection
        connection.connect_all()
示例#8
0
    def setUpZope(self, app, configurationContext):
        # Load ZCML
        import edeposit.policy
        import edeposit.user
        import edeposit.content
        import plone.app.versioningbehavior
        import collective.oaiintercom
        xmlconfig.file('configure.zcml', edeposit.content, context=configurationContext) 
        xmlconfig.file('configure.zcml', edeposit.user, context=configurationContext)
        xmlconfig.file('configure.zcml', edeposit.policy, context=configurationContext)
        xmlconfig.file('configure.zcml', plone.app.versioningbehavior, context=configurationContext)
        xmlconfig.file('configure.zcml', collective.oaiintercom, context=configurationContext)

        # import collective.pfg.dexterity
        # self.loadZCML(package=collective.pfg.dexterity)
        # z2.installProduct(app, "Products.PloneFormGen")
        # z2.installProduct(app, "Products.DataGridField")
        # z2.installProduct(app, "collective.pfg.dexterity")

        # Define dummy request handler to replace ZPublisher

        def handler(app, request, response):
            from zope.event import notify
            from zope.component import createObject
            message = request.environ.get('AMQP_MESSAGE')
            event = createObject('AMQPMessageArrivedEvent', message)
            notify(event)

        # Define ZPublisher-based request handler to be used with zserver

        def zserver_handler(app, request, response):
            from ZPublisher import publish_module
            publish_module(app, request=request, response=response)

        # Create connections and consuming servers for registered
        # producers and consumers
        sm = getSiteManager()

        connections = []
        consuming_servers = []

        for producer in sm.getAllUtilitiesRegisteredFor(IProducer):
            if not producer.connection_id in connections:
                connection = BrokerConnection(producer.connection_id,
                                              virtual_host=producer.connection_id,
                )
                sm.registerUtility(connection, provided=IBrokerConnection,
                                   name=connection.connection_id)
                connections.append(connection.connection_id)

        for consumer in sm.getAllUtilitiesRegisteredFor(IConsumer):
            if not consumer.connection_id in connections:
                connection = BrokerConnection(consumer.connection_id,
                                              virtual_host=consumer.consumer_id
                )
                sm.registerUtility(connection, provided=IBrokerConnection,
                                   name=connection.connection_id)
                connections.append(connection.connection_id)

            if not consumer.connection_id in consuming_servers:
                if self.zserver:
                    ConsumingServer(consumer.connection_id, 'plone',
                                    user_id=self.user_id,
                                    handler=zserver_handler,
                                    hostname='nohost',  # taken from z2.Startup
                                    port=80,
                                    use_vhm=False)
                else:
                    ConsumingServer(consumer.connection_id, 'plone',
                                    user_id=self.user_id,
                                    handler=handler,
                                    use_vhm=False)
                consuming_servers.append(consumer.connection_id)

        # Connect all connections

        from collective.zamqp import connection
        connection.connect_all()