コード例 #1
0
async def get_partitions(iot_connection_str):
    try:
        client = EventHubClientAsync.from_iothub_connection_string(iot_connection_str, debug=True)
        client.add_async_receiver("$default", "0", prefetch=1000, operation='/messages/events')
        await client.run_async()
        partitions = await client.get_eventhub_info_async()
        return partitions["partition_ids"]
    finally:
        await client.stop_async()
コード例 #2
0
async def get_partitions(iot_connection_str):
    try:
        client = EventHubClientAsync.from_iothub_connection_string(
            iot_connection_str, debug=True)
        client.add_async_receiver("$default",
                                  "0",
                                  prefetch=1000,
                                  operation='/messages/events')
        await client.run_async()
        partitions = await client.get_eventhub_info_async()
        return partitions["partition_ids"]
    finally:
        await client.stop_async()
コード例 #3
0
async def test_iothub_receive_multiple_async(iot_connection_str):
    partitions = await get_partitions(iot_connection_str)
    client = EventHubClientAsync.from_iothub_connection_string(iot_connection_str, debug=True)
    try:
        receivers = []
        for p in partitions:
            receivers.append(client.add_async_receiver("$default", p, prefetch=10, operation='/messages/events'))
        await client.run_async()
        outputs = await asyncio.gather(*[pump(r) for r in receivers])

        assert isinstance(outputs[0], int) and outputs[0] <= 10
        assert isinstance(outputs[1], int) and outputs[1] <= 10
    finally:
        await client.stop_async()
コード例 #4
0
async def test_iothub_receive_detach_async(iot_connection_str):
    client = EventHubClientAsync.from_iothub_connection_string(iot_connection_str, debug=True)
    receivers = []
    for i in range(2):
        receivers.append(client.add_async_receiver("$default", str(i), prefetch=1000, operation='/messages/events'))
    await client.run_async()
    try:
        outputs = await asyncio.gather(
            pump(receivers[0]),
            pump(receivers[1]),
            return_exceptions=True)

        assert isinstance(outputs[0], int) and outputs[0] == 0
        assert isinstance(outputs[1], EventHubError)
    except:
        raise
    finally:
        await client.stop_async()
コード例 #5
0
async def test_iothub_receive_multiple_async(iot_connection_str):
    partitions = await get_partitions(iot_connection_str)
    client = EventHubClientAsync.from_iothub_connection_string(
        iot_connection_str, debug=True)
    try:
        receivers = []
        for p in partitions:
            receivers.append(
                client.add_async_receiver("$default",
                                          p,
                                          prefetch=10,
                                          operation='/messages/events'))
        await client.run_async()
        outputs = await asyncio.gather(*[pump(r) for r in receivers])

        assert isinstance(outputs[0], int) and outputs[0] <= 10
        assert isinstance(outputs[1], int) and outputs[1] <= 10
    finally:
        await client.stop_async()