コード例 #1
0
def test_long_running_receive_async(connection_str):
    parser = argparse.ArgumentParser()
    parser.add_argument("--duration",
                        help="Duration in seconds of the test",
                        type=int,
                        default=30)
    parser.add_argument("--consumer",
                        help="Consumer group name",
                        default="$default")
    parser.add_argument("--partitions", help="Comma seperated partition IDs")
    parser.add_argument("--offset", help="Starting offset", default="-1")
    parser.add_argument("--conn-str",
                        help="EventHub connection string",
                        default=connection_str)
    parser.add_argument("--eventhub", help="Name of EventHub")
    parser.add_argument("--address", help="Address URI to the EventHub entity")
    parser.add_argument(
        "--sas-policy",
        help="Name of the shared access policy to authenticate with")
    parser.add_argument("--sas-key", help="Shared access key")

    loop = asyncio.get_event_loop()
    args, _ = parser.parse_known_args()
    if args.conn_str:
        client = EventHubClientAsync.from_connection_string(
            args.conn_str,
            eventhub=args.eventhub,
            auth_timeout=240,
            debug=False)
    elif args.address:
        client = EventHubClientAsync(args.address,
                                     auth_timeout=240,
                                     username=args.sas_policy,
                                     password=args.sas_key)
    else:
        try:
            import pytest
            pytest.skip("Must specify either '--conn-str' or '--address'")
        except ImportError:
            raise ValueError("Must specify either '--conn-str' or '--address'")

    try:
        if not args.partitions:
            partitions = loop.run_until_complete(get_partitions(client))
        else:
            partitions = args.partitions.split(",")
        pumps = []
        for pid in partitions:
            receiver = client.add_async_receiver(consumer_group=args.consumer,
                                                 partition=pid,
                                                 offset=Offset(args.offset),
                                                 prefetch=50)
            pumps.append(pump(pid, receiver, args, args.duration))
        loop.run_until_complete(client.run_async())
        loop.run_until_complete(asyncio.gather(*pumps))
    finally:
        loop.run_until_complete(client.stop_async())
def test_long_running_partition_send_async(connection_str):
    parser = argparse.ArgumentParser()
    parser.add_argument("--duration", help="Duration in seconds of the test", type=int, default=30)
    parser.add_argument("--payload", help="payload size", type=int, default=1024)
    parser.add_argument("--batch", help="Number of events to send and wait", type=int, default=200)
    parser.add_argument("--partitions", help="Comma seperated partition IDs")
    parser.add_argument("--conn-str", help="EventHub connection string", default=connection_str)
    parser.add_argument("--eventhub", help="Name of EventHub")
    parser.add_argument("--address", help="Address URI to the EventHub entity")
    parser.add_argument("--sas-policy", help="Name of the shared access policy to authenticate with")
    parser.add_argument("--sas-key", help="Shared access key")
    parser.add_argument("--logger-name", help="Unique log file ID")

    loop = asyncio.get_event_loop()
    args, _ = parser.parse_known_args()

    if args.conn_str:
        client = EventHubClientAsync.from_connection_string(
            args.conn_str,
            eventhub=args.eventhub, debug=True)
    elif args.address:
        client = EventHubClientAsync(
            args.address,
            username=args.sas_policy,
            password=args.sas_key,
            auth_timeout=500)
    else:
        try:
            import pytest
            pytest.skip("Must specify either '--conn-str' or '--address'")
        except ImportError:
            raise ValueError("Must specify either '--conn-str' or '--address'")

    try:
        if not args.partitions:
            partitions = loop.run_until_complete(get_partitions(client))
        else:
            pid_range = args.partitions.split("-")
            if len(pid_range) > 1:
                partitions = [str(i) for i in range(int(pid_range[0]), int(pid_range[1]) + 1)]
            else:
                partitions = args.partitions.split(",")
        pumps = []
        for pid in partitions:
            sender = client.add_async_sender(partition=pid, send_timeout=0, keep_alive=False)
            pumps.append(pump(pid, sender, args, args.duration))
        loop.run_until_complete(client.run_async())
        results = loop.run_until_complete(asyncio.gather(*pumps, return_exceptions=True))
        assert not results
    except Exception as e:
        logger.error("Sender failed: {}".format(e))
    finally:
        logger.info("Shutting down sender")
        loop.run_until_complete(client.stop_async())
