[
https://issues.apache.org/jira/browse/CAMEL-23023?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18065177#comment-18065177
]
Claus Ibsen commented on CAMEL-23023:
-------------------------------------
Added some hacky thread sleep in camel-spring and I can see this situation
{code:java}
2026-03-11T20:29:05.023+01:00 INFO 25307 --- [onsumer[cheese]]
o.a.k.c.c.internals.SubscriptionState : [Consumer
clientId=consumer-267ec591-5979-46d5-8ab3-32f93a54b2e4-1,
groupId=267ec591-5979-46d5-8ab3-32f93a54b2e4] Resetting offset for partition
cheese-0 to position FetchPosition{offset=14, offsetEpoch=Optional.empty,
currentLeader=LeaderAndEpoch{leader=Optional[localhost:9092 (id: 1 rack: null
isFenced: false)], epoch=0}}.
CamelContext state: Starting
2026-03-11T20:29:14.557+01:00 INFO 25307 --- [onsumer[cheese]] route1
: RECEIVED: ccc
CamelContext state: Starting
2026-03-11T20:29:31.307+01:00 INFO 25307 --- [onsumer[cheese]] route1
: RECEIVED: ccd
2026-03-11T20:29:34.857+01:00 INFO 25307 --- [ main]
o.e.p.application.CamelApplication : Started CamelApplication in 30.52
seconds (process running for 30.621)
CamelContext state: Started
2026-03-11T20:29:44.101+01:00 INFO 25307 --- [onsumer[cheese]] route1
: RECEIVED: cce {code}
> CamelContext Startup behavior interfers with Spring Lifecycle
> -------------------------------------------------------------
>
> Key: CAMEL-23023
> URL: https://issues.apache.org/jira/browse/CAMEL-23023
> Project: Camel
> Issue Type: Bug
> Components: camel-spring
> Affects Versions: 4.8.7
> Reporter: Christoph Ewerlin
> Assignee: Claus Ibsen
> Priority: Minor
> Fix For: 4.19.0
>
>
> SpringCamelContext registers to ApplicationEvent "ContextRefreshed" and then
> starts the CamelContext, see SpringCamelContext::onApplicationEvent.
> There is also a comment saying that
> {code:java}
> // nominally we would prefer to use Lifecycle interface that
> // would invoke start() method, but in order to do that
> // SpringCamelContext needs to implement SmartLifecycle
> // (look at DefaultLifecycleProcessor::startBeans), but it
> // cannot implement it as it already implements
> // RuntimeConfiguration, and both SmartLifecycle and
> // RuntimeConfiguration declare isAutoStartup method but
> // with boolean and Boolean return types, and covariant
> // methods with primitive types are not allowed by the JLS
> // so we need to listen for ContextRefreshedEvent and start
> // on its reception {code}
> The problem with that is, that for instance KafkaConsumers are started as
> part of the lifecycle before the CamelContext is starting, which in our case
> results in messages being consumed and delegated to a camel route, before the
> context is started -> exception, message loss.
> The ideal behavior would be that the camel context is started BEFORE the
> kafka listeners start to fire.
> In case it is difficult to fix, maybe it will be an option to update it
> together with the spring boot 4 integration ticket?
--
This message was sent by Atlassian Jira
(v8.20.10#820010)