Set ConsumerConfig.Name so NATS accepts consumer creation

NATS.Net 2.5 posts CreateOrUpdateConsumerAsync to
$JS.API.CONSUMER.CREATE.<stream>.<name>, pulling <name> from ConsumerConfig.Name.
The server compares that against DurableName in the payload and rejects the
request with "consumer name in subject does not match durable name in request"
when Name is missing. Set both properties to the same value so durable
consumer creation succeeds and messages actually reach the dispatcher.
This commit is contained in:
EugeneTes
2026-09-02 11:59:48 +00:00
parent b2c2811933
commit 1cd198cebd

View File

@@ -117,6 +117,11 @@ public sealed class NatsTriggerHostedService(
var consumer = await js.CreateOrUpdateConsumerAsync(stim.Stream, new ConsumerConfig
{
// NATS.Net 2.5 sends the create request to $JS.API.CONSUMER.CREATE.<stream>.<name>,
// pulling <name> from Name. Server compares it against DurableName in the payload
// and returns "consumer name in subject does not match durable name in request" if
// Name is missing. Set both to the same value.
Name = consumerName,
DurableName = consumerName,
AckPolicy = ConsumerConfigAckPolicy.Explicit,
DeliverPolicy = ConsumerConfigDeliverPolicy.New, // only applied on first-time creation