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.

Which way to use DaprClient is recommended?

See original GitHub issue

Hi, there are 2 ways to use DaprClient in current demos.

first one is to create a new DaprClient instance whenever you need to talk to dapr runtime:

try (DaprClient client = (new DaprClientBuilder()).build()) {
 // ...
}

second one is to create a DaprClient bean before usage, then inject it into code:

@Autowired
private DaprClient client;

since our project is Spring-based, the second way seems attractive, however, is it thread-safe to use DaprClient in the second way, since Spring’ bean is singleton by default.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
artursouzacommented, Jun 11, 2021

The second way is preferred because you reuse the client. The client is thread-safe and designed to be reused.

0reactions
darren-wangcommented, Aug 4, 2021

ources that might not be freed by taking this approach, even after the JVM shut down (i.e. used ports)?

that’s what confusing me too. i guess the only way to find it out is to read the source codes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DaprClient usage - Dapr Docs
For best performance, create a single long-lived instance of DaprClient and provide access to that shared instance throughout your application.
Read more >
Get started with Dapr | Microsoft Learn
You use the DaprClient.InvokeMethodAsync method to invoke the weatherforecast method of the MyBackEnd service. You'll configure the web API to ...
Read more >
Improvements to dapr client · Issue #197 · dapr/dotnet-sdk
I did the initial draft of Dapr.Client and defined state as its own ... we were leaning this way to reduce maintenance pain...
Read more >
Using Service Invocation from Dapr .NET SDK - Laurent Kempé
Using the DaprClient we only had to specify the HTTP method, the Dapr app-id and the method-name of our service. Conclusion. We have...
Read more >
patterns Archives - klichx.dev
This means you may use http calls or Dapr client. Best part is that no matter what is on the other end, be...
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