question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PubSub Connection Lifetime

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
chrisdunelmcommented, Sep 16, 2019

@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.

1reaction
jskeetcommented, Sep 16, 2019

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…

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found