From 0aa120b10653b54f29ffe8a52c9792a6eaa194b7 Mon Sep 17 00:00:00 2001 From: MregXN Date: Fri, 1 Dec 2023 11:17:02 +0800 Subject: [PATCH 1/6] there can be only one topic registered Signed-off-by: MregXN --- examples/pubsub/src/index.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/pubsub/src/index.ts b/examples/pubsub/src/index.ts index 83ffd5fa..f81f97a0 100644 --- a/examples/pubsub/src/index.ts +++ b/examples/pubsub/src/index.ts @@ -31,6 +31,7 @@ async function start() { const client = new DaprClient({ daprHost, daprPort: process.env.DAPR_HTTP_PORT }); + // Initialize the subscription. Note that this must be done BEFORE calling .start() await server.pubsub.subscribe("my-pubsub-component", "my-topic", async (data: Record) => { // The library parses JSON when possible. @@ -38,7 +39,7 @@ async function start() { }); // Publish multiple messages to a topic with default config. - await server.pubsub.subscribeBulk("my-pubsub-component", "my-topic", async (data: Record) => { + await server.pubsub.subscribeBulk("my-pubsub-component", "my-topic-bulk", async (data: Record) => { // The library parses JSON when possible. console.log(`[Dapr-JS][Example] Received on subscription: ${JSON.stringify(data)}`); }); @@ -46,7 +47,7 @@ async function start() { // Publish multiple messages to a topic with specific maxMessagesCount and maxAwaitDurationMs. await server.pubsub.subscribeBulk( "my-pubsub-component", - "my-topic", + "my-topic-bulk-with-config", async (data: Record) => { // The library parses JSON when possible. console.log(`[Dapr-JS][Example] Received on subscription: ${JSON.stringify(data)}`); @@ -85,12 +86,12 @@ async function start() { console.log("[Dapr-JS][Example] Bulk publishing multiple plain messages"); const messages = ["message 1", "message 2", "message 3"]; - response = await client.pubsub.publishBulk("my-pubsub-component", "my-topic", messages); + response = await client.pubsub.publishBulk("my-pubsub-component", "my-topic-bulk", messages); console.log(`[Dapr-JS][Example] Bulk publish response: ${JSON.stringify(response)}`); console.log("[Dapr-JS][Example] Bulk publishing multiple JSON messages"); const jsonMessages = [{ hello: "message 1" }, { hello: "message 2" }, { hello: "message 3" }]; - response = await client.pubsub.publishBulk("my-pubsub-component", "my-topic", jsonMessages); + response = await client.pubsub.publishBulk("my-pubsub-component", "my-topic-bulk", jsonMessages); console.log(`[Dapr-JS][Example] Bulk publish response: ${JSON.stringify(response)}`); console.log("[Dapr-JS][Example] Bulk publishing with entryID and custom content type"); @@ -111,7 +112,7 @@ async function start() { event: "foo message 3", }, ]; - response = await client.pubsub.publishBulk("my-pubsub-component", "my-topic", bulkPublishMessages); + response = await client.pubsub.publishBulk("my-pubsub-component", "my-topic-bulk-with-config", bulkPublishMessages); console.log(`[Dapr-JS][Example] Bulk publish response: ${JSON.stringify(response)}`); } From 1f41f205cc944fa5ecb76eec1a7754455a0a1a53 Mon Sep 17 00:00:00 2001 From: MregXN Date: Fri, 1 Dec 2023 11:22:29 +0800 Subject: [PATCH 2/6] modify grpc client Signed-off-by: MregXN --- examples/pubsub/src/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/pubsub/src/index.ts b/examples/pubsub/src/index.ts index f81f97a0..c7282f61 100644 --- a/examples/pubsub/src/index.ts +++ b/examples/pubsub/src/index.ts @@ -11,7 +11,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { DaprClient, DaprServer } from "@dapr/dapr"; +import { CommunicationProtocolEnum, DaprClient, DaprServer } from "@dapr/dapr"; // Common settings const serverHost = "127.0.0.1"; // App Host of this Example Server @@ -23,14 +23,14 @@ async function start() { const server = new DaprServer({ serverHost, serverPort, + communicationProtocol: CommunicationProtocolEnum.GRPC, clientOptions: { daprHost, - daprPort: process.env.DAPR_HTTP_PORT, + daprPort: process.env.DAPR_GRPC_PORT, }, }); - const client = new DaprClient({ daprHost, daprPort: process.env.DAPR_HTTP_PORT }); - + const client = new DaprClient({daprHost, daprPort:process.env.DAPR_GRPC_PORT, communicationProtocol:CommunicationProtocolEnum.GRPC}); // Initialize the subscription. Note that this must be done BEFORE calling .start() await server.pubsub.subscribe("my-pubsub-component", "my-topic", async (data: Record) => { From 1cddd0fbcc255a5ab1f101c64bdf45a9a028af55 Mon Sep 17 00:00:00 2001 From: MregXN Date: Fri, 1 Dec 2023 11:29:34 +0800 Subject: [PATCH 3/6] typo Signed-off-by: MregXN --- examples/pubsub/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/pubsub/src/index.ts b/examples/pubsub/src/index.ts index c7282f61..00d4aa52 100644 --- a/examples/pubsub/src/index.ts +++ b/examples/pubsub/src/index.ts @@ -30,7 +30,7 @@ async function start() { }, }); - const client = new DaprClient({daprHost, daprPort:process.env.DAPR_GRPC_PORT, communicationProtocol:CommunicationProtocolEnum.GRPC}); + const client = new DaprClient(daprHost, process.env.DAPR_GRPC_PORT, CommunicationProtocolEnum.GRPC); // Initialize the subscription. Note that this must be done BEFORE calling .start() await server.pubsub.subscribe("my-pubsub-component", "my-topic", async (data: Record) => { From a80accd3428e70177b2fbdd2423d37ff82740b5f Mon Sep 17 00:00:00 2001 From: MregXN Date: Fri, 1 Dec 2023 11:30:48 +0800 Subject: [PATCH 4/6] modify README Signed-off-by: MregXN --- examples/pubsub/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/pubsub/README.md b/examples/pubsub/README.md index 71f168f4..16dca4e1 100644 --- a/examples/pubsub/README.md +++ b/examples/pubsub/README.md @@ -41,7 +41,8 @@ By default, the example uses HTTP. To use gRPC instead: daprPort: process.env.DAPR_GRPC_PORT, }, }); - const client = new DaprClient(daprHost, process.env.DAPR_GRPC_PORT, CommunicationProtocolEnum.GRPC); + + const client = new DaprClient({daprHost, daprPort:process.env.DAPR_GRPC_PORT, communicationProtocol:CommunicationProtocolEnum.GRPC}); ``` - To run: From c432ead497666e37c102fadd195fdd033fb0e3d9 Mon Sep 17 00:00:00 2001 From: MregXN Date: Fri, 1 Dec 2023 11:31:44 +0800 Subject: [PATCH 5/6] fix typo Signed-off-by: MregXN --- examples/pubsub/src/index.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/pubsub/src/index.ts b/examples/pubsub/src/index.ts index 00d4aa52..fa8cf998 100644 --- a/examples/pubsub/src/index.ts +++ b/examples/pubsub/src/index.ts @@ -11,7 +11,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { CommunicationProtocolEnum, DaprClient, DaprServer } from "@dapr/dapr"; +import { DaprClient, DaprServer } from "@dapr/dapr"; // Common settings const serverHost = "127.0.0.1"; // App Host of this Example Server @@ -23,14 +23,13 @@ async function start() { const server = new DaprServer({ serverHost, serverPort, - communicationProtocol: CommunicationProtocolEnum.GRPC, clientOptions: { daprHost, - daprPort: process.env.DAPR_GRPC_PORT, + daprPort: process.env.DAPR_HTTP_PORT, }, }); - const client = new DaprClient(daprHost, process.env.DAPR_GRPC_PORT, CommunicationProtocolEnum.GRPC); + const client = new DaprClient({ daprHost, daprPort: process.env.DAPR_HTTP_PORT }); // Initialize the subscription. Note that this must be done BEFORE calling .start() await server.pubsub.subscribe("my-pubsub-component", "my-topic", async (data: Record) => { From 5b2a8387a561996f2c57b7b75d4d5648e8cd9d96 Mon Sep 17 00:00:00 2001 From: MregXN Date: Fri, 1 Dec 2023 11:35:25 +0800 Subject: [PATCH 6/6] pretty-fix Signed-off-by: MregXN --- examples/pubsub/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/pubsub/README.md b/examples/pubsub/README.md index 16dca4e1..c7668b2a 100644 --- a/examples/pubsub/README.md +++ b/examples/pubsub/README.md @@ -42,7 +42,11 @@ By default, the example uses HTTP. To use gRPC instead: }, }); - const client = new DaprClient({daprHost, daprPort:process.env.DAPR_GRPC_PORT, communicationProtocol:CommunicationProtocolEnum.GRPC}); + const client = new DaprClient({ + daprHost, + daprPort: process.env.DAPR_GRPC_PORT, + communicationProtocol: CommunicationProtocolEnum.GRPC, + }); ``` - To run: