Skip to content

Commit 0256a9c

Browse files
Switch to TemporalNexusServiceClientOptions
1 parent d385beb commit 0256a9c

4 files changed

Lines changed: 56 additions & 6 deletions

File tree

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,53 @@
11
package io.temporal.client;
22

3+
import com.google.common.base.Strings;
4+
35
public class TemporalNexusServiceClientOptions {
46
public static Builder newBuilder() {
57
return new Builder();
68
}
79

8-
public static final class Builder {}
10+
private final String endpoint;
11+
private final String taskQueue;
12+
13+
TemporalNexusServiceClientOptions(String endpoint, String taskQueue) {
14+
this.endpoint = endpoint;
15+
this.taskQueue = taskQueue;
16+
}
17+
18+
String getEndpoint() {
19+
return endpoint;
20+
}
21+
22+
String getTaskQueue() {
23+
return taskQueue;
24+
}
25+
26+
public static final class Builder {
27+
private String endpoint;
28+
private String taskQueue;
29+
30+
Builder setTaskQueue(String taskQueue) {
31+
this.taskQueue = taskQueue;
32+
return this;
33+
}
34+
35+
Builder setEndpoint(String endpoint) {
36+
this.endpoint = endpoint;
37+
return this;
38+
}
39+
40+
TemporalNexusServiceClientOptions build() {
41+
if (Strings.isNullOrEmpty(endpoint) && Strings.isNullOrEmpty(taskQueue)) {
42+
throw new IllegalArgumentException("Must provide either a task queue or an endpoint");
43+
} else if (!Strings.isNullOrEmpty(endpoint) && !Strings.isNullOrEmpty(taskQueue)) {
44+
throw new IllegalArgumentException("Must provide only a task queue or an endpoint");
45+
}
46+
47+
48+
return new TemporalNexusServiceClientOptions(
49+
endpoint, taskQueue
50+
);
51+
}
52+
}
953
}

temporal-sdk/src/main/java/io/temporal/client/WorkflowClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static WorkflowClient newInstance(WorkflowServiceStubs service, WorkflowClientOp
136136
* @return A new {@link ServiceClient} instance backed by this {@link WorkflowClient} instance.
137137
*/
138138
@Experimental
139-
<T> ServiceClient<T> newNexusServiceClient(Class<T> nexusServiceInterface, String endpoint);
139+
<T> ServiceClient<T> newNexusServiceClient(Class<T> nexusServiceInterface, TemporalNexusServiceClientOptions options);
140140

141141
/**
142142
* Creates a new {@link CompletionClient} that can be used to complete or fail async operations

temporal-sdk/src/main/java/io/temporal/client/WorkflowClientInternalImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ public WorkflowServiceStubs getWorkflowServiceStubs() {
107107

108108
@Override
109109
public <T> ServiceClient<T> newNexusServiceClient(
110-
Class<T> nexusServiceInterface, String endpoint) {
110+
Class<T> nexusServiceInterface, TemporalNexusServiceClientOptions serviceClientOptions) {
111111
return new ServiceClient<>(
112112
ServiceClientOptions.newBuilder(nexusServiceInterface)
113-
.setTransport(new workflowServiceNexusTransport(genericClient, endpoint, options))
113+
.setTransport(new workflowServiceNexusTransport(genericClient, serviceClientOptions, options))
114114
.setSerializer(new PayloadSerializer(options.getDataConverter()))
115115
.build());
116116
}

temporal-sdk/src/main/java/io/temporal/client/workflowServiceNexusTransport.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,16 @@ public class workflowServiceNexusTransport implements Transport {
4444
private final TaskDispatchTarget dispatchTarget;
4545

4646
public workflowServiceNexusTransport(
47-
GenericWorkflowClient client, String endpoint, WorkflowClientOptions options) {
47+
GenericWorkflowClient client, TemporalNexusServiceClientOptions serviceClientOptions, WorkflowClientOptions options) {
4848
this.client = client;
4949
this.clientOptions = options;
50-
this.dispatchTarget = TaskDispatchTarget.newBuilder().setEndpoint(endpoint).build();
50+
if (serviceClientOptions.getEndpoint() != null) {
51+
this.dispatchTarget = TaskDispatchTarget.newBuilder().setEndpoint(serviceClientOptions.getEndpoint()).build();
52+
} else if (serviceClientOptions.getTaskQueue() != null) {
53+
this.dispatchTarget = TaskDispatchTarget.newBuilder().setTaskQueue(serviceClientOptions.getTaskQueue()).build();
54+
} else {
55+
throw new IllegalArgumentException("No target specified");
56+
}
5157
}
5258

5359
private static final JsonFormat.Parser JSON_PARSER = JsonFormat.parser();

0 commit comments

Comments
 (0)