-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
Right now you have to construct a IngressClient for every key, this makes usage awkward and I don't see a reason why it can't be moved to the individual methods:
// before
public IngressClient(dev.restate.client.Client client, String key) {
this.client = client;
this.key = key;
}
public dev.restate.client.SendResponse<Void> submit(PaymentWorkflowInput req) {
return IngressClient.this.client.send(
PaymentWorkflowHandlers.run(this.key, req)
);
}
// After
public IngressClient(dev.restate.client.Client client) {
this.client = client;
}
public dev.restate.client.SendResponse<Void> submit(String key, PaymentWorkflowInput req) {
return IngressClient.this.client.send(
PaymentWorkflowHandlers.run(key, req)
);
}
That way you can even register all the IngressClients as Spring beans automatically.
I've got codegen working by adding the following to the Clients.hbs:
public static class GatewayClient {
private final dev.restate.client.Client client;
public GatewayClient(dev.restate.client.Client client) {
this.client = client;
}
{{#handlers}}{{#if isWorkflow}}
public dev.restate.client.Client.WorkflowHandle<{{{boxedOutputFqcn}}}> workflowHandle(String key) {
return GatewayClient.this.client.workflowHandle(
{{metadataClass}}.SERVICE_NAME,
key,
{{outputSerdeRef}});
}
public dev.restate.client.SendResponse<{{{boxedOutputFqcn}}}> submit({{#if ../isKeyed}}String key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}{{{inputFqcn}}} req{{/inputEmpty}}) {
return GatewayClient.this.client.send(
{{../handlersClass}}.{{handlersClassMethodName}}({{#if ../isKeyed}}key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}req{{/inputEmpty}})
);
}
public dev.restate.client.SendResponse<{{{boxedOutputFqcn}}}> submit({{#if ../isKeyed}}String key, {{/if}}{{^inputEmpty}}{{{inputFqcn}}} req, {{/inputEmpty}}Duration delay) {
return GatewayClient.this.client.send(
{{../handlersClass}}.{{handlersClassMethodName}}({{#if ../isKeyed}}key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}req{{/inputEmpty}}), delay
);
}
public dev.restate.client.SendResponse<{{{boxedOutputFqcn}}}> submit({{#if ../isKeyed}}String key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}{{{inputFqcn}}} req, {{/inputEmpty}}Consumer<dev.restate.common.RequestBuilder<{{{boxedInputFqcn}}}, {{{boxedOutputFqcn}}}>> requestBuilderApplier) {
var reqBuilder = {{../handlersClass}}.{{handlersClassMethodName}}({{#if ../isKeyed}}key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}req{{/inputEmpty}});
if (requestBuilderApplier != null) {
requestBuilderApplier.accept(reqBuilder);
}
return GatewayClient.this.client.send(reqBuilder);
}
public dev.restate.client.SendResponse<{{{boxedOutputFqcn}}}> submit({{#if ../isKeyed}}String key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}{{{inputFqcn}}} req, {{/inputEmpty}}Duration delay, Consumer<dev.restate.common.RequestBuilder<{{{boxedInputFqcn}}}, {{{boxedOutputFqcn}}}>> requestBuilderApplier) {
var reqBuilder = {{../handlersClass}}.{{handlersClassMethodName}}({{#if ../isKeyed}}key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}req{{/inputEmpty}});
if (requestBuilderApplier != null) {
requestBuilderApplier.accept(reqBuilder);
}
return GatewayClient.this.client.send(reqBuilder, delay);
}
public java.util.concurrent.CompletableFuture<dev.restate.client.SendResponse<{{{boxedOutputFqcn}}}>> submitAsync({{#if ../isKeyed}}String key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}{{{inputFqcn}}} req{{/inputEmpty}}) {
return GatewayClient.this.client.sendAsync(
{{../handlersClass}}.{{handlersClassMethodName}}({{#if ../isKeyed}}key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}req{{/inputEmpty}})
);
}
public java.util.concurrent.CompletableFuture<dev.restate.client.SendResponse<{{{boxedOutputFqcn}}}>> submitAsync({{#if ../isKeyed}}String key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}{{{inputFqcn}}} req, {{/inputEmpty}} Duration delay) {
return GatewayClient.this.client.sendAsync(
{{../handlersClass}}.{{handlersClassMethodName}}({{#if ../isKeyed}}key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}req{{/inputEmpty}}), delay
);
}
public java.util.concurrent.CompletableFuture<dev.restate.client.SendResponse<{{{boxedOutputFqcn}}}>> submitAsync({{#if ../isKeyed}}String key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}{{{inputFqcn}}} req, {{/inputEmpty}}Consumer<dev.restate.common.RequestBuilder<{{{boxedInputFqcn}}}, {{{boxedOutputFqcn}}}>> requestBuilderApplier) {
var reqBuilder = {{../handlersClass}}.{{handlersClassMethodName}}({{#if ../isKeyed}}key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}req{{/inputEmpty}});
if (requestBuilderApplier != null) {
requestBuilderApplier.accept(reqBuilder);
}
return GatewayClient.this.client.sendAsync(reqBuilder);
}
public java.util.concurrent.CompletableFuture<dev.restate.client.SendResponse<{{{boxedOutputFqcn}}}>> submitAsync({{#if ../isKeyed}}String key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}{{{inputFqcn}}} req, {{/inputEmpty}}Duration delay, Consumer<dev.restate.common.RequestBuilder<{{{boxedInputFqcn}}}, {{{boxedOutputFqcn}}}>> requestBuilderApplier) {
var reqBuilder = {{../handlersClass}}.{{handlersClassMethodName}}({{#if ../isKeyed}}key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}req{{/inputEmpty}});
if (requestBuilderApplier != null) {
requestBuilderApplier.accept(reqBuilder);
}
return GatewayClient.this.client.sendAsync(reqBuilder, delay);
}
{{else}}
public {{#if outputEmpty}}void{{else}}{{{outputFqcn}}}{{/if}} {{handlersClassMethodName}}({{#if ../isKeyed}}String key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}{{{inputFqcn}}} req{{/inputEmpty}}) {
{{^outputEmpty}}return {{/outputEmpty}}this.client.call(
{{../handlersClass}}.{{handlersClassMethodName}}({{#if ../isKeyed}}key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}req{{/inputEmpty}})
).response();
}
public {{#if outputEmpty}}void{{else}}{{{outputFqcn}}}{{/if}} {{handlersClassMethodName}}({{#if ../isKeyed}}String key, {{/if}}{{^inputEmpty}}{{{inputFqcn}}} req, {{/inputEmpty}}Consumer<dev.restate.common.RequestBuilder<{{{boxedInputFqcn}}}, {{{boxedOutputFqcn}}}>> requestBuilderApplier) {
var reqBuilder = {{../handlersClass}}.{{handlersClassMethodName}}({{#if ../isKeyed}}key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}req{{/inputEmpty}});
if (requestBuilderApplier != null) {
requestBuilderApplier.accept(reqBuilder);
}
{{^outputEmpty}}return {{/outputEmpty}}this.client.call(reqBuilder.build()).response();
}
public {{#if outputEmpty}}java.util.concurrent.CompletableFuture<Void>{{else}}java.util.concurrent.CompletableFuture<{{{boxedOutputFqcn}}}>{{/if}} {{handlersClassMethodName}}Async({{#if ../isKeyed}}String key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}{{{inputFqcn}}} req{{/inputEmpty}}) {
return this.client.callAsync(
{{../handlersClass}}.{{handlersClassMethodName}}({{#if ../isKeyed}}key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}req{{/inputEmpty}})
).thenApply(dev.restate.client.Response::response);
}
public {{#if outputEmpty}}java.util.concurrent.CompletableFuture<Void>{{else}}java.util.concurrent.CompletableFuture<{{{boxedOutputFqcn}}}>{{/if}} {{handlersClassMethodName}}Async({{#if ../isKeyed}}String key, {{/if}}{{^inputEmpty}}{{{inputFqcn}}} req, {{/inputEmpty}}Consumer<dev.restate.common.RequestBuilder<{{{boxedInputFqcn}}}, {{{boxedOutputFqcn}}}>> requestBuilderApplier) {
var reqBuilder = {{../handlersClass}}.{{handlersClassMethodName}}({{#if ../isKeyed}}key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}req{{/inputEmpty}});
if (requestBuilderApplier != null) {
requestBuilderApplier.accept(reqBuilder);
}
return this.client.callAsync(reqBuilder.build()).thenApply(dev.restate.client.Response::response);
}
{{/if}}{{/handlers}}
public Send send() {
return new Send();
}
public class Send {
{{#handlers}}{{^isWorkflow}}
public dev.restate.client.SendResponse<{{{boxedOutputFqcn}}}> {{handlersClassMethodName}}({{#if ../isKeyed}}String key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}{{{inputFqcn}}} req{{/inputEmpty}}) {
return GatewayClient.this.client.send(
{{../handlersClass}}.{{handlersClassMethodName}}({{#if ../isKeyed}}key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}req{{/inputEmpty}})
);
}
public dev.restate.client.SendResponse<{{{boxedOutputFqcn}}}> {{handlersClassMethodName}}({{#if ../isKeyed}}String key, {{/if}}{{^inputEmpty}}{{{inputFqcn}}} req, {{/inputEmpty}}Consumer<dev.restate.common.RequestBuilder<{{{boxedInputFqcn}}}, {{{boxedOutputFqcn}}}>> requestBuilderApplier) {
var reqBuilder = {{../handlersClass}}.{{handlersClassMethodName}}({{#if ../isKeyed}}key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}req{{/inputEmpty}});
if (requestBuilderApplier != null) {
requestBuilderApplier.accept(reqBuilder);
}
return GatewayClient.this.client.send(reqBuilder);
}
public dev.restate.client.SendResponse<{{{boxedOutputFqcn}}}> {{handlersClassMethodName}}({{#if ../isKeyed}}String key, {{/if}}{{^inputEmpty}}{{{inputFqcn}}} req, {{/inputEmpty}}Duration delay) {
return GatewayClient.this.client.send(
{{../handlersClass}}.{{handlersClassMethodName}}({{#if ../isKeyed}}key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}req{{/inputEmpty}}), delay
);
}
public dev.restate.client.SendResponse<{{{boxedOutputFqcn}}}> {{handlersClassMethodName}}({{#if ../isKeyed}}String key, {{/if}}{{^inputEmpty}}{{{inputFqcn}}} req, {{/inputEmpty}}Duration delay, Consumer<dev.restate.common.RequestBuilder<{{{boxedInputFqcn}}}, {{{boxedOutputFqcn}}}>> requestBuilderApplier) {
var reqBuilder = {{../handlersClass}}.{{handlersClassMethodName}}({{#if ../isKeyed}}key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}req{{/inputEmpty}});
if (requestBuilderApplier != null) {
requestBuilderApplier.accept(reqBuilder);
}
return GatewayClient.this.client.send(reqBuilder, delay);
}
public java.util.concurrent.CompletableFuture<dev.restate.client.SendResponse<{{{boxedOutputFqcn}}}>> {{handlersClassMethodName}}Async({{#if ../isKeyed}}String key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}{{{inputFqcn}}} req{{/inputEmpty}}) {
return GatewayClient.this.client.sendAsync(
{{../handlersClass}}.{{handlersClassMethodName}}({{#if ../isKeyed}}key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}req{{/inputEmpty}})
);
}
public java.util.concurrent.CompletableFuture<dev.restate.client.SendResponse<{{{boxedOutputFqcn}}}>> {{handlersClassMethodName}}Async({{#if ../isKeyed}}String key, {{/if}}{{^inputEmpty}}{{{inputFqcn}}} req, {{/inputEmpty}}Consumer<dev.restate.common.RequestBuilder<{{{boxedInputFqcn}}}, {{{boxedOutputFqcn}}}>> requestBuilderApplier) {
var reqBuilder = {{../handlersClass}}.{{handlersClassMethodName}}({{#if ../isKeyed}}key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}req{{/inputEmpty}});
if (requestBuilderApplier != null) {
requestBuilderApplier.accept(reqBuilder);
}
return GatewayClient.this.client.sendAsync(reqBuilder);
}
public java.util.concurrent.CompletableFuture<dev.restate.client.SendResponse<{{{boxedOutputFqcn}}}>> {{handlersClassMethodName}}Async({{#if ../isKeyed}}String key, {{/if}}{{^inputEmpty}}{{{inputFqcn}}} req, {{/inputEmpty}}Duration delay) {
return GatewayClient.this.client.sendAsync(
{{../handlersClass}}.{{handlersClassMethodName}}({{#if ../isKeyed}}key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}req{{/inputEmpty}}), delay
);
}
public java.util.concurrent.CompletableFuture<dev.restate.client.SendResponse<{{{boxedOutputFqcn}}}>> {{handlersClassMethodName}}Async({{#if ../isKeyed}}String key, {{/if}}{{^inputEmpty}}{{{inputFqcn}}} req, {{/inputEmpty}}Duration delay, Consumer<dev.restate.common.RequestBuilder<{{{boxedInputFqcn}}}, {{{boxedOutputFqcn}}}>> requestBuilderApplier) {
var reqBuilder = {{../handlersClass}}.{{handlersClassMethodName}}({{#if ../isKeyed}}key{{^inputEmpty}}, {{/inputEmpty}}{{/if}}{{^inputEmpty}}req{{/inputEmpty}});
if (requestBuilderApplier != null) {
requestBuilderApplier.accept(reqBuilder);
}
return GatewayClient.this.client.sendAsync(reqBuilder, delay);
}{{/isWorkflow}}{{/handlers}}
}
}
Changing the current IngressClient codegen is a breaking change, so I added an additional class GatewayClient.
Metadata
Metadata
Assignees
Labels
No labels