- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们正在将 Spring 与 Kafka 消费者和生产者一起使用。我们正在生成大小为 905 字节的消息。我们正在序列化消息并尝试将其反序列化以供下一个消费者使用。
消息有效负载类示例:
{
"FILE_LIST":[
{
"KEY1": "Large String Value",
"KEY2": "Large String Value",
"Key3": "Large String Value",
"Key4": "Large String Value"
}
]
}
有效负载类别
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@NoArgsConstructor
@AllArgsConstructor
public class InnerModel {
@JsonProperty("KEY1")
@Getter
@Setter
private String key1;
@JsonProperty("KEY2")
@Getter
@Setter
private String key2;
@JsonProperty("KEY3")
@Getter
@Setter
private String key3;
@JsonProperty("KEY4")
@Getter
@Setter
private String key4;
}
CustomModel.java
package com.consumer.model;
public class CustomModel {
public CustomModel(List<InnerModel> filesList) {
super();
this.filesList = filesList;
}
@JsonProperty("FILE_LIST")
@NonNull
@Getter
@Setter
List<InnerModel> filesList;
}
消费者代码
import org.springframework.kafka.annotation.KafkaHandler;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
@Component
@KafkaListener(topics = "customtopic", groupId = "customgroup")
public class CustomModelConsumer {
@KafkaHandler(isDefault = true)
private void consumeCustomModel(CustomModel model) {
System.out.println("Model Consumer");
System.out.println(model);
}
}
application.properties
spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.consumer.value-deserializer=org.springframework.kafka.support.serializer.JsonDeserializer
spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer
spring.kafka.producer.value-serializer=org.springframework.kafka.support.serializer.JsonSerializer
spring.kafka.producer.compression-type=gzip
spring.kafka.consumer.properties.spring.json.trusted.packages=com.consumer.model
当我们接受字符串格式的消息有效负载时,消费者工作得很好,但是当我们将消费者中的有效负载反序列化为对象时,我们会遇到问题。同样会抛出以下错误
org.apache.kafka.common.errors.SerializationException: Error deserializing key/value for partition customtopic-0 at offset 70. If needed, please seek past the record to continue consumption. Caused by: org.apache.kafka.common.errors.SerializationException: Can't deserialize data [[123, 34, 73, 78, 80, 85, 84, 95, 70, 73, 76, 69, 95, 76, 73, 83, 84, 34, 58, 91, 123, 34, 79, 82, 73, 71, 73, 78, 65, 76, 95, 67, 76, 73, 80, 95, 67, 85, 82, 82, 69, 78, 84, 34, 58, 34, 115, 51, 58, 47, 47, 98, 45, 97, 111, 45, 112, 114, 111, 100, 117, 99, 116, 45, 109, 111, 99, 107, 47, 55, 52, 49, 48, 57, 102, 98, 98, 45, 54, 102, 52, 101, 45, 52, 48, 54, 50, 45, 97, 98, 48, 102, 45, 100, 49, 102, 53, 98, 98, 102, 55, 49, 97, 56, 49, 47, 99, 108, 105, 112, 115, 47, 48, 58, 48, 48, 58, 48, 48, 46, 48, 48, 48, 95, 48, 58, 48, 51, 58, 48, 48, 46, 50, 48, 48, 47, 49, 48, 48, 48, 95, 111, 114, 105, 103, 105, 110, 97, 108, 99, 108, 105, 112, 47, 48, 58, 48, 48, 58, 48, 48, 46, 48, 48, 48, 95, 48, 58, 48, 51, 58, 48, 48, 46, 50, 48, 48, 47, 48, 58, 48, 48, 58, 48, 48, 46, 48, 48, 48, 95, 48, 58, 48, 51, 58, 48, 48, 46, 50, 48, 48, 47, 48, 58, 48, 48, 58, 48, 48, 46, 48, 48, 48, 95, 48, 58, 48, 51, 58, 48, 48, 46, 50, 48, 48, 46, 109, 112, 52, 34, 44, 34, 79, 82, 73, 71, 73, 78, 65, 76, 95, 67, 76, 73, 80, 95, 71, 76, 79, 66, 65, 76, 95, 84, 73, 77, 69, 83, 84, 65, 77, 80, 95, 67, 85, 82, 82, 69, 78, 84, 34, 58, 34, 115, 51, 58, 47, 47, 98, 45, 97, 111, 45, 112, 114, 111, 100, 117, 99, 116, 45, 109, 111, 99, 107, 47, 55, 52, 49, 48, 57, 102, 98, 98, 45, 54, 102, 52, 101, 45, 52, 48, 54, 50, 45, 97, 98, 48, 102, 45, 100, 49, 102, 53, 98, 98, 102, 55, 49, 97, 56, 49, 47, 99, 108, 105, 112, 115, 47, 48, 58, 48, 48, 58, 48, 48, 46, 48, 48, 48, 95, 48, 58, 48, 51, 58, 48, 48, 46, 50, 48, 48, 47, 49, 48, 48, 48, 95, 111, 114, 105, 103, 105, 110, 97, 108, 99, 108, 105, 112, 47, 48, 58, 48, 48, 58, 48, 48, 46, 48, 48, 48, 95, 48, 58, 48, 51, 58, 48, 48, 46, 50, 48, 48, 47, 48, 58, 48, 48, 58, 48, 48, 46, 48, 48, 48, 95, 48, 58, 48, 51, 58, 48, 48, 46, 50, 48, 48, 95, 116, 115, 47, 48, 58, 48, 48, 58, 48, 48, 46, 48, 48, 48, 95, 48, 58, 48, 51, 58, 48, 48, 46, 50, 48, 48, 95, 116, 115, 46, 106, 115, 111, 110, 34, 44, 34, 79, 82, 73, 71, 73, 78, 65, 76, 95, 67, 76, 73, 80, 95, 78, 69, 88, 84, 34, 58, 34, 115, 51, 58, 47, 47, 98, 45, 97, 111, 45, 112, 114, 111, 100, 117, 99, 116, 45, 109, 111, 99, 107, 47, 55, 52, 49, 48, 57, 102, 98, 98, 45, 54, 102, 52, 101, 45, 52, 48, 54, 50, 45, 97, 98, 48, 102, 45, 100, 49, 102, 53, 98, 98, 102, 55, 49, 97, 56, 49, 47, 99, 108, 105, 112, 115, 47, 48, 58, 48, 51, 58, 48, 48, 46, 48, 48, 48, 95, 48, 58, 48, 54, 58, 48, 48, 46, 50, 48, 48, 47, 49, 48, 48, 48, 95, 111, 114, 105, 103, 105, 110, 97, 108, 99, 108, 105, 112, 47, 48, 58, 48, 51, 58, 48, 48, 46, 48, 48, 48, 95, 48, 58, 48, 54, 58, 48, 48, 46, 50, 48, 48, 47, 48, 58, 48, 51, 58, 48, 48, 46, 48, 48, 48, 95, 48, 58, 48, 54, 58, 48, 48, 46, 50, 48, 48, 47, 48, 58, 48, 51, 58, 48, 48, 46, 48, 48, 48, 95, 48, 58, 48, 54, 58, 48, 48, 46, 50, 48, 48, 46, 109, 112, 52, 34, 44, 34, 79, 82, 73, 71, 73, 78, 65, 76, 95, 67, 76, 73, 80, 95, 71, 76, 79, 66, 65, 76, 95, 84, 73, 77, 69, 83, 84, 65, 77, 80, 95, 78, 69, 88, 84, 34, 58, 34, 115, 51, 58, 47, 47, 98, 45, 97, 111, 45, 112, 114, 111, 100, 117, 99, 116, 45, 109, 111, 99, 107, 47, 55, 52, 49, 48, 57, 102, 98, 98, 45, 54, 102, 52, 101, 45, 52, 48, 54, 50, 45, 97, 98, 48, 102, 45, 100, 49, 102, 53, 98, 98, 102, 55, 49, 97, 56, 49, 47, 99, 108, 105, 112, 115, 47, 48, 58, 48, 51, 58, 48, 48, 46, 48, 48, 48, 95, 48, 58, 48, 54, 58, 48, 48, 46, 50, 48, 48, 47, 49, 48, 48, 48, 95, 111, 114, 105, 103, 105, 110, 97, 108, 99, 108, 105, 112, 47, 48, 58, 48, 51, 58, 48, 48, 46, 48, 48, 48, 95, 48, 58, 48, 54, 58, 48, 48, 46, 50, 48, 48, 47, 48, 58, 48, 51, 58, 48, 48, 46, 48, 48, 48, 95, 48, 58, 48, 54, 58, 48, 48, 46, 50, 48, 48, 95, 116, 115, 47, 48, 58, 48, 51, 58, 48, 48, 46, 48, 48, 48, 95, 48, 58, 48, 54, 58, 48, 48, 46, 50, 48, 48, 95, 116, 115, 46, 106, 115, 111, 110, 34, 125, 93, 125]] from topic [customtopic] Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of
com.consumer.model.CustomModel
(no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator) at [Source: (byte[])"{"FILE_LIST":[{"KEY1":"Large String Value","KEY2":"Large String Value","Key3":"Large String Value"[truncated 405 bytes]; line: 1, column: 2] at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:67) ~[jackson-databind-2.9.5.jar:2.9.5] at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1451) ~[jackson-databind-2.9.5.jar:2.9.5] at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1027) ~[jackson-databind-2.9.5.jar:2.9.5] at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1290) ~[jackson-databind-2.9.5.jar:2.9.5] at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:326) ~[jackson-databind-2.9.5.jar:2.9.5] at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:159) ~[jackson-databind-2.9.5.jar:2.9.5] at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:1611) ~[jackson-databind-2.9.5.jar:2.9.5] at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1234) ~[jackson-databind-2.9.5.jar:2.9.5] at org.springframework.kafka.support.serializer.JsonDeserializer.deserialize(JsonDeserializer.java:198) ~[spring-kafka-2.1.4.RELEASE.jar:2.1.4.RELEASE] at org.apache.kafka.clients.consumer.internals.Fetcher.parseRecord(Fetcher.java:923) ~[kafka-clients-1.0.0.jar:na] at org.apache.kafka.clients.consumer.internals.Fetcher.access$2600(Fetcher.java:93) ~[kafka-clients-1.0.0.jar:na] at org.apache.kafka.clients.consumer.internals.Fetcher$PartitionRecords.fetchRecords(Fetcher.java:1100) ~[kafka-clients-1.0.0.jar:na] at org.apache.kafka.clients.consumer.internals.Fetcher$PartitionRecords.access$1200(Fetcher.java:949) ~[kafka-clients-1.0.0.jar:na] at org.apache.kafka.clients.consumer.internals.Fetcher.fetchRecords(Fetcher.java:570) ~[kafka-clients-1.0.0.jar:na] at org.apache.kafka.clients.consumer.internals.Fetcher.fetchedRecords(Fetcher.java:531) ~[kafka-clients-1.0.0.jar:na] at org.apache.kafka.clients.consumer.KafkaConsumer.pollOnce(KafkaConsumer.java:1146) ~[kafka-clients-1.0.0.jar:na] at org.apache.kafka.clients.consumer.KafkaConsumer.poll(KafkaConsumer.java:1103) ~[kafka-clients-1.0.0.jar:na] at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.run(KafkaMessageListenerContainer.java:667) ~[spring-kafka-2.1.4.RELEASE.jar:2.1.4.RELEASE] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_151] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_151] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151]
最佳答案
正如@Naveen Kumar所述,我缺少默认或全参数构造函数。更改代码如下所示,使其工作
package com.consumer.model;
@NoArgsConstructor
@AllArgsConstructor
public class CustomModel {
@JsonProperty("FILE_LIST")
@NonNull
@Getter
@Setter
List<InnerModel> filesList;
}
关于java - Kafka Consumer 无法为 JsonDeserializer 消费 905 字节的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49721019/
我通过 spring ioc 编写了一些 Rest 应用程序。但我无法解决这个问题。这是我的异常(exception): org.springframework.beans.factory.BeanC
我对 TestNG、Spring 框架等完全陌生,我正在尝试使用注释 @Value通过 @Configuration 访问配置文件注释。 我在这里想要实现的目标是让控制台从配置文件中写出“hi”,通过
为此工作了几个小时。我完全被难住了。 这是 CS113 的实验室。 如果用户在程序(二进制计算器)结束时选择继续,我们需要使用 goto 语句来到达程序的顶部。 但是,我们还需要释放所有分配的内存。
我正在尝试使用 ffmpeg 库构建一个小的 C 程序。但是我什至无法使用 avformat_open_input() 打开音频文件设置检查错误代码的函数后,我得到以下输出: Error code:
使用 Spring Initializer 创建一个简单的 Spring boot。我只在可用选项下选择 DevTools。 创建项目后,无需对其进行任何更改,即可正常运行程序。 现在,当我尝试在项目
所以我只是在 Mac OS X 中通过 brew 安装了 qt。但是它无法链接它。当我尝试运行 brew link qt 或 brew link --overwrite qt 我得到以下信息: ton
我在提交和 pull 时遇到了问题:在提交的 IDE 中,我看到: warning not all local changes may be shown due to an error: unable
我跑 man gcc | grep "-L" 我明白了 Usage: grep [OPTION]... PATTERN [FILE]... Try `grep --help' for more inf
我有一段代码,旨在接收任何 URL 并将其从网络上撕下来。到目前为止,它运行良好,直到有人给了它这个 URL: http://www.aspensurgical.com/static/images/a
在过去的 5 个小时里,我一直在尝试在我的服务器上设置 WireGuard,但在完成所有设置后,我无法 ping IP 或解析域。 下面是服务器配置 [Interface] Address = 10.
我正在尝试在 GitLab 中 fork 我的一个私有(private)项目,但是当我按下 fork 按钮时,我会收到以下信息: No available namespaces to fork the
我这里遇到了一些问题。我是 node.js 和 Rest API 的新手,但我正在尝试自学。我制作了 REST API,使用 MongoDB 与我的数据库进行通信,我使用 Postman 来测试我的路
下面的代码在控制台中给出以下消息: Uncaught DOMException: Failed to execute 'appendChild' on 'Node': The new child el
我正在尝试调用一个新端点来显示数据,我意识到在上一组有效的数据中,它在数据周围用一对额外的“[]”括号进行控制台,我认为这就是问题是,而新端点不会以我使用数据的方式产生它! 这是 NgFor 失败的原
我正在尝试将我的 Symfony2 应用程序部署到我的 Azure Web 应用程序,但遇到了一些麻烦。 推送到远程时,我在终端中收到以下消息 remote: Updating branch 'mas
Minikube已启动并正在运行,没有任何错误,但是我无法 curl IP。我在这里遵循:https://docs.traefik.io/user-guide/kubernetes/,似乎没有提到关闭
每当我尝试docker组成任何项目时,都会出现以下错误。 我尝试过有和没有sudo 我在这台机器上只有这个问题。我可以在Mac和Amazon WorkSpace上运行相同的容器。 (myslabs)
我正在尝试 pip install stanza 并收到此消息: ERROR: No matching distribution found for torch>=1.3.0 (from stanza
DNS 解析看起来不错,但我无法 ping 我的服务。可能是什么原因? 来自集群中的另一个 Pod: $ ping backend PING backend.default.svc.cluster.l
我正在使用Hibernate 4 + Spring MVC 4当我开始 Apache Tomcat Server 8我收到此错误: Error creating bean with name 'wel
我是一名优秀的程序员,十分优秀!