[英]Spring Cloud Kafka Consumer Properties not working
我有以下 application.yml 文件:
spring:
application:
name: test-app
cloud:
stream:
kafka:
binder:
consumerProperties:
value:
deserializer: org.apache.kafka.common.serialization.StringDeserializer
brokers: localhost:9092
autoCreateTopics: true
replicationFactor: 1
bindings:
listenCloudEvent-in-0:
destination: com.test.cloudevent
group: test-app-group
consumer:
configuration:
value:
deserializer: io.cloudevents.kafka.CloudEventDeserializer
listenString-in-0:
destination: com.test.string
group: test-app-group
function:
definition: listenCloudEvent;listenString
據我所知,以下屬性應該覆蓋默認的反序列化器,但它似乎不起作用。
consumer:
configuration:
value:
deserializer: io.cloudevents.kafka.CloudEventDeserializer
對於com.test.couldevent
主題,我收到以下錯誤。
org.springframework.messaging.converter.MessageConversionException:無法讀取 JSON:無法構造
io.cloudevents.CloudEvent
的實例(不存在 Creator,如默認構造函數):抽象類型需要映射到具體類型,具有自定義反序列化器,或包含額外的類型信息
如果我將默認反序列化器更改為事件雲反序列化器,那么它可以工作,但其他偵聽器會停止。
這是我的聽眾 function:
@Bean
public Consumer<Flux<Message<CloudEvent>>> listenCloudEvent() {
return inboundMessage -> inboundMessage
.onErrorStop()
.doOnNext(message -> log.info("[{}] Message is received.", message.getPayload().getId()))
.subscribe();
}
如果您能幫助我解決這個問題,我將不勝感激。 我的主要目標是針對不同的主題使用不同的反序列化器。 但是,盡管在 spring 文檔中指示以這種方式覆蓋默認反序列化器,但我無法成功。
先感謝您!
你錯過了kafka.
消費者屬性中的元素。 configuration
是特定於 kafka 的屬性,您正在設置一個通用的消費者屬性。
以下屬性僅適用於 Kafka 消費者,並且必須以
spring.cloud.stream.kafka.bindings.<channelName>.consumer..
為前綴
注意...stream.kafka.bindings...
,而不是...stream.bindings...
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.