Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds docs for client initialisation with env variables #992

Merged
merged 4 commits into from
Jan 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions daprdocs/content/en/java-sdk-docs/java-client/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,44 @@ If you haven't already, [try out one of the quickstarts]({{< ref quickstarts >}}

[Complete initial setup and import the Java SDK into your project]({{< ref java >}})

## Initialising the client
You can initialise a Dapr client as so:

When you initialise the client without any parameters it will use the default endpoint values for a Dapr
sidecar instance (`127.0.0.1:50001`).

```java
DaprClient client = new DaprClientBuilder().build()
```


#### Environment variables:

##### Dapr Sidecar Endpoints
You can use the standardised `DAPR_GRPC_ENDPOINT` environment variable to
specify the gRPC endpoint. When this variable is set, the client can be initialised
without any arguments:

```bash
export DAPR_GRPC_ENDPOINT="mydomain:50051?tls=true"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small nit: Initialising -> Initializing && standardising -> standardizing. I'm not 100% confident I see the parsing for the tls=true in our codebase. I might've just missed it though. Once this is confirmed, then I think the PR is good to go. Thank you for documenting this 🎉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may be missing a conditional, like:

      if (uri.getQuery() != null && uri.getQuery().contains("tls=true")) {
        insecure = false;
      }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Cassie! I realised I had some copy/paste leftovers from the python-sdk. I fixed that now.
The ?tls query parameter was added in this proposal.
I removed the example for now, so we're not showing the grpc endpoint with "https", and we can come back to this and add it, once the support for tls is added.

```

```java
from dapr.clients import DaprClient

with DaprClient() as d:
# the client will use the endpoint specified in the environment variables
```

The legacy environment variables `DAPR_HTTP_PORT` and `DAPR_GRPC_PORT` are still supported, but `DAPR_GRPC_ENDPOINT` takes precedence.

##### Dapr API Token
If your Dapr instance is configured to require the `DAPR_API_TOKEN` environment variable, you can
set it in the environment and the client will use it automatically.
You can read more about Dapr API token authentication [here](https://docs.dapr.io/operations/security/api-token/).



## Building blocks

The Java SDK allows you to interface with all of the [Dapr building blocks]({{< ref building-blocks >}}).
Expand Down
Loading