Exemplo n.º 1
0
def test_publish_and_pull(publisher: PubsubPublisher):
    publisher.publish(project_id, topic2, header_1, gzip.compress(b'[]'))
    subscriber = PubsubSubscriber(sub_client=pubsub_v1.SubscriberClient())
    for message in subscriber.pull(project_id, subscription2):
        header, data, id = subscriber.unpack_message(message)
        assert int(header['age']) == 2
        assert 'long_str' not in header
        subscriber.ack(project_id, subscription2, id)
Exemplo n.º 2
0
def test_publish_and_streaming_pull(publisher: PubsubPublisher):
    publisher.publish(project_id, topic1, header_1, gzip.compress(b'[]'))
    publisher.publish(project_id, topic2, header_1, gzip.compress(b'[]'))
    loop = asyncio.get_event_loop()
    subscriber1 = PubsubSubscriber(sub_client=pubsub_v1.SubscriberClient())
    subscriber2 = PubsubSubscriber(sub_client=pubsub_v1.SubscriberClient())
    task1 = subscriber1.stream(project_id,
                               subscription1,
                               callback=callback,
                               timeout=2)
    task2 = subscriber2.stream(project_id,
                               subscription2,
                               callback=callback,
                               timeout=2)
    loop.run_until_complete(asyncio.wait([task1, task2]))
    loop.close()