PubSub Connection Lifetime
See original GitHub issueI am using the PubSub to publish/subscribe messages to a specific topic/subscription and everything is working as expected. 👍
My question is about the connection life time. As I can read in the documentation it says to use PublisherClient
and SubscriberClient
since it’s more performant and simple comparing to PublisherServiceApiClient
and SubscriberServiceApiClient
.
Should, I create a new publisher per message or can I reuse the same publisher to send messages?
// new publisher per message
var publisher = await PublisherClient.CreateAsync(topicName);
var messageId = await publisher.PublishAsync("My message");
await publisher.ShutdownAsync(TimeSpan.FromSeconds(15));
I assume that for subscribers, I MUST reuse the same subscriber! Also, if some connectivity problem occurred, do I need to handle them or the subscriber can reconnect automatically?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
asp.net - Google Cloud Pub/Sub Publisher Lifecycle
I'm running a Cloud Pub/Sub PublisherClient instance as a Singleton in an ASP.NET web application (.NET Standard 2). Does this retain a ...
Read more >Replaying and purging messages | Cloud Pub/Sub ...
The snapshot reaches a lifespan of seven days. The oldest unacknowledged message in the snapshot exceeds the message retention duration .
Read more >Azure Web PubSub service internals
When a client connection connects, it connects to a hub, and during its lifetime it belongs to that hub. Once a client connection...
Read more >@azure/web-pubsub - Microsoft .NET
When a client connection is created, it connects to a hub, and during its lifetime, it belongs to that hub. Different applications can...
Read more >Build your own web Chat App using Azure Web PubSub Service
When a client connection connects, it connects to a hub, and during its lifetime it belongs to that hub. Once a client connection...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Talento90 Reuse the publisher and subscribers as much as possible. Both will recover from transient errors without any action required from your code. Unrecoverable errors will throw relevant exceptions, which you will need to handle. An example of an unrecoverable exception would be incorrect auth; or trying to use a non-existent topic/subscription.
Assigned Chris to comment as he knows far more about PubSub than I do, but if you’re publishing multiple messages to the same topic, I’d definitely expect it to be best to create a single publisher. Chris can answer the latter parts…