diff --git a/code_snippets/java/src/main/java/develop/workflows/WorkflowSubmitter.java b/code_snippets/java/src/main/java/develop/workflows/WorkflowSubmitter.java index 60b30e82..2c4412f9 100644 --- a/code_snippets/java/src/main/java/develop/workflows/WorkflowSubmitter.java +++ b/code_snippets/java/src/main/java/develop/workflows/WorkflowSubmitter.java @@ -2,6 +2,7 @@ import dev.restate.sdk.client.Client; import dev.restate.sdk.client.SendResponse; +import dev.restate.sdk.common.Output; public class WorkflowSubmitter { @@ -20,10 +21,20 @@ public void submitWorkflow(Email email) { // // + // Option 1: attach and wait for result boolean result = SignupWorkflowClient .fromClient(restate, "someone") .workflowHandle() .attach(); + + // Option 2: peek to check if ready + Output peekOutput = SignupWorkflowClient + .fromClient(restate, "someone") + .workflowHandle() + .getOutput(); + if(peekOutput.isReady()){ + boolean result2 = peekOutput.getValue(); + } // } diff --git a/code_snippets/java/src/main/java/operate/invocations/Ingress.java b/code_snippets/java/src/main/java/operate/invocations/Ingress.java index bb9c182b..ce7b1b15 100644 --- a/code_snippets/java/src/main/java/operate/invocations/Ingress.java +++ b/code_snippets/java/src/main/java/operate/invocations/Ingress.java @@ -34,9 +34,6 @@ public void myOneWayCallHandler(Context ctx) { GreetCounterObjectClient.fromClient(rs, "Mary") .send() .greet("Hi"); - - MyWorkflowClient.fromClient(rs, "wf-id-1") - .submit("input"); // } @@ -70,77 +67,25 @@ public void attach() { Client rs = Client.connect("http://localhost:8080"); SendResponse handle = GreeterServiceClient.fromClient(rs) .send() + // mark .greet("Hi", CallRequestOptions.DEFAULT.withIdempotency("abcde")); // ... do something else ... - // Attach later to retrieve the result - // withClass(1:3) highlight-line + // Option 1: Attach later to retrieve the result + // mark(1:3) String greeting = rs .invocationHandle(handle.getInvocationId(), JsonSerdes.STRING) .attach(); - // - } - - public void peekAtOutput(){ - // - Client rs = Client.connect("http://localhost:8080"); - SendResponse handle = GreeterServiceClient.fromClient(rs) - .send() - .greet("Hi", CallRequestOptions.DEFAULT.withIdempotency("abcde")); - - // ... do something else ... - - // Peek to see if the result is ready - // withClass(1:3) highlight-line - Output output = rs - .invocationHandle(handle.getInvocationId(), JsonSerdes.STRING) - .getOutput(); - - if (output.isReady()) { - String result = output.getValue(); - } - // - } - - public void latchOntoWorkflow(){ - - // - Client rs = Client.connect("http://localhost:8080"); - SendResponse handle = MyWorkflowClient - .fromClient(rs, "wf-id-1") - .submit("input"); - - // If you have access to the workflow handle: - // withClass(1:3) highlight-line - String response = rs - .invocationHandle(handle.getInvocationId(), JsonSerdes.STRING) - .attach(); - // If you do not have access to the workflow handle, use the workflow ID: - String response2 = MyWorkflowClient.fromClient(rs, "wf-id-1") - // withClass(1:2) highlight-line - .workflowHandle() - .attach(); - // - - // - // If you have access to the workflow handle: - // withClass(1:3) highlight-line + // Option 2: Peek to see if the result is ready + // mark(1:3) Output output = rs .invocationHandle(handle.getInvocationId(), JsonSerdes.STRING) .getOutput(); - if (output.isReady()) { String result = output.getValue(); } - - // If you do not have access to the workflow handle, use the workflow ID: - Output output2 = MyWorkflowClient.fromClient(rs, "wf-id-1") - // withClass(1:2) highlight-line - .workflowHandle() - .getOutput(); - // - + // } } diff --git a/code_snippets/ts/src/develop/workflows/service.ts b/code_snippets/ts/src/develop/workflows/service.ts index 56c6f161..dab99fdd 100644 --- a/code_snippets/ts/src/develop/workflows/service.ts +++ b/code_snippets/ts/src/develop/workflows/service.ts @@ -7,7 +7,7 @@ export default restate.object({ handlers: { // signUpUser: async (ctx: ObjectContext, email: string) => { - // focus(1:2) + // focus(1:3) const result = await ctx .workflowClient({name: "signup"}, "someone") .run({email}); diff --git a/code_snippets/ts/src/develop/workflows/submit.ts b/code_snippets/ts/src/develop/workflows/submit.ts index 957e430e..9484108d 100644 --- a/code_snippets/ts/src/develop/workflows/submit.ts +++ b/code_snippets/ts/src/develop/workflows/submit.ts @@ -7,7 +7,8 @@ async function signUpUser(user: User){ // // import * as restate from "@restatedev/restate-sdk-clients"; const rs = restate.connect({url: "http://localhost:8080"}); - await rs.workflowClient({name: "signup"}, "someone") + const handle = await rs + .workflowClient({name: "signup"}, "someone") .workflowSubmit({email: user.email}); // @@ -18,9 +19,21 @@ async function signUpUser(user: User){ // // - const result = await rs + // Option 1: attach and wait for result with handle + const result1 = await rs.result(handle); + + // Option 2: attach and wait for result with workflow ID + const result2 = await rs .workflowClient({name: "signup"}, "someone") .workflowAttach(); + + // Option 3: peek to check if ready with workflow ID + const peekOutput = await rs + .workflowClient({name: "signup"}, "someone") + .workflowOutput(); + if(peekOutput.ready){ + const result3 = peekOutput.result; + } // } diff --git a/code_snippets/ts/src/operate/invocations/ingress.ts b/code_snippets/ts/src/operate/invocations/ingress.ts index c1dc0e3c..ec5c4117 100644 --- a/code_snippets/ts/src/operate/invocations/ingress.ts +++ b/code_snippets/ts/src/operate/invocations/ingress.ts @@ -1,59 +1,48 @@ import {greetCounterObject, greeterService} from "./utils"; import {SendOpts} from "@restatedev/restate-sdk-clients"; import {myWorkflow} from "../../concepts/invocations/utils"; - -// import * as clients from "@restatedev/restate-sdk-clients"; -// const myPlainTSFunction = async () => { // + // import * as clients from "@restatedev/restate-sdk-clients"; const rs = clients.connect({url: "http://localhost:8080"}); const greet = await rs.serviceClient(greeterService) .greet({greeting: "Hi"}); const count = await rs.objectClient(greetCounterObject, "Mary") .greet({greeting: "Hi"}); - - // You cannot **submit** workflows via request-response with the clients. - // You can call the other handlers of workflows via request-response. - const response = await rs.workflowClient(myWorkflow, "wf-id-1") - .myOtherHandler({input: "Hi"}); // } const myPlainTSFunction2 = async () => { // + // import * as clients from "@restatedev/restate-sdk-clients"; const rs = clients.connect({url: "http://localhost:8080"}); await rs.serviceSendClient(greeterService) .greet({greeting: "Hi"}); await rs.objectSendClient(greetCounterObject, "Mary") .greet({greeting: "Hi"}); - - await rs.workflowClient(myWorkflow, "wf-id-1") - .workflowSubmit({input: "Hi"}); - // You cannot yet do one-way calls to other handlers of the workflows // } const myPlainTSFunction3 = async () => { // + // import * as clients from "@restatedev/restate-sdk-clients"; const rs = clients.connect({url: "http://localhost:8080"}); await rs.serviceSendClient(greeterService) .greet({greeting: "Hi"}, SendOpts.from({ delay: 1000 })); await rs.objectSendClient(greetCounterObject, "Mary") .greet({greeting: "Hi"}, SendOpts.from({ delay: 1000 })); - - // You cannot call any workflow handlers via delayed calls with the clients. // } const servicesIdempotent = async () => { const request = {greeting: "Hi"} - // const rs = clients.connect({url: "http://localhost:8080"}); + // await rs.serviceSendClient(greeterService) // withClass highlight-line .greet(request, SendOpts.from({ idempotencyKey: "abcde" })); @@ -63,49 +52,17 @@ const servicesIdempotent = async () => { const servicesAttach = async () => { const request = {greeting: "Hi"} // + // import * as clients from "@restatedev/restate-sdk-clients"; const rs = clients.connect({url: "http://localhost:8080"}); // Send a message const handle = await rs.serviceSendClient(greeterService) + // mark .greet(request, SendOpts.from({ idempotencyKey: "abcde" })); // ... do something else ... // Attach later to retrieve the result - // withClass highlight-line + // mark const response = await rs.result(handle); // } - -const workflowAttach = async () => { - // - const rs = clients.connect({url: "http://localhost:8080"}); - - // Submit the workflow - const handle = await rs.workflowClient(myWorkflow, "wf-id-1") - .workflowSubmit({input: "Hi"}); - - // ... do something else ... - - // Attach by using the handle: - // withClass highlight-line - const result = await rs.result(handle); - - // Or, attach by using the workflow ID (from another service): - // withClass highlight-line - const result2 = await rs.workflowClient(myWorkflow, "wf-id-1").workflowAttach(); - // -} - -const workflowPeek = async () => { - // - const rs = clients.connect({url: "http://localhost:8080"}); - - // Peek at the output by using the workflow ID (from another service): - // withClass highlight-line - const output = await rs.workflowClient(myWorkflow, "wf-id-1").workflowOutput(); - // If the workflow is ready, do something with the result - if (output.ready) { - console.log(output.result); - } - // -} diff --git a/docs/develop/java/clients.mdx b/docs/develop/java/clients.mdx new file mode 100644 index 00000000..a58668a9 --- /dev/null +++ b/docs/develop/java/clients.mdx @@ -0,0 +1,113 @@ +--- +sidebar_position: 13 +description: "Use the clients to invoke handlers programmatically." +--- + +import Admonition from '@theme/Admonition'; +import {Step} from "../../../src/components/Stepper"; + +# Clients +The Restate SDK client library lets you invoke Restate handlers from anywhere in your application. +Use this only in non-Restate services without access to the Restate Context. + + + Always [invoke handlers via the context](/develop/java/service-communication), if you have access to it. + Restate then attaches information about the invocation to the parent invocation. + + +## Invoking handlers with the SDK clients + +Invoke a handler programmatically with the SDK clients as follows: + + + ```kotlin + implementation("dev.restate:sdk-common:VAR::TYPESCRIPT_SDK_VERSION") + ``` + +Register the service you want to invoke.}/> + + + + ```java + CODE_LOAD::java/src/main/java/operate/invocations/Ingress.java#- + ``` + + --- + + **Request-response invocations** allow you to wait on a response from the handler. + + --- + + ```java + CODE_LOAD::java/src/main/java/operate/invocations/Ingress.java#- + ``` + + **One-way invocations** allow you to send a message without waiting for a response. + + --- + + ```java + CODE_LOAD::java/src/main/java/operate/invocations/Ingress.java#- + ``` + + **Delayed invocations** allow you to schedule an invocation for a later point in time. + + + + + + [Have a look at the workflow documentation to learn what's different when invoking workflows.](/develop/java/workflows#submitting-workflows-with-sdk-clients) + + +## Invoke a handler idempotently + +To make a service call idempotent, you can use the idempotency key feature. +Add the idempotency key [to the header](https://datatracker.ietf.org/doc/draft-ietf-httpapi-idempotency-key-header/) via: + +```java +CODE_LOAD::java/src/main/java/operate/invocations/Ingress.java#- +``` + +After the invocation completes, Restate persists the response for a retention period of one day (24 hours). +If you re-invoke the service with the same idempotency key within 24 hours, Restate sends back the same response and doesn't re-execute the request to the service. + + + By using Restate and an idempotency key, you can make any service call idempotent, without any extra code or setup. + This is a very powerful feature to ensure that your system stays consistent and doesn't perform the same operation multiple times. + + + + The call options, with which we set the idempotency key, also let you add other headers to the request. + + +
+ Tuning retention time + + + You can tune the [retention time](focus://3) on a service-level by using the [Admin API](focus://1[15:28]) ([docs](/references/admin-api#tag/service/operation/modify_service)): + ```shell + curl -X PATCH localhost:9070/services/MyService \ + -H 'content-type: application/json' \ + -d '{"idempotency_retention": "2days"}' + ``` + The [retention time](focus://3) is in [humantime format](https://docs.rs/humantime/latest/humantime/). + + +
+ +## Retrieve result of invocations and workflows + +You can use the client library to retrieve the results of invocations **with an idempotency key** or workflows. +You can: +- Attach to an ongoing invocation and retrieve the result when it finishes. +- Peek at the output of a running invocation or workflow, to check if it has finished and optionally retrieve the result. + +You can use the invocation ID to attach or peek at a service/object invocation that used an idempotency key: + +```java +CODE_LOAD::java/src/main/java/operate/invocations/Ingress.java#- +``` + + + [Have a look at the workflow documentation to learn how to attach to workflow executions.](/develop/java/workflows#submitting-workflows-with-sdk-clients) + diff --git a/docs/develop/java/workflows.mdx b/docs/develop/java/workflows.mdx index b3ac0d0c..9fc203cc 100644 --- a/docs/develop/java/workflows.mdx +++ b/docs/develop/java/workflows.mdx @@ -82,7 +82,7 @@ Have a look at the code example to get a better understanding of how workflows a ## Submitting workflows with SDK clients - [**Submit**](/invoke/clients?sdk=java#invoking-handlers-with-the-sdk-clients): + [**Submit**](/develop/java/clients): This returns a handle to the workflow once it has been registered in Restate. You can only submit once per workflow ID (here `"someone"`). @@ -92,7 +92,7 @@ Have a look at the code example to get a better understanding of how workflows a - [**Query/signal**](/invoke/clients?sdk=java#invoking-handlers-with-the-sdk-clients): + [**Query/signal**](/develop/java/clients): Call the other handlers of the workflow in the same way as for Virtual Object handlers. Use `send()` for one-way calls. @@ -103,15 +103,15 @@ Have a look at the code example to get a better understanding of how workflows a - [**Attach**](/invoke/clients?sdk=java#retrieve-result-of-invocations-and-workflows): This lets you retrieve the result of a workflow later. + [**Attach/peek**](/develop/java/clients#retrieve-result-of-invocations-and-workflows): + This lets you retrieve the result of a workflow or check if it's finished. Use `.getOutput()` to peek whether the result is ready. - + ```java CODE_LOAD::java/src/main/java/develop/workflows/WorkflowSubmitter.java#- ``` - ## Submitting workflows from a Restate service @@ -130,7 +130,7 @@ Have a look at the code example to get a better understanding of how workflows a ## Submitting workflows over HTTP - [**Submit/query/signal**](/invoke/http#request-response-calls-over-http): + [**Submit/query/signal**](/invoke/http): Call any handler of the workflow in the same way as for Services and Virtual Objects. This returns the result of the handler once it has finished. Add `/send` to the path for one-way calls. @@ -145,8 +145,8 @@ Have a look at the code example to get a better understanding of how workflows a - [**Attach**](/invoke/http#retrieve-result-of-invocations-and-workflows): - This lets you retrieve the result of a workflow later. + [**Attach/peek**](/invoke/http#retrieve-result-of-invocations-and-workflows): + This lets you retrieve the result of a workflow or check if it's finished. ```shell curl localhost:8080/restate/workflow/SignupWorkflow/someone/attach diff --git a/docs/develop/ts/clients.mdx b/docs/develop/ts/clients.mdx new file mode 100644 index 00000000..5eb27219 --- /dev/null +++ b/docs/develop/ts/clients.mdx @@ -0,0 +1,108 @@ +--- +sidebar_position: 13 +description: "Use the clients to invoke handlers programmatically." +--- + +import Admonition from '@theme/Admonition'; +import {Step} from "../../../src/components/Stepper"; + +# Clients + +The Restate SDK client library lets you invoke Restate handlers from anywhere in your application. +Use this only in non-Restate services without access to the Restate Context. + + +Always [invoke handlers via the context](/develop/ts/service-communication), if you have access to it. +Restate then attaches information about the invocation to the parent invocation. + + +## Invoking handlers with the SDK clients + + + ```shell + npm install @restatedev/restate-sdk-clients + ``` + +Register the service you want to invoke.}/> + + + + ```typescript + CODE_LOAD::ts/src/operate/invocations/ingress.ts#- + ``` + + --- + + **Request-response invocations** allow you to wait on a response from the handler. + + --- + + ```typescript + CODE_LOAD::ts/src/operate/invocations/ingress.ts#- + ``` + + **One-way invocations** allow you to send a message without waiting for a response. + + --- + + ```typescript + CODE_LOAD::ts/src/operate/invocations/ingress.ts#- + ``` + + **Delayed invocations** allow you to schedule an invocation for a later point in time. + + + + +[Have a look at the workflow documentation to learn what's different when invoking workflows.](/develop/ts/workflows#submitting-workflows-with-sdk-clients) + + +## Invoke a handler idempotently + +To make a service call idempotent, you can use the idempotency key feature. +Add the idempotency key [to the header](https://datatracker.ietf.org/doc/draft-ietf-httpapi-idempotency-key-header/) via: + +```typescript +CODE_LOAD::ts/src/operate/invocations/ingress.ts#- +``` + +After the invocation completes, Restate persists the response for a retention period of one day (24 hours). +If you re-invoke the service with the same idempotency key within 24 hours, Restate sends back the same response and doesn't re-execute the request to the service. + + + By using Restate and an idempotency key, you can make any service call idempotent, without any extra code or setup. + This is a very powerful feature to ensure that your system stays consistent and doesn't perform the same operation multiple times. + + + + The call options, with which we set the idempotency key, also let you add other headers to the request. + + +
+ Tuning retention time + + + You can tune the [retention time](focus://3) on a service-level by using the [Admin API](focus://1[15:28]) ([docs](/references/admin-api#tag/service/operation/modify_service)): + ```shell + curl -X PATCH localhost:9070/services/MyService \ + -H 'content-type: application/json' \ + -d '{"idempotency_retention": "2days"}' + ``` + The [retention time](focus://3) is in [humantime format](https://docs.rs/humantime/latest/humantime/). + + +
+ +## Retrieve result of invocations and workflows + +You can use the client library to retrieve the results of invocations **with an idempotency key** or workflows. + +Attach to them by using the handle that is returned from the invocation: + +```typescript +CODE_LOAD::ts/src/operate/invocations/ingress.ts#- +``` + + + [Have a look at the workflow documentation to learn how to attach to workflow executions.](/develop/ts/workflows#submitting-workflows-with-sdk-clients) + \ No newline at end of file diff --git a/docs/develop/ts/workflows.mdx b/docs/develop/ts/workflows.mdx index b973f1dc..e0948d7b 100644 --- a/docs/develop/ts/workflows.mdx +++ b/docs/develop/ts/workflows.mdx @@ -80,8 +80,8 @@ Have a look at the code example to get a better understanding of how workflows a ## Submitting workflows with SDK clients - [**Submit**](/invoke/clients#invoking-handlers-with-the-sdk-clients): - This returns when the workflow has been registered in Restate. + [**Submit**](/develop/ts/clients): + This returns a handle to the workflow once has been registered in Restate. You can only submit once per workflow ID (here `"someone"`). ```ts @@ -91,7 +91,7 @@ Have a look at the code example to get a better understanding of how workflows a - [**Query/signal**](/invoke/clients#invoking-handlers-with-the-sdk-clients): + [**Query/signal**](/develop/ts/clients): Call the other handlers of the workflow in the same way as for Virtual Object handlers. For now, you can only do request-response calls. @@ -102,7 +102,8 @@ Have a look at the code example to get a better understanding of how workflows a - [**Attach**](/invoke/clients#retrieve-result-of-invocations-and-workflows): This lets you retrieve the result of a workflow later. + [**Attach/peek**](/develop/ts/clients#retrieve-result-of-invocations-and-workflows): + This lets you retrieve the result of a workflow or check if it's finished. ```ts CODE_LOAD::ts/src/develop/workflows/submit.ts#- @@ -140,8 +141,8 @@ Have a look at the code example to get a better understanding of how workflows a - [**Attach**](/invoke/http#retrieve-result-of-invocations-and-workflows): - This lets you retrieve the result of a workflow later. + [**Attach/peek**](/invoke/http#retrieve-result-of-invocations-and-workflows): + This lets you retrieve the result of a workflow or check if it's finished. ```shell curl localhost:8080/restate/workflow/signup/someone/attach diff --git a/docs/invoke/clients.mdx b/docs/invoke/clients.mdx index 8246067f..94b9b546 100644 --- a/docs/invoke/clients.mdx +++ b/docs/invoke/clients.mdx @@ -3,241 +3,34 @@ sidebar_position: 2 description: "Use the clients to invoke handlers programmatically." --- -import Tabs from '@theme/Tabs'; -import TabItem from '@theme/TabItem'; import Admonition from '@theme/Admonition'; -import {Step} from "../../src/components/Stepper"; +import FeatureWidget from "../../src/components/FeatureWidget"; # Clients -When you implement a Restate handler, you have access to a Restate `Context`. -You can use this context to invoke other handlers. -Have a look at the Development docs ([TS](/develop/ts/service-communication)/[Java](/develop/java/service-communication)/[Kotlin](/develop/java/service-communication?sdk=kotlin)). - -In plain TypeScript/Java/Kotlin code, where you do not have access to the Restate Context, you can invoke handlers programmatically using the Restate SDK client library. +The Restate SDK client library lets you invoke Restate handlers from anywhere in your application. +Use this only in non-Restate services without access to the Restate Context. -Always invoke handlers via the context, if you have access to it. -Restate then attaches information about the invocation to the parent invocation. - - -## Invoking handlers with the SDK clients - -Invoke a handler programmatically with the SDK clients as follows: - - - - - ```shell - npm install @restatedev/restate-sdk-clients - ``` - - Register the service you want to invoke.}/> - - - - ```typescript - CODE_LOAD::ts/src/operate/invocations/ingress.ts#- - ``` - - --- - - **Request-response invocations** allow you to wait on a response from the handler. - - --- - - ```typescript - CODE_LOAD::ts/src/operate/invocations/ingress.ts#- - ``` - - **One-way invocations** allow you to send a message without waiting for a response. - - --- - - ```typescript - CODE_LOAD::ts/src/operate/invocations/ingress.ts#- - ``` - - **Delayed invocations** allow you to schedule an invocation for a later point in time. - - - - - - ```kotlin - implementation("dev.restate:sdk-common:VAR::TYPESCRIPT_SDK_VERSION") - ``` - - Register the service you want to invoke.}/> - - - - ```java - CODE_LOAD::java/src/main/java/operate/invocations/Ingress.java#- - ``` - - --- - - **Request-response invocations** allow you to wait on a response from the handler. - - --- - - ```java - CODE_LOAD::java/src/main/java/operate/invocations/Ingress.java#- - ``` - - **One-way invocations** allow you to send a message without waiting for a response. - - --- - - ```java - CODE_LOAD::java/src/main/java/operate/invocations/Ingress.java#- - ``` - - **Delayed invocations** allow you to schedule an invocation for a later point in time. - - - - - - - - You can retrieve the results of one-way invocations with an idempotency key and workflows, as [described here](/invoke/clients#retrieve-result-of-invocations-and-workflows). - - -## Invoke a handler idempotently - -To make a service call idempotent, you can use the idempotency key feature. -Add the idempotency key [to the header](https://datatracker.ietf.org/doc/draft-ietf-httpapi-idempotency-key-header/) via: - - - - - ```typescript - CODE_LOAD::ts/src/operate/invocations/ingress.ts#- - ``` - - - - - ```java - CODE_LOAD::java/src/main/java/operate/invocations/Ingress.java#- - ``` - - - - - - -After the invocation completes, Restate persists the response for a retention period of one day (24 hours). -If you re-invoke the service with the same idempotency key within 24 hours, Restate sends back the same response and doesn't re-execute the request to the service. - - - By using Restate and an idempotency key, you can make any service call idempotent, without any extra code or setup. - This is a very powerful feature to ensure that your system stays consistent and doesn't perform the same operation multiple times. + Always [invoke handlers via the context](/develop/java/service-communication), if you have access to it. + Restate then attaches information about the invocation to the parent invocation. - - The call options, with which we set the idempotency key, also let you add other headers to the request. - - -
- Tuning retention time - - - You can tune the [retention time](focus://3) on a service-level by using the [Admin API](focus://1[15:28]) ([docs](/references/admin-api#tag/service/operation/modify_service)): - ```shell - curl -X PATCH localhost:9070/services/MyService \ - -H 'content-type: application/json' \ - -d '{"idempotency_retention": "2days"}' - ``` - The [retention time](focus://3) is in [humantime format](https://docs.rs/humantime/latest/humantime/). - - -
- -## Retrieve result of invocations and workflows - -You can use the client library to retrieve the results of invocations with an idempotency key or workflows. -You can: -- Attach to an ongoing invocation and retrieve the result when it finishes. -- Peek at the output of a running invocation or workflow, to check if it has finished and optionally retrieve the result. - -You can attach to a service/object invocation only if the invocation used an idempotency key. - - - - - - - ```typescript - CODE_LOAD::ts/src/operate/invocations/ingress.ts#- - ``` - - --- - - **Attach to service/object calls** by using the handle that is returned from the invocation. - - ```typescript - CODE_LOAD::ts/src/operate/invocations/ingress.ts#- - ``` - - --- - - **Attach to workflows** by using the handle that is returned from the invocation, or by using the workflow ID. - - ```typescript - CODE_LOAD::ts/src/operate/invocations/ingress.ts#- - ``` - - --- - - **Peek at the output of workflows** by using the workflow ID. - - ```typescript - CODE_LOAD::ts/src/operate/invocations/ingress.ts#- - ``` - - - - - - - ```java - CODE_LOAD::java/src/main/java/operate/invocations/Ingress.java#- - ``` - - --- - - **Attach to service/object calls** by using the handle that is returned from the invocation. - - ```java - CODE_LOAD::java/src/main/java/operate/invocations/Ingress.java#- - ``` - - --- - - **Peek at the output of service/object calls** by using the handle that is returned from the invocation. - - ```java - CODE_LOAD::java/src/main/java/operate/invocations/Ingress.java#- - ``` - - --- - - **Attach to workflows** by using the handle that is returned from the invocation, or by using the workflow ID. - - ```java - CODE_LOAD::java/src/main/java/operate/invocations/Ingress.java#- - ``` - - --- - - **Peek at the output of workflows** by using the workflow ID. - - ```java - CODE_LOAD::java/src/main/java/operate/invocations/Ingress.java#- - ``` - - - +Have a look at the documentation of the SDKs: + + diff --git a/docs/invoke/http.mdx b/docs/invoke/http.mdx index 94a99cb6..bb2fcb4d 100644 --- a/docs/invoke/http.mdx +++ b/docs/invoke/http.mdx @@ -82,11 +82,6 @@ curl localhost:8080/MyService/myHandler/send \ The response contains the [Invocation ID](/operate/invocation#invocation-identifier). You can use this identifier [to cancel](/operate/invocation#cancelling-invocations) or [kill the invocation](/operate/invocation#killing-invocations). - - You can retrieve the results of one-way invocations with an idempotency key and workflows, as [described here](/invoke/clients#retrieve-result-of-invocations-and-workflows). - - - ## Sending a delayed message over HTTP You can **delay the message** by adding a delay request parameter in ISO8601 notation or in seconds: @@ -161,48 +156,24 @@ There are two options: - The result for finished workflows - `{"message":"not found"}` for non-existing workflows -You can attach to a service/object invocation only if the invocation used an idempotency key. - - - - ```shell - curl localhost:8080/restate/invocation/myInvocationId/attach - curl localhost:8080/restate/invocation/myInvocationId/output - ``` - - --- - - Via invocation ID - - ```shell - curl localhost:8080/restate/invocation/myInvocationId/attach - curl localhost:8080/restate/invocation/myInvocationId/output - ``` - --- - - ```shell - curl localhost:8080/restate/invocation/MyService/myHandler/myIdempotencyKey/attach - curl localhost:8080/restate/invocation/MyService/myHandler/myIdempotencyKey/output - ``` - - For Services, via [idempotency key](/invoke/http#invoke-a-handler-idempotently) - - --- +You can attach to a service/object invocation only if the invocation used an idempotency key: - ```shell - curl localhost:8080/restate/invocation/myObject/myKey/myHandler/myIdempotencyKey/attach - curl localhost:8080/restate/invocation/myObject/myKey/myHandler/myIdempotencyKey/output - ``` +```shell +# Via invocation ID +curl localhost:8080/restate/invocation/myInvocationId/attach +curl localhost:8080/restate/invocation/myInvocationId/output - For Virtual Objects, via [idempotency key](/invoke/http#invoke-a-handler-idempotently) +# For Services, via idempotency key +curl localhost:8080/restate/invocation/MyService/myHandler/myIdempotencyKey/attach +curl localhost:8080/restate/invocation/MyService/myHandler/myIdempotencyKey/output - --- +# For Virtual Objects, via idempotency key +curl localhost:8080/restate/invocation/myObject/myKey/myHandler/myIdempotencyKey/attach +curl localhost:8080/restate/invocation/myObject/myKey/myHandler/myIdempotencyKey/output - ```shell - curl localhost:8080/restate/workflow/MyWorkflow/myWorkflowId/attach - curl localhost:8080/restate/workflow/MyWorkflow/myWorkflowId/output - ``` +# For Workflows, with the Workflow ID +curl localhost:8080/restate/workflow/MyWorkflow/myWorkflowId/attach +curl localhost:8080/restate/workflow/MyWorkflow/myWorkflowId/output +``` - For Workflows, with the Workflow ID -