dapr / docs

Dapr user documentation, used to build docs.dapr.io
https://docs.dapr.io
Creative Commons Attribution 4.0 International
992 stars 724 forks source link

I am trying to configure resilience policy for pubsub component using Javascript sdk. But no document or demo code available. #4270

Closed shaisha05 closed 2 weeks ago

shaisha05 commented 1 month ago

I am working on a poc. For which, I started testing DAPR features with the quickstart code provided at https://github.com/dapr/quickstarts/tree/master/pub_sub/javascript/sdk. This pubsub example does not include resiliency. I added below resiliency.yaml to resources folder.

Using RabbitMQ as message broker. DAPR is setup locally with docker.

apiVersion: dapr.io/v1alpha1 kind: Resiliency metadata: name: myresiliency scopes:

spec: policies: retries: pubsubRetry: policy: constant duration: 5s maxRetries: 5

targets:
components: orderpubsub: retry: pubsubRetry

As per logs resilienycy policy is applied. But if i throw some error at subscriber as below.

server.pubsub.subscribe(pubSubName, pubSubTopic, (data, headers) =>{
if(data.orderId == 1){ console.log("Subscriber error: " + JSON.stringify(data)); throw new Error("Faulty msg"); }else{ console.log("Subscriber received: " + JSON.stringify(data)); } });

For orderId = 1, It fails and throws error. But retry is not working.

Also, I want to know how can I control retries with below.

Retry works with the

But It retries for infinitely without any interval. Is there any parameter to control max retries and duration?

yaron2 commented 1 month ago

Can you provide more information on what you're trying to achieve, your configurations and the expected result?

shaisha05 commented 1 month ago

I updated my original comment. please have a look.

shaisha05 commented 1 month ago

Hi @yaron2, is any further info required?

hhunter-ms commented 1 month ago

cc @greenie-msft

it may be good to add a resiliency example to the dapr/quickstarts repo for pub/sub.

greenie-msft commented 1 month ago

@shaisha05 Im not sure I completely understand the issue but one thing I noticed is that you haven't specified the direction for which the policy should be applied. The pubsub API supports two directions - outbound and inbound. If you want to apply the policy for when an exception occurs when delivering a message, you need to add the inbound direction.

See here for more details on component directions: https://docs.dapr.io/operations/resiliency/targets/#components

hhunter-ms commented 1 month ago

@shaisha05 just checking in - did @greenie-msft's suggestion help?

shaisha05 commented 1 month ago

@shaisha05 just checking in - did @greenie-msft's suggestion help?

No, I tried with inbound and also outbound. But did not work.

apiVersion: dapr.io/v1alpha1 kind: Resiliency metadata: name: myresiliency scopes:

spec: policies: retries: pubsubRetry: policy: constant duration: 5s maxRetries: 5

targets:
components: orderpubsub:

outbound:

    #   retry: pubsubRetry
    inbound:
      retry: pubsubRetry
greenie-msft commented 1 month ago

@shaisha05, I don't see anything immediately wrong with your Resiliency CRD resource. @yaron2, do you?

That said, I don't think this is a docs issue. The Resiliency feature is language agnostic so the examples referenced here should be enough: https://docs.dapr.io/operations/resiliency/resiliency-overview/

If you are having trouble getting this policy to work, can you please ask in the Dapr discord for guidance? https://discord.com/invite/ptHhX6jc34

msfussell commented 3 weeks ago

@shaisha05 - Are you still stuck on this? Any update you could provide?

shaisha05 commented 2 weeks ago

@shaisha05 - Are you still stuck on this? Any update you could provide?

Yes, could not figure it out. I am not actively working on this for now. Hence, I haven't asked this on discord yet.

hhunter-ms commented 2 weeks ago

Since this is not a docs issue, I'm going to close this issue for now. Thanks!