From d2cc38ee9fa9567934599520ad21bee016bca46e Mon Sep 17 00:00:00 2001 From: MregXN <46479059+MregXN@users.noreply.github.com> Date: Tue, 5 Dec 2023 15:59:34 +0800 Subject: [PATCH] Modify example pubsub (#558) * there can be only one topic registered Signed-off-by: MregXN * modify grpc client Signed-off-by: MregXN * typo Signed-off-by: MregXN * modify README Signed-off-by: MregXN * fix typo Signed-off-by: MregXN * pretty-fix Signed-off-by: MregXN --------- Signed-off-by: MregXN --- examples/pubsub/README.md | 7 ++++++- examples/pubsub/src/index.ts | 10 +++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/examples/pubsub/README.md b/examples/pubsub/README.md index 71f168f4..c7668b2a 100644 --- a/examples/pubsub/README.md +++ b/examples/pubsub/README.md @@ -41,7 +41,12 @@ 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: diff --git a/examples/pubsub/src/index.ts b/examples/pubsub/src/index.ts index 83ffd5fa..fa8cf998 100644 --- a/examples/pubsub/src/index.ts +++ b/examples/pubsub/src/index.ts @@ -38,7 +38,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 +46,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 +85,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 +111,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)}`); }