Пример #1
0
def dummy_bus(loop, redis_server_url):
    # fmt: off
    dummy_bus = lightbus.creation.create(
        config=RootConfig(
            apis={
                'default':
                ApiConfig(
                    rpc_transport=RpcTransportSelector(
                        debug=DebugRpcTransport.Config()),
                    result_transport=ResultTransportSelector(
                        debug=DebugResultTransport.Config()),
                    event_transport=EventTransportSelector(
                        debug=DebugEventTransport.Config()),
                )
            },
            bus=BusConfig(
                schema=SchemaConfig(transport=SchemaTransportSelector(
                    redis=RedisSchemaTransport.Config(
                        url=redis_server_url)), ))),
        plugins=[],
    )
    # fmt: on
    yield dummy_bus
    try:
        dummy_bus.client.close()
    except BusAlreadyClosed:
        pass
Пример #2
0
 def _new_bus(service_name="{friendly}"):
     bus = lightbus.creation.create(
         config=RootConfig(
             apis={
                 'default':
                 ApiConfig(
                     rpc_transport=RpcTransportSelector(
                         redis=RedisRpcTransport.Config(
                             url=redis_server_url)),
                     result_transport=ResultTransportSelector(
                         redis=RedisResultTransport.Config(
                             url=redis_server_url)),
                     event_transport=EventTransportSelector(
                         redis=RedisEventTransport.Config(
                             url=redis_server_url,
                             stream_use=StreamUse.PER_EVENT,
                             service_name="test_service",
                             consumer_name="test_consumer",
                         )),
                 )
             },
             bus=BusConfig(
                 schema=SchemaConfig(transport=SchemaTransportSelector(
                     redis=RedisSchemaTransport.Config(
                         url=redis_server_url)), )),
             service_name=service_name),
         plugins=[],
     )
     bus.client.disable_proxy()
     return bus
Пример #3
0
 async def _new_bus():
     bus = await lightbus.creation.create_async(
         config=RootConfig(
             apis={
                 'default': ApiConfig(
                     rpc_transport=RpcTransportSelector(
                         redis=RedisRpcTransport.Config(url=redis_server_url)
                     ),
                     result_transport=ResultTransportSelector(
                         redis=RedisResultTransport.Config(url=redis_server_url)
                     ),
                     event_transport=EventTransportSelector(redis=RedisEventTransport.Config(
                         url=redis_server_url,
                         stream_use=StreamUse.PER_EVENT,
                         service_name="test_service",
                         consumer_name="test_consumer",
                     )),
                 )
             },
             bus=BusConfig(
                 schema=SchemaConfig(
                     transport=SchemaTransportSelector(redis=RedisSchemaTransport.Config(url=redis_server_url)),
                 )
             )
         ),
         plugins=[],
     )
     return bus
Пример #4
0
async def test_from_config(redis_client):
    await redis_client.select(5)
    host, port = redis_client.address
    transport = RedisSchemaTransport.from_config(
        config=None, url=f"redis://127.0.0.1:{port}/5", connection_parameters=dict(maxsize=3)
    )
    with await transport.connection_manager() as transport_client:
        assert transport_client.connection.address == ("127.0.0.1", port)
        assert transport_client.connection.db == 5
        await transport_client.set("x", 1)
        assert await redis_client.get("x")

    assert transport._redis_pool.connection.maxsize == 3
    await transport.close()
Пример #5
0
def schema(redis_pool):
    return Schema(schema_transport=RedisSchemaTransport(redis_pool=redis_pool))