Temporal Client

Local Cluster

import io.temporal.client.WorkflowClient;
import io.temporal.serviceclient.WorkflowServiceStubs;
 
// other code omitted for brevity
 
WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs();
WorkflowClient client = WorkflowClient.newInstance(service);

Non-local Cluster

import io.temporal.serviceclient.WorkflowServiceStubs;
import io.temporal.serviceclient.WorkflowServiceStubsOptions;
import io.temporal.client.WorkflowClient;
 
// other code omitted for brevity
 
WorkflowServiceStubsOptions stubsOptions = new WorkflowServiceStubsOptions.newBuilder()
        .setTarget("mycluster.example.com:7233")
        .build();
 
WorkflowServiceStubs service = WorkflowServiceStubs.newServiceStubs(stubsOptions);
 
WorkflowClientOptions options = WorkflowClientOptions.newBuilder()
        .setNamespace("operations")
        .build();
 
WorkflowClient client = WorkflowClient.newInstance(service, options);

With TLS:

import io.grpc.netty.shaded.io.netty.handler.ssl.SslContext;
import io.temporal.serviceclient.SimpleSslContextBuilder;
import io.temporal.serviceclient.WorkflowServiceStubs;
import io.temporal.serviceclient.WorkflowServiceStubsOptions;
import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowClientOptions;
import java.io.FileInputStream;
import java.io.InputStream;
 
// other code omitted for brevity
 
// Step 1: create the SimpleSslContext
String clientCertPath = "/home/myuser/tls/certificate.pem";
InputStream clientCert = new FileInputStream(clientCertPath);
 
String clientCertPrivateKeyPath = "/home/myuser/tls/private.key";
InputStream clientCertPrivateKey = new FileInputStream(clientCertPrivateKeyPath);
 
SslContext sslContext = SimpleSslContextBuilder.forPKCS8(clientCert, clientCertPrivateKey).build();
 
// Step 2: create the WorkflowServiceStubsOptions
WorkflowServiceStubsOptions stubOptions = WorkflowServiceStubsOptions.newBuilder()
        .setSslContext(sslContext)
        .setTarget("mycluster.example.com:7233")
        .build();
 
// Step 3: create the WorkflowServiceStubs using the SimpleSslContext
WorkflowServiceStubs service = WorkflowServiceStubs.newServiceStubs(stubOptions);
 
// Step 4: create the WorkflowClientOptions (this example uses a non-default Namespace)
WorkflowClientOptions options = WorkflowClientOptions.newBuilder()
        .setNamespace("operations")
        .build();
 
// Step 5: Use the stubs and options to create the WorkflowClient
WorkflowClient client = WorkflowClient.newInstance(service, options);

In command line:

$ temporal workflow list \
    --address mycluster.example.com:7233 \
    --namespace operations
 
$ # With TLS
$ temporal workflow list \
    --address mycluster.example.com:7233 \
    --namespace operations \
    --tls-cert-path /home/myuser/tls/certificate.pem \
    --tls-key-path /home/myuser/tls/private.key