I have multiples spring boot apps implementing spring cloud stream with kafka brokers. I'd like to know if I can stop or disable spring cloud stream or kafka broker connections to enable apps to start.
Every topic in Kafka is split into one or more partitions. Kafka partitions data for storing, transporting, and replicating it. Kafka Streams partitions data for processing it. In both cases, this partitioning enables elasticity, scalability, high performance, and fault tolerance.
Spring Cloud Stream is a framework for building highly scalable event-driven microservices connected with shared messaging systems.
Apps should start even the brokers are not available.
You could add a noop Binder in the classpath and make it a default binder or specify it for your binding. Here some code with Kotlin:
The NoOpBinder implementation class:
package com.demo
import org.slf4j.LoggerFactory
import org.springframework.cloud.stream.binder.Binder
import org.springframework.cloud.stream.binder.Binding
import org.springframework.cloud.stream.binder.ConsumerProperties
import org.springframework.cloud.stream.binder.ProducerProperties
import org.springframework.messaging.MessageChannel
class NoOpBinder : Binder<MessageChannel, ConsumerProperties, ProducerProperties> {
val logger = LoggerFactory.getLogger(javaClass)!!
override fun bindConsumer(
name: String,
group: String,
inboundBindTarget: MessageChannel,
consumerProperties: ConsumerProperties
): Binding<MessageChannel> = NoOpBinding(name).also { logger.info("bindConsumer: $it") }
override fun bindProducer(
name: String,
outboundBindTarget: MessageChannel,
producerProperties: ProducerProperties
): Binding<MessageChannel> = NoOpBinding(name).also { logger.info("bindProducer: $it") }
private class NoOpBinding(val binderName: String) : Binding<MessageChannel> {
val logger = LoggerFactory.getLogger(javaClass)!!
override fun getName() = binderName
override fun unbind() {
logger.info("unbind: $this")
}
override fun toString() = "NoOpBinding [$name]"
}
}
A configuration class:
package com.demo
import org.springframework.context.annotation.Bean
// Warn: this class is referenced in META-INF/spring.binders and used by spring cloud stream to instantiate binders.
class NoOpBinderServiceConfigurer {
@Bean
fun noOpBinder() = NoOpBinder()
}
// resources/META-INF/spring.binders
noop: com.demo.NoOpBinderServiceConfigurer
Specify the binder in your configuration file application.yml
spring:
cloud:
stream:
bindings:
my-binding:
destination: my-destination
group: my-group
binder: noop
Or specify the default binder in your configuration file application.yml
spring:
cloud:
stream:
bindings:
defaultBinder: noop
--
Reference:
You can do this by disabling the kafka binding in the spring boot application
Application class
import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration;
@SpringBootApplication(exclude = KafkaAutoConfiguration.class)
public class Application {
...
}
application.yml (If using yml)
spring:
autoconfigure:
exclude: org.org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration
application.properties (If using properties)
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With