-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds the support for the Event API for the keyed dynamic handlers. Since the dynamic handler API requires a string key, this means that the registered gRPC methods are of the form rpc Handle(StringKeyedEvent) returns (google.protobuf.Empty) {};
- Loading branch information
1 parent
08458c0
commit 0b19442
Showing
8 changed files
with
236 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2023 - Restate Software, Inc., Restate GmbH | ||
* | ||
* This file is part of the Restate SDK for Node.js/TypeScript, | ||
* which is released under the MIT license. | ||
* | ||
* You can find a copy of the license in file LICENSE in the root | ||
* directory of this repository or package, or at | ||
* https://github.com/restatedev/sdk-typescript/blob/main/LICENSE | ||
*/ | ||
|
||
/* eslint-disable no-console */ | ||
|
||
/* | ||
* A simple example program using the Restate's event handlers. | ||
*/ | ||
|
||
import * as restate from "../src/public_api"; | ||
|
||
const registration = async (ctx: restate.RpcContext, event: restate.Event) => { | ||
// store in state the user's information as coming from the registeration event | ||
const { name } = event.json<{ name: string }>(); | ||
ctx.set("name", name); | ||
}; | ||
|
||
const email = async (ctx: restate.RpcContext, event: restate.Event) => { | ||
// store in state the user's information as coming from the email event | ||
const { email } = event.json<{ email: string }>(); | ||
ctx.set("email", email); | ||
}; | ||
|
||
type UserProfile = { | ||
id: string; | ||
name: string; | ||
email: string; | ||
}; | ||
|
||
const get = async ( | ||
ctx: restate.RpcContext, | ||
id: string | ||
): Promise<UserProfile> => { | ||
return { | ||
id, | ||
name: (await ctx.get<string>("name")) ?? "", | ||
email: (await ctx.get<string>("email")) ?? "", | ||
}; | ||
}; | ||
|
||
const profile = restate.keyedRouter({ | ||
registration: restate.keyedEventHandler(registration), | ||
email: restate.keyedEventHandler(email), | ||
get, | ||
}); | ||
|
||
// restate server | ||
restate.createServer().bindKeyedRouter("profile", profile).listen(8080); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters