kafka AdminClient获取kafka版本

时间:2019-07-12 08:18:28

标签: apache-kafka

有没有办法以编程方式获取kafka集群的版本?例如,使用 AdminClient API。

我想在消费者/生产者应用程序中识别kafka集群的版本。

2 个答案:

答案 0 :(得分:0)

您可以在消费者/生产者代码中使用@Configuration @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/managers").hasRole("MANAGERS") .antMatchers("/employees").hasRole("EMPLOYEES") .anyRequest().fullyAuthenticated() .and() .formLogin() .and() .logout() .logoutSuccessUrl("/") .deleteCookies("JSESSIONID") .invalidateHttpSession(true); } @Override public void configure(AuthenticationManagerBuilder auth) throws Exception { auth .ldapAuthentication() .userDnPatterns("uid={0},ou=people") .groupSearchBase("ou=groups") .contextSource(contextSource()) .passwordCompare() .passwordEncoder(new LdapShaPasswordEncoder()) .passwordAttribute("userPassword"); } @Bean public DefaultSpringSecurityContextSource contextSource() { return new DefaultSpringSecurityContextSource( Collections.singletonList("ldap://localhost:10389"), "dc=memorynotfound,dc=com"); }

答案 1 :(得分:0)

目前无法检索正在运行的Kafka版本代理。

正在进行KIP将该功能添加到AdminClient:KIP-483: Add Broker Version API in Admin Client,以便将来的版本中可用。

同时,您可以尝试以下几种解决方法:

  • 使用describeConfigs()查找代理的inter.broker.protocol.version配置。如果返回2.2-IV1,则表示代理正在运行至少 2.2。

  • 检查ApiVersions响应。启动时,客户端发送ApiVersions请求,并将响应写入日志(在INFO级别)。或手动发送ApiVersions,由于它是一个空的主体,因此很容易制定这样的请求。然后,您可以使用https://cwiki.apache.org/confluence/display/KAFKA/Kafka+APIs

  • 识别代理版本