Skip to content

Config client from profile#42

Draft
tomwheeler wants to merge 5 commits into
mainfrom
config-client-from-profile
Draft

Config client from profile#42
tomwheeler wants to merge 5 commits into
mainfrom
config-client-from-profile

Conversation

@tomwheeler

Copy link
Copy Markdown
Contributor

DO NOT MERGE.

I have created this draft PR to support review and sharing this code. However, I do not intend for this code to become part of the main branch right now.

What was changed

I added code to configure the Temporal Client from a configuration file that defines a named profile, which specifies the frontend address of the Temporal Service, the Namespace, and details related to the desired authentication method. The configuration file is loaded from its default location, while the profile name is specified through an environment variable (TEMPORAL_PROFILE). I also updated the Clients created by the Worker and Starter code to use the Client Options returned by this code.

Why?

Currently, the clients used in this tutorial have no explicit configuration and rely solely on the default options. Imagine that someone new to Temporal application development signed up for Temporal Cloud on their own and now wants to run this intro-level money transfer tutorial. Getting it to work with Temporal Cloud requires making changes to the Client configuration, but this user won't know what to change. Note that this scenario I've described isn't limited to Temporal Cloud. Someone using a non-default Namespace name or a non-local Temporal Service would have the same problem.

Having the clients configure themselves based on the presence of environment variables eliminates the need to hardcode the frontend address, Namespace name, or authentication details. It helps the user understand that the application logic remains unchanged when migrating from the Temporal Service used for development on their laptop to a production Temporal Service (or vice versa). Finally, this makes it easier for users to run this example locally, on a remote self-hosted cluster, or on Temporal Cloud.

This updated takes advantage of the pre-release support for profile-based configuration in the Java SDK

NOTE: I have updated the code but not the prose in the tutorial, pending further discussion with the Education team. I plan to make similar changes to the other money-transfer repositories, but if it turns out that is not viable, then I will probably need to fork these repos and tutorials to support the onboarding path for new cloud users.

Checklist

  1. Closes

This does not close an issue, but enables further progress of EDU-3801. That issue would be closed only after all similar tutorials have been updated.

  1. How was this tested:

I tested this by first creating a profile named cloud using the Temporal CLI (note that these values are similar to but not identical to the ones I actually set):

$ temporal --profile cloud config set --prop address --value "us-east-1.aws.api.temporal.io:7233"
$ temporal --profile cloud config set --prop namespace --value "example.c9ef8"
$ temporal --profile cloud config set --prop api_key --value "abc123.actual.value.redacted.xyz789"

According to the output from this command, the config file was created at $HOME/Library/Application Support/temporalio/temporal.toml.

I then set an environment variable:

export TEMPORAL_PROFILE=cloud

I started the Worker by running mvn clean compile exec:java -Dexec.mainClass="moneytransferapp.MoneyTransferWorker". Finally, I opened a new terminal tab, set the same environment variable as above, and started the Workflow by running mvn clean compile exec:java -Dexec.mainClass="moneytransferapp.TransferApp". I verified in the Temporal Cloud Web UI that the Workflow Execution ran and completed successfully.

I also set up a profile for mTLS authentication with Temporal Cloud and successfully ran it with the implementation provided here.

  1. Any docs updates needed?

The tutorial prose will require a small update to describe the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant