继续在 Kafka 连接失败时启动 Spring Kafka。

huangapple go评论70阅读模式
英文:

Continue Spring Kafka Startup even on Kafka Connection Failure

问题

有没有配置可以让Spring在启动时继续,并在Kafka连接失败的情况下初始化Beans

我正在使用Spring Framework 5.2.3和Spring Kafka 2.5.3.RELEASE。

英文:

Is there a configuration I can use to instruct Spring to continue on startup and initialize the Beans even if Kafka connection failed?

I am using Spring Framework 5.2.3 and Spring Kafka 2.5.3.RELEASE.

答案1

得分: 1

如果您的应用程序在每种用例中都需要使用 Kafka beans,那么如果没有 Kafka 连接,继续启动就没有意义。没有 Kafka,您的应用程序将无法执行任何操作。

但是,如果您的应用程序的某些部分不需要使用 Kafka,并且您只想使用这些部分,那么您可以将与 Kafka 相关的 beans 标记为懒加载,或者默认情况下将所有的 beans 都设置为懒加载。在这种情况下,Spring 只会在实际需要时才创建这些 beans。即使没有可用的 Kafka 连接,不需要 Kafka 的应用程序部分也将正常工作。

英文:

If you need kafka beans for your application to work in every use case then continue with startup if there is no kafka connection makes no sense. Your application will not be able to do anything without kafka.

But if some parts of your application do not need kafka and you would like to use only those parts then you can either mark kafka related beans as lazy or make all beans lazy by default. In this case spring will create beans only when they are actually needed. And even if there is no kafka connection available parts of your app that do not need kafka will work.

huangapple
  • 本文由 发表于 2020年9月8日 11:59:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/63786910.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定