Skip to content

Commit 0bd71f3

Browse files
Merge pull request #137 from XavierGeerinck/master
feat(actors): implement actor proxy object and remove actor access remotely
2 parents 8c01eb3 + 0ce8ccd commit 0bd71f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3986
-6431
lines changed

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Changelog
2+
3+
## 2.x release
4+
5+
### v2.0.0
6+
7+
Version 2.0.0 brings a lot of changes to the Dapr JS SDK that were long due. Below an overview of the major contributions can be found, with a more detailed overview of the **Breaking Changes** under it.
8+
9+
* Actor Support has been added
10+
* Actor Proxy has been added for Actor Access
11+
* The HTTP Connection is now being reused to reduce the CONNRESET errors when intensively using the JS SDK
12+
13+
#### Breaking Changes
14+
15+
* `DaprServer.ts`: `startServer()`, `stopServer()` have been renamed to `start()` and `stop()` this means that `await server.startServer()` will now be called as `await server.start()`
16+
* `DaprServer.ts`: `close()` has been removed in favor of `stop()`
17+
18+
#### Major Changes
19+
20+
* KeepAlive for HTTP has been added and a new method in the `DaprClient` has been added named `stop()` to stop the client and release the connections kept by the sockets.
21+
22+
## 1.x release

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const client = new DaprClient(daprHost, daprPort);
5454

5555
// Initialize the server to subscribe (listen)
5656
await server.pubsub.subscribe("my-pubsub-component", "my-topic", async (data: any) => console.log(`Received: ${JSON.stringify(data)}`));
57-
await server.startServer();
57+
await server.start();
5858

5959
// Send a message
6060
await client.pubsub.publish("my-pubsub-component", "my-topic", { hello: "world" });

daprdocs/content/en/js-sdk-docs/js-actors/_index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ async function start() {
7171

7272
await server.actor.init(); // Let the server know we need actors
7373
server.actor.registerActor(ParkingSensorImpl); // Register the actor
74-
await server.startServer(); // Start the server
74+
await server.start(); // Start the server
7575
}
7676
```
7777

@@ -88,7 +88,7 @@ async function start() {
8888

8989
await server.actor.init();
9090
server.actor.registerActor(ParkingSensorImpl);
91-
await server.startServer();
91+
await server.start();
9292

9393

9494
await client.actor.invoke("PUT", ParkingSensorImpl.name, `actor-id`, "carEnter"); // Invoke the ParkingSensor Actor by calling the carEnter function
@@ -107,7 +107,7 @@ async function start() {
107107

108108
await server.actor.init();
109109
server.actor.registerActor(ParkingSensorImpl);
110-
await server.startServer();
110+
await server.start();
111111

112112
// Perform state transaction
113113
await client.actor.stateTransaction("ParkingSensorImpl", `actor-id`, [
@@ -152,7 +152,7 @@ async function start()
152152

153153
await server.actor.init();
154154
server.actor.registerActor(ParkingSensorImpl);
155-
await server.startServer();
155+
await server.start();
156156

157157
// Register a timer
158158
await client.actor.timerCreate(ParkingSensorImpl.name, `actor-id`, `timer-id`, {
@@ -177,7 +177,7 @@ async function start()
177177

178178
await server.actor.init();
179179
server.actor.registerActor(ParkingSensorImpl);
180-
await server.startServer();
180+
await server.start();
181181

182182

183183
// Register a reminder, it has a default callback

daprdocs/content/en/js-sdk-docs/js-client/_index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const client = new DaprClient(daprHost, daprPort, CommunicationProtocolEnum.GRPC
4141
A library that provides methods for how an application communicates with the Dapr sidecar.
4242

4343
##### DaprServer Library
44-
A library for how an application registers bindings / routes with Dapr. The `startServer()` method is used to start the server and bind the routes.
44+
A library for how an application registers bindings / routes with Dapr. The `start()` method is used to start the server and bind the routes.
4545

4646
## Building blocks
4747

@@ -165,7 +165,7 @@ async function start() {
165165
// Configure Subscriber for a Topic
166166
await server.pubsub.subscribe(pubSubName, topic, async (data: any) => console.log(`Got Data: ${JSON.stringify(data)}`));
167167

168-
await server.startServer();
168+
await server.start();
169169
}
170170
```
171171

@@ -207,7 +207,7 @@ async function start() {
207207

208208
const response = await server.binding.receive(bindingName, async (data: any) => console.log(`Got Data: ${JSON.stringify(data)}`));
209209

210-
await server.startServer();
210+
await server.start();
211211
}
212212
```
213213

examples/grpc/hello-world-distributed/server/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const serverPort = "50051"; // App Port of this Example Server
77

88
async function start() {
99
const server = new DaprServer(serverHost, serverPort, daprHost, daprPort, CommunicationProtocolEnum.GRPC);
10-
await server.startServer();
10+
await server.start();
1111

1212
await server.invoker.listen("hello-world", async (data: any) => {
1313
console.log("[Dapr-JS][Example] Received Hello World Method Call");
@@ -18,6 +18,6 @@ async function start() {
1818
}
1919

2020
start().catch((e) => {
21-
console.error(e);
22-
process.exit(1);
21+
console.error(e);
22+
process.exit(1);
2323
});

examples/grpc/hello-world/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ async function start() {
2727
// We initialize after registering our listeners since these should be defined upfront
2828
// this is how Dapr works, it waits until we are listening on the port. Once that is detected
2929
// it will scan the binding list and pubsub subscriptions list to process
30-
await server.startServer();
30+
await server.start();
3131

3232
console.log("===============================================================");
3333
console.log("EXECUTING CLIENT -INVOKER")
@@ -94,7 +94,7 @@ async function start() {
9494
const resState = await client.state.get("state-redis", "key-1");
9595
console.log(`[Dapr-JS][Example][State] Fetched State: ${JSON.stringify(resState)}`);
9696

97-
const resStateBulk = await client.state.getBulk("state-redis", [ "key-3", "key-2"]);
97+
const resStateBulk = await client.state.getBulk("state-redis", ["key-3", "key-2"]);
9898
console.log(`[Dapr-JS][Example][State] Fetched State Bulk: ${JSON.stringify(resStateBulk)}`);
9999

100100
await client.state.delete("state-redis", "key-2");

examples/http/actor-parking-sensor/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async function start() {
1919
console.log("===============================================================");
2020
await server.actor.init(); // Let the server know we need actors
2121
server.actor.registerActor(ParkingSensorImpl); // Register the actor
22-
await server.startServer(); // Start the server
22+
await server.start(); // Start the server
2323

2424
console.log("===============================================================");
2525
console.log("CLIENT EXECUTION");

examples/http/actor/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async function start() {
3131
// We initialize after registering our listeners since these should be defined upfront
3232
// this is how Dapr works, it waits until we are listening on the port. Once that is detected
3333
// it will scan the binding list and pubsub subscriptions list to process
34-
await server.startServer();
34+
await server.start();
3535

3636
console.log("===============================================================");
3737
console.log("EXECUTING CLIENT - ACTORS");

examples/http/pubsub/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async function start() {
1313

1414
// Initialize the server to subscribe (listen)
1515
await server.pubsub.subscribe("my-pubsub-component", "my-topic", async (data: any) => console.log(`Received: ${JSON.stringify(data)}`));
16-
await server.startServer();
16+
await server.start();
1717

1818
// Send a message
1919
await client.pubsub.publish("my-pubsub-component", "my-topic", { hello: "world" });

examples/invocation/src/index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@ import { DaprServer, DaprClient, HttpMethod, CommunicationProtocolEnum } from "d
33
// Common settings
44
const daprAppId = "example-invocation";
55
const serverHost = "127.0.0.1"; // App Host of this Example Server
6-
const daprHost = "127.0.0.1";
6+
const daprHost = "127.0.0.1";
77
const serverPort = "50051"; // App Port of this Example Server
88

99
async function start() {
1010
// Note that the DAPR_HTTP_PORT and DAPR_GRPC_PORT environment variables are set by DAPR itself. https://docs.dapr.io/reference/environment/
1111
const server = new DaprServer(
12-
serverHost,
13-
serverPort,
14-
daprHost,
15-
process.env.DAPR_HTTP_PORT,
12+
serverHost,
13+
serverPort,
14+
daprHost,
15+
process.env.DAPR_HTTP_PORT,
1616
CommunicationProtocolEnum.HTTP
1717
);
1818

1919
const client = new DaprClient(
20-
daprHost,
21-
process.env.DAPR_HTTP_PORT as string,
20+
daprHost,
21+
process.env.DAPR_HTTP_PORT as string,
2222
CommunicationProtocolEnum.HTTP
2323
);
2424

25-
// Note that invoker listeners can be set up after startServer() has been called
26-
await server.startServer();
25+
// Note that invoker listeners can be set up after start() has been called
26+
await server.start();
2727

2828
console.log("Setting up invocation endpoints")
2929
await server.invoker.listen("hello-world", async (data: Record<string, any>) => {

0 commit comments

Comments
 (0)