I can consume and produce data from kafka with Spring Cloud Function. Also, for consumers, I do not allow data to be consumed automatically when the service is starting(auto-startup=false). While the project is starting(Smart-Lifecycle), I want the data to be consumed after the initialization process of the data in the database is finished. My project works exactly as I described.
However, when I build a native docker image with spring native, various problems arise. Again, I can consume and produce data. 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 stands up.
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() {
// 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.