You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: daprdocs/content/en/js-sdk-docs/js-client/_index.md
+115-2Lines changed: 115 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -277,7 +277,17 @@ start().catch((e) => {
277
277
});
278
278
```
279
279
280
-
##### Subscribe to messages
280
+
#### Subscribe to messages
281
+
282
+
Subscribing to messages can be done in several ways to offer flexibility of receiving messages on your topics:
283
+
284
+
* Direct subscription through the `subscribe` method
285
+
* Direct susbcription with options through the `subscribeWithOptions` method
286
+
* Subscription afterwards through the `susbcribeOnEvent` method
287
+
288
+
> Dapr requires subscriptions to be set up on startup, but in the JS SDK we allow event handlers to be added afterwards as well, providing you the flexibility of programming.
> E.g., you are writing an application that needs to handle messages depending on their "type" with Dapr, you can send them to different routes `handlerType1` and `handlerType2` with the default route being `handlerDefault`
333
+
334
+
```javascript
335
+
import { DaprServer } from"@dapr/dapr";
336
+
337
+
constdaprHost="127.0.0.1"; // Dapr Sidecar Host
338
+
constdaprPort="3500"; // Dapr Sidecar Port of this Example Server
339
+
constserverHost="127.0.0.1"; // App Host of this Example Server
340
+
constserverPort="50051"; // App Port of this Example Server "
Dapr supports [dead letter topic](https://docs.dapr.io/developing-applications/building-blocks/pubsub/pubsub-deadletter/). This means that when a message fails to be processed, it gets sent to a dead letter queue. E.g., when a message fails to be handled on `/my-queue` it will be sent to `/my-queue-failed`.
377
+
E.g., when a message fails to be handled on `/my-queue` it will be sent to `/my-queue-failed`.
378
+
379
+
You can use the following options with `subscribeWithOptions` method:
380
+
*`deadletterTopic`: Specify a deadletter topic name (note: if none is provided we create one named `deadletter`)
381
+
*`deadletterCallback`: The method to trigger as handler for our deadletter
382
+
383
+
Implementing Deadletter support in the JS SDK can be done by either
384
+
* Passing the `deadletterCallback` as an option
385
+
* By subscribing to route manually with `subscribeToRoute`
386
+
387
+
An example is provided below
388
+
389
+
```javascript
390
+
import { DaprServer } from"@dapr/dapr";
391
+
392
+
constdaprHost="127.0.0.1"; // Dapr Sidecar Host
393
+
constdaprPort="3500"; // Dapr Sidecar Port of this Example Server
394
+
constserverHost="127.0.0.1"; // App Host of this Example Server
395
+
constserverPort="50051"; // App Port of this Example Server "
0 commit comments