Skip to content

Commit 8babe75

Browse files
feat(pubsub): add wildcard support (+, #) (#529)
* Upgrade gRPC JS lib and HTTP terminator. Co-authored-by: Xavier Geerinck <[email protected]> Signed-off-by: Shubham Sharma <[email protected]> * Update route generation to support wildcards, refactor common code between protocols. Co-authored-by: Xavier Geerinck <[email protected]> Signed-off-by: Shubham Sharma <[email protected]> * Add gRPC server wildcard handling and wildcard tests. Co-authored-by: Xavier Geerinck <[email protected]> Signed-off-by: Shubham Sharma <[email protected]> * WIP: Refactor PubSub subscription logic into a new module Signed-off-by: Shubham Sharma <[email protected]> * WIP: Refactor PubSub subscription logic into a new module Signed-off-by: Shubham Sharma <[email protected]> * Refactor PubSub subscription logic into a new module Signed-off-by: Shubham Sharma <[email protected]> * WIP: Make HTTP server implementation use the PubSub module Signed-off-by: Shubham Sharma <[email protected]> * WIP: Make HTTP tests work Signed-off-by: Shubham Sharma <[email protected]> * Tests work now Signed-off-by: Shubham Sharma <[email protected]> * Prettify Signed-off-by: Shubham Sharma <[email protected]> * add doc block for wildcards Signed-off-by: Xavier Geerinck <[email protected]> * add test for checking topic registration Signed-off-by: Xavier Geerinck <[email protected]> * refactor protocols and add test Signed-off-by: Xavier Geerinck <[email protected]> * fix warnings Signed-off-by: Xavier Geerinck <[email protected]> * fix unit test runner: Signed-off-by: Xavier Geerinck <[email protected]> * add more tests Signed-off-by: Xavier Geerinck <[email protected]> * cleanup Signed-off-by: Xavier Geerinck <[email protected]> * small extra doc Signed-off-by: Xavier Geerinck <[email protected]> --------- Signed-off-by: Shubham Sharma <[email protected]> Signed-off-by: Xavier Geerinck <[email protected]> Co-authored-by: Xavier Geerinck <[email protected]>
1 parent e3987b7 commit 8babe75

File tree

23 files changed

+4306
-7650
lines changed

23 files changed

+4306
-7650
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,5 @@ src/version.ts
152152
# JetBrains
153153
/.idea
154154

155+
# PNPM
156+
pnpm-lock.yaml

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,45 @@ async function start() {
408408
}
409409
```
410410

411+
#### Susbcribe with Wildcards
412+
413+
The popular wildcards `*` and `+` are supported (make sure to validate if the [pubsub component supports it](https://docs.dapr.io/reference/components-reference/supported-pubsub/)) and can be subscribed to as follows:
414+
415+
```typescript
416+
import { DaprServer } from "@dapr/dapr";
417+
418+
const daprHost = "127.0.0.1"; // Dapr Sidecar Host
419+
const daprPort = "3500"; // Dapr Sidecar Port of this Example Server
420+
const serverHost = "127.0.0.1"; // App Host of this Example Server
421+
const serverPort = "50051"; // App Port of this Example Server "
422+
423+
async function start() {
424+
const server = new DaprServer({
425+
serverHost,
426+
serverPort,
427+
clientOptions: {
428+
daprHost,
429+
daprPort,
430+
},
431+
});
432+
433+
const pubSubName = "my-pubsub-name";
434+
435+
// * Wildcard
436+
await server.pubsub.subscribe(pubSubName, "/events/*", async (data: any, headers: object) =>
437+
console.log(`Received Data: ${JSON.stringify(data)}`),
438+
);
439+
440+
// + Wildcard
441+
await server.pubsub.subscribe(pubSubName, "/events/+/temperature", async (data: any, headers: object) =>
442+
console.log(`Received Data: ${JSON.stringify(data)}`),
443+
);
444+
445+
// Start the server
446+
await server.start();
447+
}
448+
```
449+
411450
#### Bulk Subscribe to messages
412451

413452
Bulk Subscription is supported and is available through following API:

0 commit comments

Comments
 (0)