java - 启用 SSL 的 kafka 配置:错误:在创建地图/配置时找不到合适的方法
问题描述
我是 kafka-stream 的新手,我们正在尝试向受 SSL 保护的 kafka 主题发送消息。因此,我们在流配置中添加了额外的 SSl-config-properties,如下所示:
@Configuration
@EnableKafkaStreams
public class KafkaStreamConfig {
@Autowired
private PreferredMediaMsgStreamProperties appProperties;
@Value("${spring.kafka.streams.properties.receive.buffer.bytes}")
private String receiveBufferBytes;
@Bean(name = KafkaStreamsDefaultConfiguration.DEFAULT_STREAMS_CONFIG_BEAN_NAME)
public KafkaStreamsConfiguration kStreamsConfigs() {
Map<String, Object> props = Map.of(
StreamsConfig.APPLICATION_ID_CONFIG, appProperties.getApplicationId(),
StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, appProperties.getBootstrapServers(),
//configure the following three settings for SSL Encryption
CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, "SSL",
SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, "/etc/ssl/container/truststore.jks",
SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, "changeit",
// configure the following three settings for SSL Authentication
SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, "/etc/ssl/container/server.jks",
SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, "changeit",
SslConfigs.SSL_KEY_PASSWORD_CONFIG, "changeit",
StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, PreferredMediaMsgStreamProperties.Constants.KEY_SERDE.getClass().getName(),
StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, PreferredMediaMsgStreamProperties.Constants.VALUE_SERDE.getClass().getName(),
StreamsConfig.DEFAULT_TIMESTAMP_EXTRACTOR_CLASS_CONFIG, WallclockTimestampExtractor.class.getName(),
StreamsConfig.RECEIVE_BUFFER_CONFIG, receiveBufferBytes
);
return new KafkaStreamsConfiguration(props);
}
@Bean
public KafkaAdmin admin() {
Map<String, Object> configs = Map.of(
AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, appProperties.getBootstrapServers());
return new KafkaAdmin(configs);
}
}
我在编译期间看到的错误消息是:
error: no suitable method found for of(String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String)
Map<String, Object> props = Map.of(
^
method Map.<K#1,V#1>of() is not applicable
(cannot infer type-variable(s) K#1,V#1
(actual and formal argument lists differ in length))
method Map.<K#2,V#2>of(K#2,V#2) is not applicable
(cannot infer type-variable(s) K#2,V#2
(actual and formal argument lists differ in length))
method Map.<K#3,V#3>of(K#3,V#3,K#3,V#3) is not applicable
(cannot infer type-variable(s) K#3,V#3
(actual and formal argument lists differ in length))
method Map.<K#4,V#4>of(K#4,V#4,K#4,V#4,K#4,V#4) is not applicable
(cannot infer type-variable(s) K#4,V#4
(actual and formal argument lists differ in length))
method Map.<K#5,V#5>of(K#5,V#5,K#5,V#5,K#5,V#5,K#5,V#5) is not applicable
(cannot infer type-variable(s) K#5,V#5
(actual and formal argument lists differ in length))
method Map.<K#6,V#6>of(K#6,V#6,K#6,V#6,K#6,V#6,K#6,V#6,K#6,V#6) is not applicable
(cannot infer type-variable(s) K#6,V#6
(actual and formal argument lists differ in length))
method Map.<K#7,V#7>of(K#7,V#7,K#7,V#7,K#7,V#7,K#7,V#7,K#7,V#7,K#7,V#7) is not applicable
(cannot infer type-variable(s) K#7,V#7
(actual and formal argument lists differ in length))
method Map.<K#8,V#8>of(K#8,V#8,K#8,V#8,K#8,V#8,K#8,V#8,K#8,V#8,K#8,V#8,K#8,V#8) is not applicable
(cannot infer type-variable(s) K#8,V#8
(actual and formal argument lists differ in length))
method Map.<K#9,V#9>of(K#9,V#9,K#9,V#9,K#9,V#9,K#9,V#9,K#9,V#9,K#9,V#9,K#9,V#9,K#9,V#9) is not applicable
(cannot infer type-variable(s) K#9,V#9
(actual and formal argument lists differ in length))
method Map.<K#10,V#10>of(K#10,V#10,K#10,V#10,K#10,V#10,K#10,V#10,K#10,V#10,K#10,V#10,K#10,V#10,K#10,V#10,K#10,V#10) is not applicable
(cannot infer type-variable(s) K#10,V#10
(actual and formal argument lists differ in length))
method Map.<K#11,V#11>of(K#11,V#11,K#11,V#11,K#11,V#11,K#11,V#11,K#11,V#11,K#11,V#11,K#11,V#11,K#11,V#11,K#11,V#11,K#11,V#11) is not applicable
(cannot infer type-variable(s) K#11,V#11
(actual and formal argument lists differ in length))
where K#1,V#1,K#2,V#2,K#3,V#3,K#4,V#4,K#5,V#5,K#6,V#6,K#7,V#7,K#8,V#8,K#9,V#9,K#10,V#10,K#11,V#11 are type-variables:
K#1 extends Object declared in method <K#1,V#1>of()
V#1 extends Object declared in method <K#1,V#1>of()
K#2 extends Object declared in method <K#2,V#2>of(K#2,V#2)
V#2 extends Object declared in method <K#2,V#2>of(K#2,V#2)
K#3 extends Object declared in method <K#3,V#3>of(K#3,V#3,K#3,V#3)
V#3 extends Object declared in method <K#3,V#3>of(K#3,V#3,K#3,V#3)
K#4 extends Object declared in method <K#4,V#4>of(K#4,V#4,K#4,V#4,K#4,V#4)
V#4 extends Object declared in method <K#4,V#4>of(K#4,V#4,K#4,V#4,K#4,V#4)
K#5 extends Object declared in method <K#5,V#5>of(K#5,V#5,K#5,V#5,K#5,V#5,K#5,V#5)
V#5 extends Object declared in method <K#5,V#5>of(K#5,V#5,K#5,V#5,K#5,V#5,K#5,V#5)
K#6 extends Object declared in method <K#6,V#6>of(K#6,V#6,K#6,V#6,K#6,V#6,K#6,V#6,K#6,V#6)
V#6 extends Object declared in method <K#6,V#6>of(K#6,V#6,K#6,V#6,K#6,V#6,K#6,V#6,K#6,V#6)
K#7 extends Object declared in method <K#7,V#7>of(K#7,V#7,K#7,V#7,K#7,V#7,K#7,V#7,K#7,V#7,K#7,V#7)
V#7 extends Object declared in method <K#7,V#7>of(K#7,V#7,K#7,V#7,K#7,V#7,K#7,V#7,K#7,V#7,K#7,V#7)
K#8 extends Object declared in method <K#8,V#8>of(K#8,V#8,K#8,V#8,K#8,V#8,K#8,V#8,K#8,V#8,K#8,V#8,K#8,V#8)
V#8 extends Object declared in method <K#8,V#8>of(K#8,V#8,K#8,V#8,K#8,V#8,K#8,V#8,K#8,V#8,K#8,V#8,K#8,V#8)
K#9 extends Object declared in method <K#9,V#9>of(K#9,V#9,K#9,V#9,K#9,V#9,K#9,V#9,K#9,V#9,K#9,V#9,K#9,V#9,K#9,V#9)
V#9 extends Object declared in method <K#9,V#9>of(K#9,V#9,K#9,V#9,K#9,V#9,K#9,V#9,K#9,V#9,K#9,V#9,K#9,V#9,K#9,V#9)
K#10 extends Object declared in method <K#10,V#10>of(K#10,V#10,K#10,V#10,K#10,V#10,K#10,V#10,K#10,V#10,K#10,V#10,K#10,V#10,K#10,V#10,K#10,V#10)
V#10 extends Object declared in method <K#10,V#10>of(K#10,V#10,K#10,V#10,K#10,V#10,K#10,V#10,K#10,V#10,K#10,V#10,K#10,V#10,K#10,V#10,K#10,V#10)
K#11 extends Object declared in method <K#11,V#11>of(K#11,V#11,K#11,V#11,K#11,V#11,K#11,V#11,K#11,V#11,K#11,V#11,K#11,V#11,K#11,V#11,K#11,V#11,K#11,V#11)
V#11 extends Object declared in method <K#11,V#11>of(K#11,V#11,K#11,V#11,K#11,V#11,K#11,V#11,K#11,V#11,K#11,V#11,K#11,V#11,K#11,V#11,K#11,V#11,K#11,V#11)
Note: /Users/pbose/patrali_sand/notification-preference-stream/src/main/java/com/talentreef/notification/preference/utils/RecipientPoolValueJoiner.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
如果我取出下面的属性,那么它编译得很好:
//configure the following three settings for SSL Encryption
CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, "SSL",
SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, "/etc/ssl/container/truststore.jks",
SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, "changeit",
// configure the following three settings for SSL Authentication
SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, "/etc/ssl/container/server.jks",
SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, "changeit",
SslConfigs.SSL_KEY_PASSWORD_CONFIG, "changeit",
我可以了解这里发生了什么吗?
解决方案
Map.of()
有最多 10 个条目的重载(检查这个)。你总共有 11 个。这就是为什么当您删除其中的 6 个时会编译。
如果你想让这个工作使用Map.ofEntries()
. 此方法采用可变参数,并且对条目数没有限制。
推荐阅读
- reactjs - React Native - StyleSheet.absoluteFill() 和 StyleSheet.absoluteFillObject() 有什么区别?
- html - 用不同的链接颜色覆盖 CSS
- eclipse - 驱动器映射更改后的 Maven Eclipse 错误
- ros - roslibjs - 使用自定义消息订阅主题
- swift - Swift 4 中的全屏 UIImage
- c# - 模型绑定 Asp.Net Core 与用户名
- python - 从数据框中删除内容可能是字符串选择的行
- java - 无法为事务打开 JPA EntityManager(使用 LocalContainerEntityManagerFactoryBean)
- excel - 具有可变固定单元格的 R1C1 公式格式
- java - 使用 apache poi 从 pptx 获取幻灯片 id