nats-io / nats.net

Full Async C# / .NET client for NATS
https://nats-io.github.io/nats.net
Apache License 2.0
262 stars 53 forks source link

JetStream Backoff #422

Closed alberk8 closed 8 months ago

alberk8 commented 8 months ago

Observed behavior

With code below it looks like the backoff is not in effect. Also there is no reference anywhere in the source.

Expected behavior

Backoff Setting works

Server and client version

Server: v2.10.11 Client: NATS.Client.JetStream v2.1.2

Host environment

Official NATS docker (latest) with JetStream enabled.

Steps to reproduce

var consumer = await jsContext.CreateOrUpdateConsumerAsync("EVENTS", new ConsumerConfig(consumerName)
{
    DeliverPolicy = ConsumerConfigDeliverPolicy.All,
    FilterSubject = "data.>",
    AckPolicy = ackPolicy,
    AckWait = ackWait,

    MaxDeliver = 5,
    Backoff = new List<long>() { (long) TimeSpan.FromSeconds(1).TotalSeconds, (long)TimeSpan.FromSeconds(2).TotalSeconds }
});

 await foreach (NatsJSMsg<Person> msg in consumer.ConsumeAsync<Person>())
 {
     Console.WriteLine($"Subject: {msg.Subject} Size: {msg.Size}");
     var md = msg.Metadata;
     if (md.HasValue)
     {
        Console.WriteLine($"Num Delivered: {md.Value.NumDelivered} TimeStamp: {md.Value.Timestamp.ToLocalTime()}");
        Console.WriteLine($"Consumer Seq: {md.Value.Sequence.Consumer} Stream Seq: {md.Value.Sequence.Stream}");
     }
     await msg.NakAsync();
 }
mtmk commented 8 months ago

it might be nanoseconds, could you try that? We changed everything to be TimeSpan but missed this one I think 🤔

alberk8 commented 8 months ago

I have changed to MicroSeconds and there is no difference. The Re-Delivery went through in quick succession.

Looking at the source code, it does not seems that Backoff is implemented.

mtmk commented 8 months ago

I have changed to MicroSeconds and there is no difference. The Re-Delivery went through in quick succession.

it's should be nano .. another x1000

Looking at the source code, it does not seems that Backoff is implemented.

I think this is just passed to the server, I don't think there is anything to implement on client side, is there?

alberk8 commented 8 months ago

Thanks. I really missed it. Nanoseconds did the trick. It is working as expected.