You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "oscerd (via GitHub)" <gi...@apache.org> on 2026/05/08 11:32:52 UTC
[PR] CAMEL-23419: camel-nats - Fix JetStream consumer pull subscription mode [camel]
oscerd opened a new pull request, #23084:
URL: https://github.com/apache/camel/pull/23084
## Summary
Fixes [CAMEL-23419](https://issues.apache.org/jira/browse/CAMEL-23419) — the camel-nats JetStream consumer did not actually consume any messages in pull subscription mode (which is the default). The only workaround was to explicitly opt into push mode via `pullSubscription=false`.
## Root cause
In `NatsConsumer.setupJetStreamConsumer`, the pull branch used the dispatcher-based subscribe overload:
```java
this.connection.jetStream().subscribe(topic, dispatcher, messageHandler, pullOptions);
```
In the NATS Java client this overload creates a managed pull subscription, **but the caller still must explicitly request batches via `sub.pull(...)` / `sub.fetch(...)`**. Camel never did. As a result the consumer started up cleanly and the JetStream consumer appeared on the server, but messages stayed in `Unprocessed` and were never delivered to the route.
## Fix
Switch the pull path to the synchronous API:
```java
this.connection.jetStream().subscribe(topic, pullOptions);
```
…and drive it from a fetch loop on the existing consumer worker thread. The loop respects the consumer's `isRunAllowed()` so shutdown is clean. Each fetched message goes through the existing `CamelNatsMessageHandler`, so ack/nack/redelivery semantics are unchanged. The push path is unchanged.
Two new consumer options expose the loop tuning:
| Option | Default | Description |
|--------|---------|-------------|
| `pullBatchSize` | `10` | Max messages per fetch request |
| `pullFetchTimeout` | `1000` ms | Max time to wait per fetch request |
Also unsubscribe the JetStream subscription on `doStop()` so pull subscriptions are cleaned up properly (push mode previously relied on the dispatcher unsubscribe).
## Tests
- New integration test `NatsJetstreamConsumerPullIT` covers the default pull path against a real NATS JetStream broker.
- Existing JetStream ITs (`NatsJetstreamConsumerIT`, `NatsJetstreamConsumerAckPolicyNoneIT`, `NatsJetstreamConsumerMaxDeliverIT`, `NatsJetstreamConsumerRedeliveryIT`) all still pass — the push path is unaffected.
```
[INFO] Running ...NatsJetstreamConsumerAckPolicyNoneIT — Tests run: 1, Failures: 0
[INFO] Running ...NatsJetstreamConsumerIT — Tests run: 1, Failures: 0
[INFO] Running ...NatsJetstreamConsumerMaxDeliverIT — Tests run: 1, Failures: 0
[INFO] Running ...NatsJetstreamConsumerPullIT — Tests run: 1, Failures: 0
[INFO] Running ...NatsJetstreamConsumerRedeliveryIT — Tests run: 1, Failures: 0
```
## Docs
Added a note to `camel-4x-upgrade-guide-4_21.adoc` describing the fix and the two new options.
## Test plan
- [x] `mvn -DskipTests install` for `camel-nats` (with regen of catalog + DSL factories)
- [x] `mvn test` (unit tests)
- [x] `mvn verify -Dit.test='NatsJetstream*IT'` (all JetStream ITs, including the new pull test)
- [ ] CI green
---
_Claude Code on behalf of Andrea Cosentino_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-23419: camel-nats - Fix JetStream consumer pull subscription mode [camel]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #23084:
URL: https://github.com/apache/camel/pull/23084#issuecomment-4406080147
:star2: Thank you for your contribution to the Apache Camel project! :star2:
:robot: CI automation will test this PR automatically.
:camel: Apache Camel Committers, please review the following items:
* First-time contributors **require MANUAL approval** for the GitHub Actions to run
* You can use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot although they are normally detected and executed by CI.
* You can label PRs using `skip-tests` and `test-dependents` to fine-tune the checks executed by this PR.
* Build and test logs are available in the summary page. **Only** [Apache Camel committers](https://camel.apache.org/community/team/#committers) have access to the summary.
:warning: Be careful when sharing logs. Review their contents before sharing them publicly.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-23419: camel-nats - Fix JetStream consumer pull subscription mode [camel]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #23084:
URL: https://github.com/apache/camel/pull/23084#issuecomment-4406193098
<!-- ci-tested-modules -->
:test_tube: **CI tested the following changed modules:**
- `catalog/camel-catalog`
- `components/camel-nats`
- `docs`
- `dsl/camel-componentdsl`
- `dsl/camel-endpointdsl`
<details><summary>All tested modules (11 modules)</summary>
- Camel :: Catalog :: Camel Catalog
- Camel :: Component DSL
- Camel :: Endpoint DSL
- Camel :: JBang :: MCP
- Camel :: JBang :: Plugin :: Route Parser
- Camel :: JBang :: Plugin :: TUI
- Camel :: JBang :: Plugin :: Validate
- Camel :: Launcher :: Container
- Camel :: Nats
- Camel :: YAML DSL :: Validator
- Camel :: YAML DSL :: Validator Maven Plugin
</details>
---
:gear: [View full build and test results](https://github.com/apache/camel/actions/runs/25553271519)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-23419: camel-nats - Fix JetStream consumer pull subscription mode [camel]
Posted by "oscerd (via GitHub)" <gi...@apache.org>.
oscerd merged PR #23084:
URL: https://github.com/apache/camel/pull/23084
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org