Skip to content

Commit d2cc38e

Browse files
authored
Modify example pubsub (#558)
* there can be only one topic registered Signed-off-by: MregXN <[email protected]> * modify grpc client Signed-off-by: MregXN <[email protected]> * typo Signed-off-by: MregXN <[email protected]> * modify README Signed-off-by: MregXN <[email protected]> * fix typo Signed-off-by: MregXN <[email protected]> * pretty-fix Signed-off-by: MregXN <[email protected]> --------- Signed-off-by: MregXN <[email protected]>
1 parent 46c83d9 commit d2cc38e

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

examples/pubsub/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ By default, the example uses HTTP. To use gRPC instead:
4141
daprPort: process.env.DAPR_GRPC_PORT,
4242
},
4343
});
44-
const client = new DaprClient(daprHost, process.env.DAPR_GRPC_PORT, CommunicationProtocolEnum.GRPC);
44+
45+
const client = new DaprClient({
46+
daprHost,
47+
daprPort: process.env.DAPR_GRPC_PORT,
48+
communicationProtocol: CommunicationProtocolEnum.GRPC,
49+
});
4550
```
4651

4752
- To run:

examples/pubsub/src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ async function start() {
3838
});
3939

4040
// Publish multiple messages to a topic with default config.
41-
await server.pubsub.subscribeBulk("my-pubsub-component", "my-topic", async (data: Record<string, any>) => {
41+
await server.pubsub.subscribeBulk("my-pubsub-component", "my-topic-bulk", async (data: Record<string, any>) => {
4242
// The library parses JSON when possible.
4343
console.log(`[Dapr-JS][Example] Received on subscription: ${JSON.stringify(data)}`);
4444
});
4545

4646
// Publish multiple messages to a topic with specific maxMessagesCount and maxAwaitDurationMs.
4747
await server.pubsub.subscribeBulk(
4848
"my-pubsub-component",
49-
"my-topic",
49+
"my-topic-bulk-with-config",
5050
async (data: Record<string, any>) => {
5151
// The library parses JSON when possible.
5252
console.log(`[Dapr-JS][Example] Received on subscription: ${JSON.stringify(data)}`);
@@ -85,12 +85,12 @@ async function start() {
8585

8686
console.log("[Dapr-JS][Example] Bulk publishing multiple plain messages");
8787
const messages = ["message 1", "message 2", "message 3"];
88-
response = await client.pubsub.publishBulk("my-pubsub-component", "my-topic", messages);
88+
response = await client.pubsub.publishBulk("my-pubsub-component", "my-topic-bulk", messages);
8989
console.log(`[Dapr-JS][Example] Bulk publish response: ${JSON.stringify(response)}`);
9090

9191
console.log("[Dapr-JS][Example] Bulk publishing multiple JSON messages");
9292
const jsonMessages = [{ hello: "message 1" }, { hello: "message 2" }, { hello: "message 3" }];
93-
response = await client.pubsub.publishBulk("my-pubsub-component", "my-topic", jsonMessages);
93+
response = await client.pubsub.publishBulk("my-pubsub-component", "my-topic-bulk", jsonMessages);
9494
console.log(`[Dapr-JS][Example] Bulk publish response: ${JSON.stringify(response)}`);
9595

9696
console.log("[Dapr-JS][Example] Bulk publishing with entryID and custom content type");
@@ -111,7 +111,7 @@ async function start() {
111111
event: "foo message 3",
112112
},
113113
];
114-
response = await client.pubsub.publishBulk("my-pubsub-component", "my-topic", bulkPublishMessages);
114+
response = await client.pubsub.publishBulk("my-pubsub-component", "my-topic-bulk-with-config", bulkPublishMessages);
115115
console.log(`[Dapr-JS][Example] Bulk publish response: ${JSON.stringify(response)}`);
116116
}
117117

0 commit comments

Comments
 (0)