亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

啟動springboot服務器時如何繞過kafka代理失敗?

啟動springboot服務器時如何繞過kafka代理失?。?/h1>
瀟瀟雨雨 2023-09-27 10:16:35
我在 spring-boot(2.1.7.RELEASE) 應用程序服務器中遇到問題,該服務器使用 spring-boot-Kafka('spring-Kafka' -'2.2.7.RELEASE') 集成庫來訪問我的 Kafka 主題。當我的 Kafka 代理關閉時,我的應用程序無法啟動。這就是我得到的:2019-10-06 02:41:02.764  WARN -- [main           ] org.apache.kafka.clients.NetworkClient                       [] : [Consumer clientId=consumer-1, groupId=caas] Connection to node -1 could not be established. Broker may not be available.Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.2019-10-06 02:41:31.777 ERROR -- [main           ] org.springframework.boot.SpringApplication                   [] : Application run failedorg.springframework.context.ApplicationContextException: Failed to start bean 'org.springframework.kafka.config.internalKafkaListenerEndpointRegistry'; nested exception is org.apache.kafka.common.errors.TimeoutException: Timeout expired while fetching topic metadata    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:185)    at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:53)    at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:360)    at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:158)    at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:122)    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:893)    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:162)    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:552)有沒有辦法繞過對 Kafka 代理的依賴?即使經紀人不可用/關閉,我也希望我的應用程序能夠啟動。一旦代理啟動,應用程序服務器應該能夠連接。
查看完整描述

2 回答

?
弒天下

TA貢獻1818條經驗 獲得超8個贊

有一個容器屬性missingTopicsFatal: https://docs.spring.io/spring-kafka/api/org/springframework/kafka/listener/ContainerProperties.html#isMissingTopicsFatal - 即使主題和/或經紀人不可用。

@Bean(name = "kafkaListenerContainerFactory")

public ConcurrentKafkaListenerContainerFactory<?, ?> kafkaListenerContainerFactory(

    ConsumerFactory<Object, Object> kafkaConsumerFactor,

    ConcurrentKafkaListenerContainerFactoryConfigurer configurer) {


  ConcurrentKafkaListenerContainerFactory<Object, Object> factory =

      new ConcurrentKafkaListenerContainerFactory<>();

  configurer.configure(factory, kafkaConsumerFactor);


  ContainerProperties containerProperties = factory.getContainerProperties();

  containerProperties.setMissingTopicsFatal(false);


  ...

  return factory;

}


查看完整回答
反對 回復 2023-09-27
?
慕勒3428872

TA貢獻1848條經驗 獲得超6個贊

這是新版本的spring的變化。


@Component

class ContainerFactoryConfigurer {


    ContainerFactoryConfigurer(ConcurrentKafkaListenerContainerFactory<?, ?> factory) {

        factory.getContainerProperties().setMissingTopicsFatal(false);

    }


}


查看完整回答
反對 回復 2023-09-27
  • 2 回答
  • 0 關注
  • 177 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號