Skip to content

Commit

Permalink
Modify example pubsub (#558)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
MregXN authored Dec 5, 2023
1 parent 46c83d9 commit d2cc38e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 6 additions & 1 deletion examples/pubsub/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions examples/pubsub/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ async function start() {
});

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

// 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<string, any>) => {
// The library parses JSON when possible.
console.log(`[Dapr-JS][Example] Received on subscription: ${JSON.stringify(data)}`);
Expand Down Expand Up @@ -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");
Expand All @@ -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)}`);
}

Expand Down

0 comments on commit d2cc38e

Please sign in to comment.