Config client from profile#42
Draft
tomwheeler wants to merge 5 commits into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
mainbranch 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
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.
I tested this by first creating a profile named
cloudusing the Temporal CLI (note that these values are similar to but not identical to the ones I actually set):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:
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 runningmvn 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.
The tutorial prose will require a small update to describe the changes.