Beispiel #1
0
 def setUp(self):
     super(ConnectionConfigTestCase, self).setUp()
     self.user = "******"
     self.password = "******"
     self.credentials = config.Credentials(self.user, self.password)
     self.host = "host"
     self.config = config.ConnectionConfig(self.host, self.credentials)
Beispiel #2
0
 def setUp(self):
     super(AMQPDriverTestCase, self).setUp()
     self.user = "******"
     self.password = "******"
     self.credentials = config.Credentials(self.user, self.password)
     self.host = "host"
     self.conf = config.ConnectionConfig(self.host, self.credentials)
     self.driver = driver.AMQPDriver(self.conf)
Beispiel #3
0
 def test_driver_uses_pika_sync_engine(self):
     """
     Tests that driver uses sync amqp engine if async_engine parameter=False
      in config object
     """
     conf = config.ConnectionConfig(self.host, self.credentials)
     drvr = driver.AMQPDriver(conf)
     self.assertEqual(drvr._engine, pika_sync)
Beispiel #4
0
    def test_get_writer_for_sync_engine(self, engine_mock):
        """
        Tests that driver uses Writer of sync engine
        """

        conf = config.ConnectionConfig(self.host, self.credentials)
        drvr = driver.AMQPDriver(conf)
        writer = drvr.create_writer()
        self.assertEqual(writer, engine_mock())
Beispiel #5
0
    def test_get_reader_for_sync_engine(self, engine_mock):
        """
        Tests that driver uses Reader of sync engine
        """

        conf = config.ConnectionConfig(self.host, self.credentials)
        drvr = driver.AMQPDriver(conf)
        queue = "queue_name"
        preprocessor = mock.Mock()
        reader = drvr.create_reader(queue, preprocessor)
        self.assertEqual(reader, engine_mock())
Beispiel #6
0
def run_me():

    creds = config.Credentials("guest", "guest")
    conf = config.ConnectionConfig("localhost",
                                   credentials=creds,
                                   async_engine=True)

    srv = server.Server(conf,
                        queue_name="test_service",
                        exchange_name="test_exchange",
                        service_list=[HelloController, WorldController])
    srv.run()
Beispiel #7
0
    def __init__(self, config_file=None, project_name=None):
        configfile.get_config(sys.argv[1:],
                              project_name=project_name,
                              config_file=config_file)
        conf = configfile.CONF
        credentials = config.Credentials(username=conf.connection.username,
                                         password=conf.connection.password)
        ssl_opts = None
        if conf.ssl:
            ssl_opts = {
                "keyfile": conf.ssl.keyfile,
                "certfile": conf.ssl.certfile,
                "server_side": False,
                "cert_reqs": conf.ssl.cert_reqs,
                "ssl_version": conf.ssl.ssl_version,
                "ca_certs": conf.ssl.ca_certs,
                "suppress_ragged_eofs": conf.ssl.suppress_ragged_eofs,
                "ciphers": conf.ssl.ciphers,
            }
        conn_conf = config.ConnectionConfig(
            host=conf.connection.host,
            credentials=credentials,
            port=conf.connection.port,
            virtual_host=conf.connection.virtual_host,
            channel_max=conf.connection.channel_max,
            frame_max=conf.connection.frame_max,
            heartbeat_interval=conf.connection.heartbeat_interval,
            ssl=conf.connection.ssl,
            ssl_options=ssl_opts,
            connection_attempts=conf.connection.connection_attempts,
            retry_delay=conf.connection.retry_delay,
            socket_timeout=conf.connection.socket_timeout,
            locale=conf.connection.locale,
            backpressure_detection=conf.connection.backpressure_detection,
            reconnect_attempts=conf.connection.reconnect_attempts,
            async_engine=conf.connection.async_engine)

        service_list = configfile.get_services_classes()
        service_mapping = configfile.get_service_name_class_mapping()
        for service in configfile.get_services():
            df = discovery.DiscoveryFactory(service["discovery"])
            disc = df.get_discovery_service(service["name"],
                                            service.get("subscriptions"))
            service_mapping[service["name"]].set_discovery(disc)

        super(CLIServer,
              self).__init__(conn_conf,
                             queue_name=conf.server.queue_name,
                             exchange_name=conf.server.exchange_name,
                             service_list=service_list)
Beispiel #8
0
    def test_publish_message_via_existing_reader_sync(self, get_mock):
        """
        Tests that message is published via existing reader
        """
        conf = config.ConnectionConfig(self.host, self.credentials)
        drvr = driver.AMQPDriver(conf)
        drvr._reader = mock.MagicMock()
        exchange = "exchange_name"
        routing_key = "rk"
        message = mock.MagicMock()

        drvr.publish_message(exchange, routing_key, message)
        get_mock().publish_message.assert_called_once_with(
            exchange, routing_key, message)
Beispiel #9
0
# FOR RPC
# -------
# register remote service's exchanges to send there requests (RPC calls)
disc.register_remote_service("test_hello", "test_exchange")

# FOR SUBSCRIBE
# -------------
# register remote notification exchange to bind to it and get notifications
# In this example service 'test_subscribe' gets notifications to it's queue
# from 'test_notification_exchange' which is the publication exchange of
# service 'test_hello'
disc.register_remote_publisher("test_hello", "test_notification_exchange")

# FOR RPC AND SUBSCRIBE
# ---------------------
# start server on given queue and exchange
# The given queue will be used to obtain messages from other services (rpc
# and publishers).
# The given exchange will be used by other services to send there it's
# requests, responses, errors.

creds = config.Credentials("guest", "guest")
conf = config.ConnectionConfig("localhost", credentials=creds)
WorldController.set_discovery(disc)
ChuckController.set_discovery(disc)
srv = server.Server(conf,
                    queue_name="test_world_service",
                    exchange_name="test_world_exchange",
                    service_list=[WorldController, ChuckController])
srv.run()
Beispiel #10
0
# -------
# register remote service's exchanges to send there requests (RPC calls)
disc.register_remote_service("test_world", "test_world_exchange")
disc.register_remote_service("test_chuck_norris", "test_world_exchange")

# FOR PUBLICATIONS
# ----------------
# register service's notification exchange to publish notifications
# Service 'test_hello' publishes notifications to it's exchange
# 'test_notification_exchange'
disc.register_local_publisher("test_hello", "test_notification_exchange")

# FOR RPC AND SUBSCRIBE
# ---------------------
# start server on given queue and exchange
# The given queue will be used to obtain messages from other services (rpc
# and publishers).
# The given exchange will be used by other services to send there it's
# requests, responses, errors.

creds = config.Credentials("guest", "guest")
conf = config.ConnectionConfig("localhost",
                               credentials=creds,
                               async_engine=True)
HelloController.set_discovery(disc)
srv = server.Server(conf,
                    queue_name="test_service",
                    exchange_name="test_exchange",
                    service_list=[HelloController])
srv.run()