Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into python_tour
Browse files Browse the repository at this point in the history
# Conflicts:
#	code_snippets/go/go.mod
#	code_snippets/go/go.sum
#	docs/get_started/tour.mdx
#	restate.config.json
  • Loading branch information
gvdongen committed Sep 9, 2024
2 parents a97c09e + 953fcac commit a31e199
Show file tree
Hide file tree
Showing 19 changed files with 1,257 additions and 1,068 deletions.
2 changes: 1 addition & 1 deletion code_snippets/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/aws/aws-lambda-go v1.47.0
github.com/awslabs/aws-lambda-go-api-proxy v0.16.2
github.com/restatedev/examples/tutorials/tour-of-restate-go v0.0.0-20240822081842-d36fec58c6cf
github.com/restatedev/sdk-go v0.10.1-0.20240822083433-0d57a0aef17b
github.com/restatedev/sdk-go v0.11.0
google.golang.org/protobuf v1.34.2
)

Expand Down
4 changes: 2 additions & 2 deletions code_snippets/go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/restatedev/examples/tutorials/tour-of-restate-go v0.0.0-20240822081842-d36fec58c6cf h1:biOe8TVlMe0wnsXjmOBZPZJUvJclvPMAa2LysiH2oJY=
github.com/restatedev/examples/tutorials/tour-of-restate-go v0.0.0-20240822081842-d36fec58c6cf/go.mod h1:K0LyoiZk9ZKsNHJiPpfV80AOzX9MU+d26YTXHlY0qjk=
github.com/restatedev/sdk-go v0.10.1-0.20240822083433-0d57a0aef17b h1:d+w/Ch3tIZtJ0v2qyucNTWOujrh+3/NZBOFw5qj/8UE=
github.com/restatedev/sdk-go v0.10.1-0.20240822083433-0d57a0aef17b/go.mod h1:6gHoU8pyP7YQfFWxKG2u94u/TSGen0qN7BWowWNDw4Y=
github.com/restatedev/sdk-go v0.11.0 h1:5pN5XSlTxJBWHZEuY0fZPorKU6xncz5CPGnnCChgjxg=
github.com/restatedev/sdk-go v0.11.0/go.mod h1:6gHoU8pyP7YQfFWxKG2u94u/TSGen0qN7BWowWNDw4Y=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
Expand Down
1,722 changes: 854 additions & 868 deletions code_snippets/ts/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions code_snippets/ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
},
"dependencies": {
"@restatedev/restate-cdk": "^1.0.0",
"@restatedev/restate-sdk": "^1.0.0",
"@restatedev/restate-sdk-clients": "^1.0.0",
"@restatedev/restate-sdk": "^1.3.0",
"@restatedev/restate-sdk-clients": "^1.3.0",
"express": "^4.19.2"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions code_snippets/ts/src/concepts/invocations/delayed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ async function myRestateHandler(ctx: restate.Context) {
// focus
ctx
// focus
.serviceSendClient(greeter, { delay: 1000 })
.serviceSendClient(greeter)
// focus
.greet({ greeting: "Hi" });
.greet({ greeting: "Hi" }, restate.rpc.sendOpts({ delay: 1000 }));
}
// <end_delayed_call>
5 changes: 2 additions & 3 deletions code_snippets/ts/src/concepts/invocations/ingress/delayed.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as restate from "@restatedev/restate-sdk-clients";
import { greetCounter, greeter } from "../utils";
import { SendOpts } from "@restatedev/restate-sdk-clients";
import { greeter } from "../utils";

// <start_delayed_call_node>
const myPlainTSFunction = async () => {
Expand All @@ -11,6 +10,6 @@ const myPlainTSFunction = async () => {
// focus
.serviceSendClient(greeter)
// focus
.greet({ greeting: "Hi" }, SendOpts.from({ delay: 1000 }));
.greet({ greeting: "Hi" }, restate.rpc.sendOpts({ delay: 1000 }));
};
// <end_delayed_call_node>
9 changes: 4 additions & 5 deletions code_snippets/ts/src/develop/clients/ingress.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
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";

Expand Down Expand Up @@ -35,11 +34,11 @@ const myPlainTSFunction3 = async () => {
const rs = clients.connect({ url: "http://localhost:8080" });
await rs
.serviceSendClient(greeterService)
.greet({ greeting: "Hi" }, SendOpts.from({ delay: 1000 }));
.greet({ greeting: "Hi" }, clients.rpc.sendOpts({ delay: 1000 }));

await rs
.objectSendClient(greetCounterObject, "Mary")
.greet({ greeting: "Hi" }, SendOpts.from({ delay: 1000 }));
.greet({ greeting: "Hi" }, clients.rpc.sendOpts({ delay: 1000 }));
// <end_delayed_call_node>
};

Expand All @@ -50,7 +49,7 @@ const servicesIdempotent = async () => {
await rs
.serviceSendClient(greeterService)
// withClass highlight-line
.greet(request, SendOpts.from({ idempotencyKey: "abcde" }));
.greet(request, clients.rpc.sendOpts({ idempotencyKey: "abcde" }));
// <end_service_idempotent>
};

Expand All @@ -63,7 +62,7 @@ const servicesAttach = async () => {
const handle = await rs
.serviceSendClient(greeterService)
// mark
.greet(request, SendOpts.from({ idempotencyKey: "abcde" }));
.greet(request, clients.rpc.sendOpts({ idempotencyKey: "abcde" }));

// ... do something else ...

Expand Down
46 changes: 46 additions & 0 deletions code_snippets/ts/src/develop/serialization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as restate from "@restatedev/restate-sdk";
import {Context, WorkflowContext} from "@restatedev/restate-sdk";

// <start_service_definition>
const myService = restate.service({
name: "MyService",
handlers: {
myHandler: restate.handlers.handler({
// Set the input serde here
input: restate.serde.binary,
// Set the output serde here
output: restate.serde.binary
}, async (ctx: Context, data: Uint8Array): Promise<Uint8Array> => {
// Process the request
return data;
}),
},
});
// <end_service_definition>

let ctx: WorkflowContext = undefined as unknown as WorkflowContext;
let input = new Uint8Array();

// <start_client>
ctx.serviceClient(myService)
.myHandler(
input,
restate.rpc.opts({
input: restate.serde.binary,
output: restate.serde.binary
})
);
// <end_client>

// <start_state>
ctx.get("my-binary-data", restate.serde.binary);
ctx.set("my-binary-data", new Uint8Array(), restate.serde.binary);
// <end_state>

// <start_awakeable>
ctx.awakeable(restate.serde.binary)
// <end_awakeable>

// <start_run>
ctx.run("my-side-effect", () => new Uint8Array(), { serde: restate.serde.binary });
// <end_run>
6 changes: 3 additions & 3 deletions code_snippets/ts/src/develop/service_communication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ const service = restate.service({
// <end_one_way_object>

// <start_delayed_service>
ctx.serviceSendClient(MyService, { delay: 5000 }).myHandler("Hi");
ctx.serviceSendClient(MyService).myHandler("Hi", restate.rpc.sendOpts({ delay: 5000 }));
// <end_delayed_service>

// <start_delayed_object>
ctx
.objectSendClient(MyVirtualObject, "Mary", { delay: 5000 })
.myHandler("Hi");
.objectSendClient(MyVirtualObject, "Mary")
.myHandler("Hi", restate.rpc.sendOpts({ delay: 5000 }));
// <end_delayed_object>

// <start_ordering>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function submitAndAwaitTask(task: TaskOpts) {
.runTask(
task,
// <mark_2>
SendOpts.from({ idempotencyKey: "dQw4w9WgXcQ" })
restate.rpc.sendOpts({ idempotencyKey: "dQw4w9WgXcQ" })
// </mark_2>
);
// </mark_1>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const eventEnricher = restate.object({
ctx.set("user", event);
// </mark_1>
// <mark_3>
ctx.objectSendClient(EventEnricher, ctx.key, { delay: 1000 }).emit();
ctx.objectSendClient(EventEnricher, ctx.key).emit(restate.rpc.sendOpts({ delay: 1000 }));
// </mark_3>
},

Expand Down
9 changes: 2 additions & 7 deletions docs/deploy/cloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ import Admonition from '@theme/Admonition';

# Restate Cloud

<Admonition type="warning">
Restate Cloud free tier is in early access and we don't offer strict
availability or durability SLAs at this time.
</Admonition>

[Restate Cloud](https://cloud.restate.dev) is the early-access managed service of Restate, where we run an instance of the Restate server for you. This allows you to focus on your services, which you can deploy wherever you normally do - long-lived compute, or serverless platforms like Lambda.
[Restate Cloud](https://restate.dev/cloud) is a fully managed serverless version of Restate, with a suite of tools supporting a stellar local development experience, and security features like [request signing](#securing-your-services) and [IAM roles for AWS Lambda](#aws-lambda-services). This allows you to focus on your services, which you can deploy wherever you normally do, while Restate Cloud handles all aspects of availability and durability for your invocations, workflows, and state.

## Creating your first environment

Expand Down Expand Up @@ -68,7 +63,7 @@ identity in the same account that the Lambda is deployed to. Create a new role
that has permission to invoke your Lambda handlers, and give it the following
trust policy.

<Admonition type="warning">
<Admonition type="info">
The Restate Cloud role is distinct from the Lambda function's execution role.
The execution role is assumed by your function to perform its work. A dedicated
invoker role is needed to grant Restate Cloud permission to invoke service handler
Expand Down
2 changes: 1 addition & 1 deletion docs/develop/java/clients.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Invoke a handler programmatically with the SDK clients as follows:

<Step stepLabel="1" title="Add the dependency to your project">
```kotlin
implementation("dev.restate:sdk-common:VAR::TYPESCRIPT_SDK_VERSION")
implementation("dev.restate:sdk-common:VAR::JAVA_SDK_VERSION")
```
</Step>
<Step stepLabel="2" title={<span><a href={"/operate/registration"}>Register the service</a> you want to invoke.</span>}/>
Expand Down
43 changes: 43 additions & 0 deletions docs/develop/ts/serialization.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
sidebar_position: 9
description: "How to serialize and deserialize data with the Restate SDK."
---

# Serialization

Restate sends data over the network for storing state, journaling actions, awakeables, etc.

By default, Typescript SDK uses the built-in [JSON](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON)
support to perform (de)serialization, but it is possible to override this behavior using the `Serde` interface.

For example, to customize the `Serde` to use for the handler input and output:

```typescript
CODE_LOAD::ts/src/develop/serialization.ts#service_definition
```

To customize the serde to use on requests:

```typescript
CODE_LOAD::ts/src/develop/serialization.ts#client
```

When sending a request to a handler configured with custom serde(s) you always need to manually specify them, because the client does not automatically infer what serde(s) should be used.

To customize the serde to use for state:

```typescript
CODE_LOAD::ts/src/develop/serialization.ts#state
```

For awakeables:

```typescript
CODE_LOAD::ts/src/develop/serialization.ts#awakeable
```

For `run`:

```typescript
CODE_LOAD::ts/src/develop/serialization.ts#run
```
Loading

0 comments on commit a31e199

Please sign in to comment.