PRIYANKA VERGADIA: If you are ingesting large amounts of data
for analysis or looking to simplify
the development of event driven microservices,
then you need to check out Cloud Pub/Sub.
[MUSIC PLAYING]
Welcome to Pub/Sub Made Easy.
I'm Priyanka.
And in today's episode, we will dive deeper into Subscribers.
A publisher sent messages to a Cloud Pub/Sub topic.
Subscriber application creates a subscription to this topic
in order to receive those messages.
A topic can have multiple subscriptions but a given
subscription belongs to a single topic,
which means a subscription cannot be receiving messages
from more than one topics.
Check out episode 2 of the series
to see how to set up subscriptions.
Cloud Pub/Sub delivers each published message at least once
for every subscription.
There are some exceptions to this at least once behavior
though.
You can configure message retention duration.
And the value can be between 10 minutes and seven days.
By default, a message that cannot be delivered within
the maximum retention time of seven days is deleted and is no
longer accessible.
This typically happens when a subscriber does not keep up
with the flow of the messages.
Oh, and make sure to create at least one subscription
when you create a topic.
Otherwise, the messages published
to the topic with no subscription
disappear into the ether.
Once a message is sent to a subscriber,
the subscriber should acknowledge the message.
But until it does, the message is considered outstanding.
And it stays outstanding until the subscriber
reaches the configurable limited amount of time
called ACT deadline, at which point
Cloud Pub/Sub will attempt to redeliver it.
And while the message is outstanding to a subscriber,
Cloud Pub/Sub tries not to deliver it
to any other subscriber on the same subscription.
Typically, Cloud Pub/Sub delivers each message once
in the order in which it was published.
However, messages may sometimes be delivered out
of order or more than once.
Idempotency and duplication is important to think
about regardless of Pub/Sub since it can happen simply
because publishers republish the same content.
A very simple way to achieve exactly once processing
is to rely on Cloud Dataflow's Pub/Sub I/O connector which
solves some of the harder problems like this for you.
You can also achieve ordered processing
by having the publishers send the sequence
token in the message.
Stay tuned for more on this in the upcoming episodes.
Alternatively, Cloud Dataflow gives you very simple
to use tools to produce ordered output or process
messages in order.
Now a subscription can use either pull or push mechanism
for message delivery.
And it's configurable.
So you can change or configure the mechanism at any time.
In pull delivery, the subscribing application
explicitly calls the pull method which
requests messages for delivery.
The Cloud Pub/Sub server responds
with a message or an error if the queue
is empty and an Ack ID.
The subscriber explicitly calls the acknowledged method
using the returned Ack ID to acknowledge receipt.
A lot of this is abstracted in the client libraries
where you might simply create callbacks that are invoked
when a new message arrives.
The client library itself will manage
all the acknowledgment deadlines and extensions.
In push delivery, the Cloud Pub/Sub servers
sends each message as an HTTPS request
to the subscriber application at a pre-configured endpoint.
The endpoint acknowledges the message
by returning an HTTP success status code.
A nonsuccess response indicates that the message
should be resent.
Cloud Pub/Sub dynamically adjusts the rate
of push requests based on the rate at which it
receives success responses.
Now that we know how push and pull subscriptions work,
how can we choose which method should
be best for our use case?
Well, stay tuned for the next episode to find out.
Now let's talk about the lifecycle of subscription.
By default, subscription expires after 31 days of inactivity.
Inactivity can be no active connections,
pull requests, or push successes.
If Cloud Pub/Sub detects subscriber activity,
the subscription deletion clock restarts.
But by using subscription expiration policies,
you can configure the inactivity duration
or make the subscription persistent
regardless of activity.
You can also delete a subscription manually.
And if you create a subscription with the same name
as the deleted one, the new subscription
has no relationship with the old one.
Today be learned how to subscribe to Cloud Pub/Sub
messages.
We looked at least once delivery, push, and pull
methods.
Join us next time to learn more about choosing between push
and pull subscribers.
If you liked this video and would
like to see more such content, don't
forget to like and subscribe to our channel.
[MUSIC PLAYING]