Skip to content

Commit

Permalink
feat(pubsub): add wildcard support (+, #) (#529)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
shubham1172 and XavierGeerinck authored Oct 13, 2023
1 parent e3987b7 commit 8babe75
Show file tree
Hide file tree
Showing 23 changed files with 4,306 additions and 7,650 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,5 @@ src/version.ts
# JetBrains
/.idea

# PNPM
pnpm-lock.yaml
39 changes: 39 additions & 0 deletions daprdocs/content/en/js-sdk-docs/js-server/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,45 @@ async function start() {
}
```

#### Susbcribe with Wildcards

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:

```typescript
import { DaprServer } from "@dapr/dapr";

const daprHost = "127.0.0.1"; // Dapr Sidecar Host
const daprPort = "3500"; // Dapr Sidecar Port of this Example Server
const serverHost = "127.0.0.1"; // App Host of this Example Server
const serverPort = "50051"; // App Port of this Example Server "

async function start() {
const server = new DaprServer({
serverHost,
serverPort,
clientOptions: {
daprHost,
daprPort,
},
});

const pubSubName = "my-pubsub-name";

// * Wildcard
await server.pubsub.subscribe(pubSubName, "/events/*", async (data: any, headers: object) =>
console.log(`Received Data: ${JSON.stringify(data)}`),
);

// + Wildcard
await server.pubsub.subscribe(pubSubName, "/events/+/temperature", async (data: any, headers: object) =>
console.log(`Received Data: ${JSON.stringify(data)}`),
);

// Start the server
await server.start();
}
```

#### Bulk Subscribe to messages

Bulk Subscription is supported and is available through following API:
Expand Down
Loading

0 comments on commit 8babe75

Please sign in to comment.