コード例 #3
0
def test_long_running_partition_send_async(connection_str):
    parser = argparse.ArgumentParser()
    parser.add_argument("--duration", help="Duration in seconds of the test", type=int, default=30)
    parser.add_argument("--payload", help="payload size", type=int, default=1024)
    parser.add_argument("--batch", help="Number of events to send and wait", type=int, default=200)
    parser.add_argument("--partitions", help="Comma seperated partition IDs")
    parser.add_argument("--conn-str", help="EventHub connection string", default=connection_str)
    parser.add_argument("--eventhub", help="Name of EventHub")
    parser.add_argument("--address", help="Address URI to the EventHub entity")
    parser.add_argument("--sas-policy", help="Name of the shared access policy to authenticate with")
    parser.add_argument("--sas-key", help="Shared access key")
    parser.add_argument("--logger-name", help="Unique log file ID")

    loop = asyncio.get_event_loop()
    args, _ = parser.parse_known_args()

    if args.conn_str:
        client = EventHubClientAsync.from_connection_string(
            args.conn_str,
            eventhub=args.eventhub, debug=True)
    elif args.address:
        client = EventHubClientAsync(
            args.address,
            username=args.sas_policy,
            password=args.sas_key,
            auth_timeout=500)
    else:
        try:
            import pytest
            pytest.skip("Must specify either '--conn-str' or '--address'")
        except ImportError:
            raise ValueError("Must specify either '--conn-str' or '--address'")

    try:
        if not args.partitions:
            partitions = loop.run_until_complete(get_partitions(client))
        else:
            pid_range = args.partitions.split("-")
            if len(pid_range) > 1:
                partitions = [str(i) for i in range(int(pid_range[0]), int(pid_range[1]) + 1)]
            else:
                partitions = args.partitions.split(",")
        pumps = []
        for pid in partitions:
            sender = client.add_async_sender(partition=pid, send_timeout=0, keep_alive=False)
            pumps.append(pump(pid, sender, args, args.duration))
        loop.run_until_complete(client.run_async())
        results = loop.run_until_complete(asyncio.gather(*pumps, return_exceptions=True))
        assert not results
    except Exception as e:
        logger.error("Sender failed: {}".format(e))
    finally:
        logger.info("Shutting down sender")
        loop.run_until_complete(client.stop_async())
コード例 #4
0
def test_long_running_receive_async(connection_str):
    parser = argparse.ArgumentParser()
    parser.add_argument("--duration", help="Duration in seconds of the test", type=int, default=30)
    parser.add_argument("--consumer", help="Consumer group name", default="$default")
    parser.add_argument("--partitions", help="Comma seperated partition IDs")
    parser.add_argument("--offset", help="Starting offset", default="-1")
    parser.add_argument("--conn-str", help="EventHub connection string", default=connection_str)
    parser.add_argument("--eventhub", help="Name of EventHub")
    parser.add_argument("--address", help="Address URI to the EventHub entity")
    parser.add_argument("--sas-policy", help="Name of the shared access policy to authenticate with")
    parser.add_argument("--sas-key", help="Shared access key")

    loop = asyncio.get_event_loop()
    args, _ = parser.parse_known_args()
    if args.conn_str:
        client = EventHubClientAsync.from_connection_string(
            args.conn_str,
            eventhub=args.eventhub, auth_timeout=240, debug=False)
    elif args.address:
        client = EventHubClientAsync(
            args.address,
            auth_timeout=240,
            username=args.sas_policy,
            password=args.sas_key)
    else:
        try:
            import pytest
            pytest.skip("Must specify either '--conn-str' or '--address'")
        except ImportError:
            raise ValueError("Must specify either '--conn-str' or '--address'")

    try:
        if not args.partitions:
            partitions = loop.run_until_complete(get_partitions(client))
        else:
            partitions = args.partitions.split(",")
        pumps = []
        for pid in partitions:
            receiver = client.add_async_receiver(
                consumer_group=args.consumer,
                partition=pid,
                offset=Offset(args.offset),
                prefetch=50)
            pumps.append(pump(pid, receiver, args, args.duration))
        loop.run_until_complete(client.run_async())
        loop.run_until_complete(asyncio.gather(*pumps))
    finally:
        loop.run_until_complete(client.stop_async())
コード例 #5
0
    start_time = time.time()
    for event_data in await receiver.receive(timeout=10):
        last_offset = event_data.offset
        last_sn = event_data.sequence_number
        print("Received: {}, {}".format(last_offset, last_sn))
        total += 1
    end_time = time.time()
    run_time = end_time - start_time
    print("Received {} messages in {} seconds".format(total, run_time))


try:
    if not ADDRESS:
        raise ValueError("No EventHubs URL supplied.")

    loop = asyncio.get_event_loop()
    client = EventHubClientAsync(ADDRESS,
                                 debug=False,
                                 username=USER,
                                 password=KEY)
    tasks = [
        asyncio.ensure_future(pump(client, "0")),
        asyncio.ensure_future(pump(client, "1"))
    ]
    loop.run_until_complete(asyncio.wait(tasks))
    loop.run_until_complete(client.stop_async())
    loop.close()

except KeyboardInterrupt:
    pass
コード例 #6
0
async def pump(client, partition):
    receiver = client.add_async_receiver(CONSUMER_GROUP, partition, OFFSET, prefetch=5)
    await client.run_async()
    total = 0
    start_time = time.time()
    for event_data in await receiver.receive(timeout=10):
        last_offset = event_data.offset
        last_sn = event_data.sequence_number
        print("Received: {}, {}".format(last_offset.value, last_sn))
        total += 1
    end_time = time.time()
    run_time = end_time - start_time
    print("Received {} messages in {} seconds".format(total, run_time))

try:
    if not ADDRESS:
        raise ValueError("No EventHubs URL supplied.")

    loop = asyncio.get_event_loop()
    client = EventHubClientAsync(ADDRESS, debug=False, username=USER, password=KEY)
    tasks = [
        asyncio.ensure_future(pump(client, "0")),
        asyncio.ensure_future(pump(client, "1"))]
    loop.run_until_complete(asyncio.wait(tasks))
    loop.run_until_complete(client.stop_async())
    loop.close()

except KeyboardInterrupt:
    pass