Skip to content

Jetstream / MessageConsumer not working in Kubernetes environment #6772

@fritzfs

Description

@fritzfs

Observed behavior

We're using a simplified API with MessageConsumer, following the example on GitHub. However, the consumer app is not working correctly when deployed in the Kubernetes. The app connects to the NATS and reads the stream and consumer information. The message consumer handler is not called even though LastDeliveredMessage-ConsumeSequence keeps increasing, but StreamSequence stays the same. I can restart the consumer application multiple times outside Kubernetes and the consumer will continue successfully. We're not sure how can this be related to Kubernetes, but that's the only difference in setup.

The consumer is durable, with the following settings:

    ConsumerConfiguration.Builder consumerConfigBuilder = ConsumerConfiguration.builder()
            .durable(NAME)
            .filterSubject(SUBJECTS)
            .ackPolicy(AckPolicy.Explicit);

Consumer report when consumer is deployed on Kubernetes:

Information for Consumer MARKET_DATA > 01591b40-1a79-4073-9a3f-3e84f017f31e created 2025-04-08T17:03:43+02:00
Configuration:
                Name: 01591b40-1a79-4073-9a3f-3e84f017f31e
           Pull Mode: true
      Filter Subject: echo.inbound.01591b40-1a79-4073-9a3f-3e84f017f31e
      Deliver Policy: All
          Ack Policy: Explicit
            Ack Wait: 30.00s
       Replay Policy: Instant
     Max Ack Pending: 1,000
   Max Waiting Pulls: 512
Cluster Information:
                Name: nats-exp
              Leader: nats-exp-1
State:
  Last Delivered Message: Consumer sequence: 4,000 Stream sequence: 1,000 Last delivery: 14.26s ago
  Acknowledgment Floor: Consumer sequence: 0 Stream sequence: 0
  Outstanding Acks: 1,000 out of maximum 1,000
  Redelivered Messages: 1,000
  Unprocessed Messages: 2,648
  Waiting Pulls: 6 of maximum 512

Consumer report after consumer has been stopped on Kubernetes and started outside:

Information for Consumer MARKET_DATA > 01591b40-1a79-4073-9a3f-3e84f017f31e created 2025-04-08T17:07:22+02:00
Configuration:
                Name: 01591b40-1a79-4073-9a3f-3e84f017f31e
           Pull Mode: true
      Filter Subject: echo.inbound.01591b40-1a79-4073-9a3f-3e84f017f31e
      Deliver Policy: All
          Ack Policy: Explicit
            Ack Wait: 30.00s
       Replay Policy: Instant
     Max Ack Pending: 1,000
   Max Waiting Pulls: 512
Cluster Information:
                Name: nats-exp
              Leader: nats-exp-1
State:
  Last Delivered Message: Consumer sequence: 4,104 Stream sequence: 4,104 Last delivery: 5.38s ago
  Acknowledgment Floor: Consumer sequence: 4,104 Stream sequence: 4,104 Last Ack: 3.55s ago
  Outstanding Acks: 0 out of maximum 1,000
  Redelivered Messages: 0
  Unprocessed Messages: 0
  Waiting Pulls: 0 of maximum 512

Expected behavior

MessageConsumer handler should receive messages as it does outside the Kubernetes env.

Server and client version

nats-server 2.10.26
nats.java 2.20.1

Host environment

No response

Steps to reproduce

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    defectSuspected defect such as a bug or regressionstaleThis issue has had no activity in a while

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions