Приложения должны запускаться, даже если посредники недоступны.
Вы можете добавить связыватель oop в classpath и сделать его связующим по умолчанию или указать его для привязки. Вот некоторый код с Kotlin:
Класс реализации NoOpBinder:
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]"
}
}
Класс конфигурации:
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
Укажите подшивку в файле конфигурации application.yml
spring:
cloud:
stream:
bindings:
my-binding:
destination: my-destination
group: my-group
binder: noop