davsclaus opened a new pull request, #30593:
URL: https://github.com/apache/camel/pull/30593

   JIRA: [CAMEL-27379](https://issues.apache.org/jira/browse/CAMEL-27379)
   
   ## What was missing
   
   A new share group starts at the latest records. `share.auto.offset.reset` is 
a **group configuration** on the broker
   (`GroupConfig.SHARE_AUTO_OFFSET_RESET_CONFIG` in kafka-group-coordinator 
4.4.0). It is not a consumer property, so it
   had to be set with `kafka-configs.sh` or the Admin client before a route 
could read a topic from the beginning. The
   module's own `KafkaShareConsumerIT` does exactly that in `@BeforeAll`.
   
   ## The change
   
   New consumer option `shareAutoOffsetReset` (String, no default):
   
   - Values: `earliest`, `latest`, or `by_duration:<ISO-8601 duration>`. I 
checked them against `GroupConfig` of Kafka
     4.4.0, the version Camel uses (`SHARE_AUTO_OFFSET_RESET_DOC`). The value 
is checked before any client is created
     (`by_duration` must parse as a duration that is not negative), so a typo 
fails at once instead of at the broker.
   - When the consumer starts, after the existing checks and before the share 
consumers subscribe, it calls
     `Admin.incrementalAlterConfigs` with a `SET` of `share.auto.offset.reset` 
on `ConfigResource.Type.GROUP` for the
     `groupId`, with `consumerRequestTimeoutMs` as the timeout. The admin 
client is closed afterwards.
   - The admin client gets the share consumer's properties without the ones 
only a consumer knows (consumer config names
     that are not admin config names, such as the deserializers, `group.id` and 
`max.poll.records`). The brokers, security
     settings and custom additional properties are passed through.
   - The admin client comes from 
`KafkaShareClientFactory.getAdmin(Properties)`, a new **default** method
     (`Admin.create`), so existing custom factories still compile and tests can 
plug in a fake.
   - If the call fails (no `ALTER_CONFIGS` on the group, brokers unreachable, 
timeout), the consumer fails to start with
     `Cannot set share.auto.offset.reset=earliest on the share group my-group 
(the shareAutoOffsetReset option): <cause>.
     The principal of the consumer needs the ALTER_CONFIGS permission on the 
group.` I chose a loud failure because the
     user asked for the setting explicitly. Starting silently at `latest` would 
skip records.
   - When the option is not set, nothing changes: no admin client is created.
   
   Docs: `kafka-share-component.adoc` has a new section "Where a new share 
group starts". It covers the option, the values,
   that the setting only matters when the group first consumes a 
share-partition, that it applies to the whole group,
   the `ALTER_CONFIGS` permission (with a `kafka-acls.sh` example), and the 
`kafka-configs.sh` fallback. The catalog copy,
   component JSON, configurers and endpoint/component DSL are regenerated.
   
   ## Tests
   
   - New `KafkaShareAutoOffsetResetTest` (Mockito `Admin`, `mockito-core` added 
as a test dependency), 5 tests:
     - the GROUP resource, the `SET` of `share.auto.offset.reset=earliest`, the 
timeout, and that the admin is closed;
     - the admin properties keep the brokers, security, JAAS and custom 
properties, and drop the consumer-only ones;
     - `by_duration:PT1H`;
     - no option means no admin client;
     - a `GroupAuthorizationException` fails the route start with the message 
above, and no share consumer is created;
     - invalid values (`newest`, `by_duration:1h`, `by_duration:-PT1H`) fail 
before an admin client is created.
   - New `KafkaShareAutoOffsetResetIT` (test-infra Kafka 4.4.0 container): 
produces 3 records, then starts a route with a
     new group and `shareAutoOffsetReset=earliest`. It checks that all 3 
records are received and that `describeConfigs`
     shows `earliest`. **Passes** (about 8 s). Without the option the same test 
fails with `Expected: <3> but was: <0>`.
   - `mvn -o test` in camel-kafka-share: 1039 tests, 0 failures (including the 
DST test).
   
   _Claude Code on behalf of davsclaus_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to