Documentation: https://cloud.google.com/pubsub/docs/subscription-message-filter
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
Publish:
$ python publisher.py
11237580821027878
11237607528300183
11237851938500420
11237794950102544
11237530420659009
11237682617640967
11237764827784213
11237482585729123
11237609517612153
Published messages to projects/<project-id>/topics/artem-aws-manual.
Subscribe (can also run subscriber_viewer.py
in a separate terminal - it does not acknoledge messages, just prints):
$ N=3 python subscriber.py
Created subscription within 5.055 sec: name: "projects/<project-id>/subscriptions/artem-aws-manual-sub-b5f8da6c-4783-4f6b-8c2d-48812264adc5-3"
topic: "projects/<project-id>/topics/artem-aws-manual"
push_config {
}
ack_deadline_seconds: 10
message_retention_duration {
seconds: 604800
}
expiration_policy {
ttl {
seconds: 2678400
}
}
filter: "attributes.request_id=\"request-3\""
state: ACTIVE
Subscribed within 0.002 sec
Received Message {
data: b'Message: 10d5b311-c571-40b1-93ed-3cce9b4ec763'
ordering_key: ''
attributes: {
"request_id": "request-3"
}
}
^C
Subscription deleted within 2.419 sec
Traceback (most recent call last):
...
KeyboardInterrupt
Also try to run multiple different subscribers with different N
in order to emulate multiple pipelines running in parallel.