Skip to content

Commit aee8840

Browse files
Merge pull request #114 from XavierGeerinck/master
Add Actor example
2 parents 422e902 + 6fb829d commit aee8840

File tree

1 file changed

+33
-31
lines changed

1 file changed

+33
-31
lines changed

examples/http/actor/src/index.ts

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,43 +37,45 @@ async function start() {
3737
console.log("EXECUTING CLIENT - ACTORS");
3838
console.log("Note: we create new client for now since Actors are not supported internally!")
3939
console.log("===============================================================");
40+
const actorId = "MyActorId1";
4041

4142

4243
const resRegisteredActors = await server.actor.getRegisteredActors();
4344
console.log(`Registered Actor Types: ${JSON.stringify(resRegisteredActors)}`);
44-
45-
// console.log("[Dapr-JS][Example][Actors] Trying to invoke method 'say' with msg 'hello world'");
46-
// const resActorInvokeSay = await client.actor.invoke("PUT", DemoActorSayImpl.name, "MyActorId1", "say", "Hello World");
47-
// console.log(`[Dapr-JS][Example][Actors] Invoked Method and got data: ${resActorInvokeSay}`);
4845

49-
// const resActorStateGet = await clientActor.actor.stateGet("DemoActor", "MyActorId1", "PropertyA");
50-
// await clientActor.actor.stateTransaction("DemoActor", "MyActorId1", [
51-
// {
52-
// operation: "upsert",
53-
// request: {
54-
// key: "key-1",
55-
// value: "my-new-data-1"
56-
// }
57-
// },
58-
// {
59-
// operation: "upsert",
60-
// request: {
61-
// key: "key-to-delete",
62-
// value: "my-new-data-1"
63-
// }
64-
// },
65-
// {
66-
// operation: "delete",
67-
// request: {
68-
// key: "key-to-delete"
69-
// }
70-
// }
71-
// ]);
46+
console.log("[Dapr-JS][Example][Actors] Trying to invoke method 'say' with msg 'hello world'");
47+
const resActorInvokeSay = await client.actor.invoke("PUT", DemoActorSayImpl.name, actorId, "sayString", "Hello World");
48+
console.log(`[Dapr-JS][Example][Actors] Invoked Method and got data: ${resActorInvokeSay}`);
7249

73-
// const resActorStateGet = await clientActor.actor.stateGet("DemoActor", "MyActorId1", "key-to-delete");
74-
// console.log(`[Dapr-JS][Example][Actors] Get State (should be empty): ${JSON.stringify(resActorStateGet)}`);
75-
// const resActorStateGet2 = await clientActor.actor.stateGet("DemoActor", "MyActorId1", "key-1");
76-
// console.log(`[Dapr-JS][Example][Actors] Get State (should be my-new-data-1): ${JSON.stringify(resActorStateGet2)}`);
50+
let resActorStateGet = await client.actor.stateGet(DemoActorSayImpl.name, actorId, "PropertyA");
51+
await client.actor.stateTransaction(DemoActorSayImpl.name, actorId, [
52+
{
53+
operation: "upsert",
54+
request: {
55+
key: "key-1",
56+
value: "my-new-data-1"
57+
}
58+
},
59+
{
60+
operation: "upsert",
61+
request: {
62+
key: "key-to-delete",
63+
value: "my-new-data-1"
64+
}
65+
},
66+
{
67+
operation: "delete",
68+
request: {
69+
key: "key-to-delete"
70+
}
71+
}
72+
]);
73+
74+
resActorStateGet = await client.actor.stateGet(DemoActorSayImpl.name, actorId, "key-to-delete");
75+
console.log(`[Dapr-JS][Example][Actors] Get State (should be empty): ${JSON.stringify(resActorStateGet)}`);
76+
77+
const resActorStateGet2 = await client.actor.stateGet(DemoActorSayImpl.name, actorId, "key-1");
78+
console.log(`[Dapr-JS][Example][Actors] Get State (should be my-new-data-1): ${JSON.stringify(resActorStateGet2)}`);
7779
}
7880

7981
start().catch((e) => {

0 commit comments

Comments
 (0)