-
Notifications
You must be signed in to change notification settings - Fork 629
Description
After writing this problem, I review the code in detail. The main problem is that NestedConfigurations is null while the application is initialized. (Example: ConsumerProperties And ProducerProperties) . When the BindingServiceProperties configuration is initialized, the ConsumerProperties and ProducerProperties configurations become null.
Due to this problem, the autostartup feature of the ConsumerProperties does not work.
I can consume and produce data from kafka with Spring Cloud Function. I configure the service to not automatically read data on startup by setting auto-startup=false(application.yml). While the project is starting(Smart-Lifecycle), I want the data to be consumed after the initialization process. My project is running successfully as I described.
However, when I build a native docker image with spring native, various problems arise. I can consume and produce data in spring native docker image. However, the auto-startup false feature doesn't work. The auto-startup feature I wrote in application.yml does not work and does not throw an error. Although I do not start the relevant consumer in my code(programmaticaly), the service starts to consume data as soon as it startup.
Additional Info : If I run it without a native image, there is no problem. This problem occurs when I build native docker image and run it. In addition, when I programmatically give false to auto-startup, this feature starts working. But I want to make it executable from application.yml. What should I do?
My Project Github Link: graalvm-spring-cloud-auto-startup
Spring Boot Starter Parent Version : 3.1.2
Spring Cloud Version : 2022.0.4
GraalVM Version: 17
My Code:
@Service("listenPersonData")
public class PersonListener implements Consumer<Person> {
@Override
public void accept(Person person) {
System.out.println("Person Received : " + person.getName());
}
}
@Service("personInitializer")
public class PersonInitializer implements SmartLifecycle {
@Autowired
private BindingsLifecycleController lifecycleController;
@Override
public void start() {
// If I stop the consumer like this programmatically, the feature works. However, I want to do it from application.yml.
// lifecycleController.changeState("listenPersonData-in-0", STOPPED);
// Some Database Operation
// lifecycleController.changeState("listenPersonData-in-0", STARTED);
}
}
Application.yml
spring:
cloud:
stream:
kafka:
binder:
replication-factor: 2
bindings:
listenPersonData-in-0:
destination: deneme-person-topic-2
binder: kafka1
group: omer-celik-2243
consumer:
auto-startup: false
function:
definition: listenPersonData;
binders:
kafka1:
type: kafka
environment:
spring:
cloud:
stream:
kafka:
binder:
brokers: localhost:19092
autoCreateTopics: true
reflect-config.json
[
{
"condition": {
"typeReachable": "org.springframework.kafka.security.jaas.KafkaJaasLoginModuleInitializer"
},
"name": "sun.security.provider.ConfigFile",
"allPublicConstructors": true
},
{
"name": "org.springframework.cloud.stream.binding.InputBindingLifecycle",
"allDeclaredFields": true
},
{
"name": "org.springframework.cloud.stream.binding.OutputBindingLifecycle",
"allDeclaredFields": true
}
]
Docker Image: spring-boot:build-image -P native
If I open the comment line code, the consumer is stopped. However, I want to stop it using application.yml. But my auto startup : false config in application.yml is not working.