{"id":205,"date":"2022-02-12T23:24:00","date_gmt":"2022-02-12T23:24:00","guid":{"rendered":"https:\/\/liangqi.org\/?p=205"},"modified":"2022-02-12T23:24:01","modified_gmt":"2022-02-12T23:24:01","slug":"%e5%af%b9%e8%b1%a1%e7%9a%84%e5%ba%8f%e5%88%97%e5%8c%96","status":"publish","type":"post","link":"https:\/\/liangqi.org\/?p=205","title":{"rendered":"\u5bf9\u8c61\u7684\u5e8f\u5217\u5316"},"content":{"rendered":"\n<p>\u5bf9\u8c61\u7684\u5e8f\u5217\u5316\u548c\u4f20\u8f93\u5728\u8fc7\u53bb\u8fd9\u4e9b\u5e74\u4e5f\u53d1\u751f\u4e86\u5f88\u591a\u7684\u53d8\u5316\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"java\u5e8f\u5217\u5316\">Java\u5e8f\u5217\u5316<\/h2>\n\n\n\n<p>\u5f88\u65e9\u4ee5\u524d\u7528\u8fd9\u4e2a\uff0c\u56e0\u4e3a\u8fd9\u79cd\u5e8f\u5217\u5316\u65b9\u5f0f\u53ea\u80fd\u5c40\u9650\u4e8e\u4e00\u4e2a\u5355\u4e00\u8bed\u8a00\uff0c\u5df2\u7ecf\u4e0d\u518d\u7528\u4e86\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"json\">Json<\/h2>\n\n\n\n<p>\u7528Jackson\u7684ObjectMapper\u628a\u4e00\u4e2a\u5bf9\u8c61\u5e8f\u5217\u5316\u6210Jason\uff0c\u7136\u540e\u518d\u53cd\u5e8f\u5217\u5316.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"avro\">Avro<\/h2>\n\n\n\n<p>Kafka\u7684\u9ed8\u8ba4\u65b9\u5f0f\u3002\u9700\u8981\u63d0\u524d\u9884\u5b9a\u4e49\u597dmodel\uff0c\u5e8f\u5217\u5316\uff0c\u53cd\u5e8f\u5217\u5316\u7684\u65f6\u5019\u90fd\u9700\u8981\u7528\u90a3\u4e2amodel\u3002model\u66f4\u65b0\u7684\u65f6\u5019\u6211\u8bb0\u5f97\u5e76\u4e0d\u50cf\u60f3\u8c61\u7684\u90a3\u4e48\u7b80\u5355\u3002\u6bd4\u5982\u8bf4\u52a0\u4e00\u4e2a\u5b57\u6bb5\u3002<br>\u6211\u4eec\u5fc5\u987basdl\u5b9a\u4e49<br>NoAE\u7684\u6240\u6709\u7684\u6d88\u606f\u90fd\u6709\u81ea\u5df1\u5bf9\u5e94\u7684Class\uff0cSerializer\u548cDeseriallizer\uff0c\u90fd\u662f\u57fa\u4e8eAvro\u7684\u3002\u6bd4\u5982<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">NotificationInstanceDeserializer<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\/\/NotificationInstance is generated from *.avdl<\/strong>\npublic class NotificationInstanceDeserializer extends GenericBinaryDeserializer&lt;NotificationInstance&gt; {\n    public NotificationInstanceDeserializer() {\n    }\n    \/\/NotificationInstance is Avro auto generated.\n    public Class&lt;NotificationInstance&gt; getType() {\n        return NotificationInstance.class;\n    }\n\n    public List&lt;Schema&gt; getWriterSchemas() {\n        List&lt;Schema&gt; prevSchemas = new ArrayList();\n        prevSchemas.add(NotificationInstanceOld.getClassSchema());\n        return prevSchemas;\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">NotificationInstanceSerializer<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong><strong>\/\/NotificationInstance is generated from *.avdl<\/strong><\/strong>\npublic class NotificationInstanceSerializer extends GenericBinarySerializer&lt;NotificationInstance&gt; {\n    public NotificationInstanceSerializer() {\n    }\n\n    public Schema getSchema() {\n        return NotificationInstance.getClassSchema();\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">AvroSerializer.java (This copied from GenericBinarySerializer.java in CDC-model)<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ The class has to extend the Avro class \"SpecificRecordBASE\"\npublic class AvroSerializer&lt;T extends SpecificRecordBase&gt; implements Serializer&lt;T&gt; {\n\n    @Override\n    public byte&#91;] serialize(String topic, T data) {\n        if (data == null) {\n            return null;\n        }\n\n        try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {\n            BinaryEncoder encoder = ENCODER_FACTORY.binaryEncoder(baos, null);\n            DatumWriter&lt;T&gt; writer = new SpecificDatumWriter&lt;&gt;(getSchema());\n            writer.write(data, encoder);\n            encoder.flush();\n            return baos.toByteArray();\n        } catch (IOException e) {\n            LOGGER.w\n        }\n    }<\/code><\/pre>\n\n\n\n<p>\u800cDACO\u7684Serializer\u548cDeserializer\u90fd\u662f\u7528\u4e00\u4e2a JsonSerializer.\u5176\u5b9e\u5c31\u662fJakson\u7684ObjectMapper\u7684\u5b9e\u73b0\u3002\u4e0d\u8fc7\u4f20\u8f93\u7684\u90fd\u662f\u4e8c\u8fdb\u5236\uff08\u4f46\u662f\u5176\u5b9e\u5c31\u662fjson\u4e13\u7a0bbytes\u800c\u5df2\uff0cKafka\u7684\u6240\u6709\u6d88\u606f\u90fd\u662fbytes\uff09\u3002DataModel\u5fc5\u987b\u662fJsonNode\u7684\u5b9e\u73b0(\u5176\u5b9e\u4e0d\u9700\u8981\uff0cobjectMapper.writeValueAsBytes\u8fd9\u4e2a\u65b9\u6cd5\u5c31\u662f\u63a5\u53d7Object)\u3002\u6ca1\u6709\u8bed\u8a00\u72ec\u7acb\u7684\u8868\u8fbe\u3002\u3002\u7ed1\u5b9aJackson.<\/p>\n\n\n\n<p><strong>\u8fd9\u4e2a\u5c31\u662f\u5077\u61d2\u7684\u505a\u6cd5\u3002\u4e0d\u9700\u8981\u5b9a\u4e49avil\u6587\u4ef6\uff0c\u53ea\u9700\u8981\u5199\u4e00\u4e2a\u7ee7\u627fJsonNode\u7684bean\u5c31\u597d\u3002\u4e3b\u8981\u662f\u516c\u53f8\u6ca1\u6709\u4e00\u4e2a\u7edf\u4e00\u7684\u6807\u51c6\uff0c\u5927\u5bb6\u90fd\u9009\u62e9\u81ea\u5df1\u6700convinience\u7684\u65b9\u6cd5\u53bb\u505a\u3002\u4ee5\u540e\u5982\u679c\u8981\u6539\u683c\u5f0f\u5c31\u8fd8\u633a\u9ebb\u70e6\u3002<br><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">JsonSerializer.java<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\npublic class JsonSerializer implements Serializer&lt;<strong>JsonNode<\/strong>&gt; {\n\n    public byte&#91;] serialize(String topic, JsonNode data) {\n        if (data == null) {\n            return null;\n        }\n\n        try {\n            return objectMapper.writeValueAsBytes(data);\n        } catch (IOException e) {\n            throw new SerializationException(\"Error serializing JSON message\", e);\n        }\n\n    }<\/code><\/pre>\n\n\n\n<p>KafkaJsonDeserializer.java. \u6240\u4ee5Kafka consumer\u90fd\u662f\u62ff\u7684JsonNode,\u9700\u8981\u518d\u8f6c\u4e3a\u5b50\u7c7b\u3002\u6bd4\u5982NotificationMessage.java <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class KafkaJsonDeserializer implements Deserializer&lt;JsonNode&gt; {\n    private static final ObjectMapper MAPPER = Jackson.newObjectMapper()\n            .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)\n            .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);\n\n    @Override\n    public void configure(Map&lt;String, ?&gt; configs, boolean isKey) {\n\n    }\n\n    @Override\n    public <strong>JsonNode<\/strong> deserialize(String key, byte&#91;] bytes) {\n        try {\n            return MAPPER.readTree(bytes);\n        } catch (IOException e) {\n            throw new UncheckedIOException(e);\n        }\n    }<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"protocal-buffer\">Protocal Buffer<\/h2>\n\n\n\n<p>gRPC\u7684\u9ed8\u8ba4\u65b9\u5f0f\u3002\u548cAvro\u7c7b\u4f3c\u3002\u5c3a\u5bf8\u90fd\u6bd4\u8f83\u5c0f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5bf9\u8c61\u7684\u5e8f\u5217\u5316\u548c\u4f20\u8f93\u5728\u8fc7\u53bb\u8fd9\u4e9b\u5e74\u4e5f\u53d1\u751f\u4e86\u5f88\u591a\u7684\u53d8\u5316\u3002 Java\u5e8f\u5217\u5316 \u5f88\u65e9\u4ee5\u524d\u7528\u8fd9\u4e2a\uff0c\u56e0\u4e3a\u8fd9\u79cd\u5e8f\u5217\u5316\u65b9\u5f0f\u53ea\u80fd\u5c40\u9650\u4e8e\u4e00\u4e2a\u5355\u4e00\u8bed\u8a00\uff0c\u5df2\u7ecf\u4e0d\u518d\u7528\u4e86\u3002 Json \u7528Jackson\u7684ObjectMapper\u628a\u4e00\u4e2a\u5bf9\u8c61\u5e8f\u5217\u5316\u6210Jason\uff0c\u7136\u540e\u518d\u53cd\u5e8f\u5217\u5316. Avro Kafka\u7684\u9ed8\u8ba4\u65b9\u5f0f\u3002\u9700\u8981\u63d0\u524d\u9884\u5b9a\u4e49\u597dmodel\uff0c\u5e8f\u5217\u5316\uff0c\u53cd\u5e8f\u5217\u5316\u7684\u65f6\u5019\u90fd\u9700\u8981\u7528\u90a3\u4e2amodel\u3002model\u66f4\u65b0\u7684\u65f6\u5019\u6211\u8bb0\u5f97\u5e76\u4e0d\u50cf\u60f3\u8c61\u7684\u90a3\u4e48\u7b80\u5355\u3002\u6bd4\u5982\u8bf4\u52a0\u4e00\u4e2a\u5b57\u6bb5\u3002\u6211\u4eec\u5fc5\u987basdl\u5b9a\u4e49NoAE\u7684\u6240\u6709\u7684\u6d88\u606f\u90fd\u6709\u81ea\u5df1\u5bf9\u5e94\u7684Class\uff0cSerializer\u548cDeseriallizer\uff0c\u90fd\u662f\u57fa\u4e8eAvro\u7684\u3002\u6bd4\u5982 NotificationInstanceDeserializer NotificationInstanceSerializer AvroSerializer.java (This copied from GenericBinarySerializer.java in CDC-model) \u800cDACO\u7684Serializer\u548cDeserializer\u90fd\u662f\u7528\u4e00\u4e2a JsonSerializer.\u5176\u5b9e\u5c31\u662fJakson\u7684ObjectMapper\u7684\u5b9e\u73b0\u3002\u4e0d\u8fc7\u4f20\u8f93\u7684\u90fd\u662f\u4e8c\u8fdb\u5236\uff08\u4f46\u662f\u5176\u5b9e\u5c31\u662fjson\u4e13\u7a0bbytes\u800c\u5df2\uff0cKafka\u7684\u6240\u6709\u6d88\u606f\u90fd\u662fbytes\uff09\u3002DataModel\u5fc5\u987b\u662fJsonNode\u7684\u5b9e\u73b0(\u5176\u5b9e\u4e0d\u9700\u8981\uff0cobjectMapper.writeValueAsBytes\u8fd9\u4e2a\u65b9\u6cd5\u5c31\u662f\u63a5\u53d7Object)\u3002\u6ca1\u6709\u8bed\u8a00\u72ec\u7acb\u7684\u8868\u8fbe\u3002\u3002\u7ed1\u5b9aJackson. \u8fd9\u4e2a\u5c31\u662f\u5077\u61d2\u7684\u505a\u6cd5\u3002\u4e0d\u9700\u8981\u5b9a\u4e49avil\u6587\u4ef6\uff0c\u53ea\u9700\u8981\u5199\u4e00\u4e2a\u7ee7\u627fJsonNode\u7684bean\u5c31\u597d\u3002\u4e3b\u8981\u662f\u516c\u53f8\u6ca1\u6709\u4e00\u4e2a\u7edf\u4e00\u7684\u6807\u51c6\uff0c\u5927\u5bb6\u90fd\u9009\u62e9\u81ea\u5df1\u6700convinience\u7684\u65b9\u6cd5\u53bb\u505a\u3002\u4ee5\u540e\u5982\u679c\u8981\u6539\u683c\u5f0f\u5c31\u8fd8\u633a\u9ebb\u70e6\u3002 JsonSerializer.java KafkaJsonDeserializer.java. \u6240\u4ee5Kafka consumer\u90fd\u662f\u62ff\u7684JsonNode,\u9700\u8981\u518d\u8f6c\u4e3a\u5b50\u7c7b\u3002\u6bd4\u5982NotificationMessage.java Protocal Buffer gRPC\u7684\u9ed8\u8ba4\u65b9\u5f0f\u3002\u548cAvro\u7c7b\u4f3c\u3002\u5c3a\u5bf8\u90fd\u6bd4\u8f83\u5c0f\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29,16],"tags":[],"class_list":["post-205","post","type-post","status-publish","format-standard","hentry","category-29","category-16"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5bf9\u8c61\u7684\u5e8f\u5217\u5316 - Liangqi\u2018s Technical Journey<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/liangqi.org\/?p=205\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5bf9\u8c61\u7684\u5e8f\u5217\u5316 - Liangqi\u2018s Technical Journey\" \/>\n<meta property=\"og:description\" content=\"\u5bf9\u8c61\u7684\u5e8f\u5217\u5316\u548c\u4f20\u8f93\u5728\u8fc7\u53bb\u8fd9\u4e9b\u5e74\u4e5f\u53d1\u751f\u4e86\u5f88\u591a\u7684\u53d8\u5316\u3002 Java\u5e8f\u5217\u5316 \u5f88\u65e9\u4ee5\u524d\u7528\u8fd9\u4e2a\uff0c\u56e0\u4e3a\u8fd9\u79cd\u5e8f\u5217\u5316\u65b9\u5f0f\u53ea\u80fd\u5c40\u9650\u4e8e\u4e00\u4e2a\u5355\u4e00\u8bed\u8a00\uff0c\u5df2\u7ecf\u4e0d\u518d\u7528\u4e86\u3002 Json \u7528Jackson\u7684ObjectMapper\u628a\u4e00\u4e2a\u5bf9\u8c61\u5e8f\u5217\u5316\u6210Jason\uff0c\u7136\u540e\u518d\u53cd\u5e8f\u5217\u5316. Avro Kafka\u7684\u9ed8\u8ba4\u65b9\u5f0f\u3002\u9700\u8981\u63d0\u524d\u9884\u5b9a\u4e49\u597dmodel\uff0c\u5e8f\u5217\u5316\uff0c\u53cd\u5e8f\u5217\u5316\u7684\u65f6\u5019\u90fd\u9700\u8981\u7528\u90a3\u4e2amodel\u3002model\u66f4\u65b0\u7684\u65f6\u5019\u6211\u8bb0\u5f97\u5e76\u4e0d\u50cf\u60f3\u8c61\u7684\u90a3\u4e48\u7b80\u5355\u3002\u6bd4\u5982\u8bf4\u52a0\u4e00\u4e2a\u5b57\u6bb5\u3002\u6211\u4eec\u5fc5\u987basdl\u5b9a\u4e49NoAE\u7684\u6240\u6709\u7684\u6d88\u606f\u90fd\u6709\u81ea\u5df1\u5bf9\u5e94\u7684Class\uff0cSerializer\u548cDeseriallizer\uff0c\u90fd\u662f\u57fa\u4e8eAvro\u7684\u3002\u6bd4\u5982 NotificationInstanceDeserializer NotificationInstanceSerializer AvroSerializer.java (This copied from GenericBinarySerializer.java in CDC-model) \u800cDACO\u7684Serializer\u548cDeserializer\u90fd\u662f\u7528\u4e00\u4e2a JsonSerializer.\u5176\u5b9e\u5c31\u662fJakson\u7684ObjectMapper\u7684\u5b9e\u73b0\u3002\u4e0d\u8fc7\u4f20\u8f93\u7684\u90fd\u662f\u4e8c\u8fdb\u5236\uff08\u4f46\u662f\u5176\u5b9e\u5c31\u662fjson\u4e13\u7a0bbytes\u800c\u5df2\uff0cKafka\u7684\u6240\u6709\u6d88\u606f\u90fd\u662fbytes\uff09\u3002DataModel\u5fc5\u987b\u662fJsonNode\u7684\u5b9e\u73b0(\u5176\u5b9e\u4e0d\u9700\u8981\uff0cobjectMapper.writeValueAsBytes\u8fd9\u4e2a\u65b9\u6cd5\u5c31\u662f\u63a5\u53d7Object)\u3002\u6ca1\u6709\u8bed\u8a00\u72ec\u7acb\u7684\u8868\u8fbe\u3002\u3002\u7ed1\u5b9aJackson. \u8fd9\u4e2a\u5c31\u662f\u5077\u61d2\u7684\u505a\u6cd5\u3002\u4e0d\u9700\u8981\u5b9a\u4e49avil\u6587\u4ef6\uff0c\u53ea\u9700\u8981\u5199\u4e00\u4e2a\u7ee7\u627fJsonNode\u7684bean\u5c31\u597d\u3002\u4e3b\u8981\u662f\u516c\u53f8\u6ca1\u6709\u4e00\u4e2a\u7edf\u4e00\u7684\u6807\u51c6\uff0c\u5927\u5bb6\u90fd\u9009\u62e9\u81ea\u5df1\u6700convinience\u7684\u65b9\u6cd5\u53bb\u505a\u3002\u4ee5\u540e\u5982\u679c\u8981\u6539\u683c\u5f0f\u5c31\u8fd8\u633a\u9ebb\u70e6\u3002 JsonSerializer.java KafkaJsonDeserializer.java. \u6240\u4ee5Kafka consumer\u90fd\u662f\u62ff\u7684JsonNode,\u9700\u8981\u518d\u8f6c\u4e3a\u5b50\u7c7b\u3002\u6bd4\u5982NotificationMessage.java Protocal Buffer gRPC\u7684\u9ed8\u8ba4\u65b9\u5f0f\u3002\u548cAvro\u7c7b\u4f3c\u3002\u5c3a\u5bf8\u90fd\u6bd4\u8f83\u5c0f\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/liangqi.org\/?p=205\" \/>\n<meta property=\"og:site_name\" content=\"Liangqi\u2018s Technical Journey\" \/>\n<meta property=\"article:published_time\" content=\"2022-02-12T23:24:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-12T23:24:01+00:00\" \/>\n<meta name=\"author\" content=\"liangqi\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"liangqi\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/liangqi.org\/?p=205#article\",\"isPartOf\":{\"@id\":\"https:\/\/liangqi.org\/?p=205\"},\"author\":{\"name\":\"liangqi\",\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3\"},\"headline\":\"\u5bf9\u8c61\u7684\u5e8f\u5217\u5316\",\"datePublished\":\"2022-02-12T23:24:00+00:00\",\"dateModified\":\"2022-02-12T23:24:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/liangqi.org\/?p=205\"},\"wordCount\":47,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3\"},\"articleSection\":[\"\u5de5\u5177\",\"\u6280\u672f\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/liangqi.org\/?p=205#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/liangqi.org\/?p=205\",\"url\":\"https:\/\/liangqi.org\/?p=205\",\"name\":\"\u5bf9\u8c61\u7684\u5e8f\u5217\u5316 - Liangqi\u2018s Technical Journey\",\"isPartOf\":{\"@id\":\"https:\/\/liangqi.org\/#website\"},\"datePublished\":\"2022-02-12T23:24:00+00:00\",\"dateModified\":\"2022-02-12T23:24:01+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/liangqi.org\/?p=205#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/liangqi.org\/?p=205\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/liangqi.org\/?p=205#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/liangqi.org\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5bf9\u8c61\u7684\u5e8f\u5217\u5316\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/liangqi.org\/#website\",\"url\":\"https:\/\/liangqi.org\/\",\"name\":\"Liangqi\u2018s Technical Journey\",\"description\":\"Chasing Excellence; Enjoy life.\",\"publisher\":{\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/liangqi.org\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3\",\"name\":\"liangqi\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/liangqi.org\/wp-content\/uploads\/2022\/01\/P1100089-3-scaled.jpg\",\"contentUrl\":\"https:\/\/liangqi.org\/wp-content\/uploads\/2022\/01\/P1100089-3-scaled.jpg\",\"width\":2560,\"height\":1920,\"caption\":\"liangqi\"},\"logo\":{\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:\/\/liangqi.org\"],\"url\":\"https:\/\/liangqi.org\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u5bf9\u8c61\u7684\u5e8f\u5217\u5316 - Liangqi\u2018s Technical Journey","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/liangqi.org\/?p=205","og_locale":"en_US","og_type":"article","og_title":"\u5bf9\u8c61\u7684\u5e8f\u5217\u5316 - Liangqi\u2018s Technical Journey","og_description":"\u5bf9\u8c61\u7684\u5e8f\u5217\u5316\u548c\u4f20\u8f93\u5728\u8fc7\u53bb\u8fd9\u4e9b\u5e74\u4e5f\u53d1\u751f\u4e86\u5f88\u591a\u7684\u53d8\u5316\u3002 Java\u5e8f\u5217\u5316 \u5f88\u65e9\u4ee5\u524d\u7528\u8fd9\u4e2a\uff0c\u56e0\u4e3a\u8fd9\u79cd\u5e8f\u5217\u5316\u65b9\u5f0f\u53ea\u80fd\u5c40\u9650\u4e8e\u4e00\u4e2a\u5355\u4e00\u8bed\u8a00\uff0c\u5df2\u7ecf\u4e0d\u518d\u7528\u4e86\u3002 Json \u7528Jackson\u7684ObjectMapper\u628a\u4e00\u4e2a\u5bf9\u8c61\u5e8f\u5217\u5316\u6210Jason\uff0c\u7136\u540e\u518d\u53cd\u5e8f\u5217\u5316. Avro Kafka\u7684\u9ed8\u8ba4\u65b9\u5f0f\u3002\u9700\u8981\u63d0\u524d\u9884\u5b9a\u4e49\u597dmodel\uff0c\u5e8f\u5217\u5316\uff0c\u53cd\u5e8f\u5217\u5316\u7684\u65f6\u5019\u90fd\u9700\u8981\u7528\u90a3\u4e2amodel\u3002model\u66f4\u65b0\u7684\u65f6\u5019\u6211\u8bb0\u5f97\u5e76\u4e0d\u50cf\u60f3\u8c61\u7684\u90a3\u4e48\u7b80\u5355\u3002\u6bd4\u5982\u8bf4\u52a0\u4e00\u4e2a\u5b57\u6bb5\u3002\u6211\u4eec\u5fc5\u987basdl\u5b9a\u4e49NoAE\u7684\u6240\u6709\u7684\u6d88\u606f\u90fd\u6709\u81ea\u5df1\u5bf9\u5e94\u7684Class\uff0cSerializer\u548cDeseriallizer\uff0c\u90fd\u662f\u57fa\u4e8eAvro\u7684\u3002\u6bd4\u5982 NotificationInstanceDeserializer NotificationInstanceSerializer AvroSerializer.java (This copied from GenericBinarySerializer.java in CDC-model) \u800cDACO\u7684Serializer\u548cDeserializer\u90fd\u662f\u7528\u4e00\u4e2a JsonSerializer.\u5176\u5b9e\u5c31\u662fJakson\u7684ObjectMapper\u7684\u5b9e\u73b0\u3002\u4e0d\u8fc7\u4f20\u8f93\u7684\u90fd\u662f\u4e8c\u8fdb\u5236\uff08\u4f46\u662f\u5176\u5b9e\u5c31\u662fjson\u4e13\u7a0bbytes\u800c\u5df2\uff0cKafka\u7684\u6240\u6709\u6d88\u606f\u90fd\u662fbytes\uff09\u3002DataModel\u5fc5\u987b\u662fJsonNode\u7684\u5b9e\u73b0(\u5176\u5b9e\u4e0d\u9700\u8981\uff0cobjectMapper.writeValueAsBytes\u8fd9\u4e2a\u65b9\u6cd5\u5c31\u662f\u63a5\u53d7Object)\u3002\u6ca1\u6709\u8bed\u8a00\u72ec\u7acb\u7684\u8868\u8fbe\u3002\u3002\u7ed1\u5b9aJackson. \u8fd9\u4e2a\u5c31\u662f\u5077\u61d2\u7684\u505a\u6cd5\u3002\u4e0d\u9700\u8981\u5b9a\u4e49avil\u6587\u4ef6\uff0c\u53ea\u9700\u8981\u5199\u4e00\u4e2a\u7ee7\u627fJsonNode\u7684bean\u5c31\u597d\u3002\u4e3b\u8981\u662f\u516c\u53f8\u6ca1\u6709\u4e00\u4e2a\u7edf\u4e00\u7684\u6807\u51c6\uff0c\u5927\u5bb6\u90fd\u9009\u62e9\u81ea\u5df1\u6700convinience\u7684\u65b9\u6cd5\u53bb\u505a\u3002\u4ee5\u540e\u5982\u679c\u8981\u6539\u683c\u5f0f\u5c31\u8fd8\u633a\u9ebb\u70e6\u3002 JsonSerializer.java KafkaJsonDeserializer.java. \u6240\u4ee5Kafka consumer\u90fd\u662f\u62ff\u7684JsonNode,\u9700\u8981\u518d\u8f6c\u4e3a\u5b50\u7c7b\u3002\u6bd4\u5982NotificationMessage.java Protocal Buffer gRPC\u7684\u9ed8\u8ba4\u65b9\u5f0f\u3002\u548cAvro\u7c7b\u4f3c\u3002\u5c3a\u5bf8\u90fd\u6bd4\u8f83\u5c0f\u3002","og_url":"https:\/\/liangqi.org\/?p=205","og_site_name":"Liangqi\u2018s Technical Journey","article_published_time":"2022-02-12T23:24:00+00:00","article_modified_time":"2022-02-12T23:24:01+00:00","author":"liangqi","twitter_card":"summary_large_image","twitter_misc":{"Written by":"liangqi","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/liangqi.org\/?p=205#article","isPartOf":{"@id":"https:\/\/liangqi.org\/?p=205"},"author":{"name":"liangqi","@id":"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3"},"headline":"\u5bf9\u8c61\u7684\u5e8f\u5217\u5316","datePublished":"2022-02-12T23:24:00+00:00","dateModified":"2022-02-12T23:24:01+00:00","mainEntityOfPage":{"@id":"https:\/\/liangqi.org\/?p=205"},"wordCount":47,"commentCount":0,"publisher":{"@id":"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3"},"articleSection":["\u5de5\u5177","\u6280\u672f"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/liangqi.org\/?p=205#respond"]}]},{"@type":"WebPage","@id":"https:\/\/liangqi.org\/?p=205","url":"https:\/\/liangqi.org\/?p=205","name":"\u5bf9\u8c61\u7684\u5e8f\u5217\u5316 - Liangqi\u2018s Technical Journey","isPartOf":{"@id":"https:\/\/liangqi.org\/#website"},"datePublished":"2022-02-12T23:24:00+00:00","dateModified":"2022-02-12T23:24:01+00:00","breadcrumb":{"@id":"https:\/\/liangqi.org\/?p=205#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/liangqi.org\/?p=205"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/liangqi.org\/?p=205#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/liangqi.org\/"},{"@type":"ListItem","position":2,"name":"\u5bf9\u8c61\u7684\u5e8f\u5217\u5316"}]},{"@type":"WebSite","@id":"https:\/\/liangqi.org\/#website","url":"https:\/\/liangqi.org\/","name":"Liangqi\u2018s Technical Journey","description":"Chasing Excellence; Enjoy life.","publisher":{"@id":"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/liangqi.org\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3","name":"liangqi","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/liangqi.org\/#\/schema\/person\/image\/","url":"https:\/\/liangqi.org\/wp-content\/uploads\/2022\/01\/P1100089-3-scaled.jpg","contentUrl":"https:\/\/liangqi.org\/wp-content\/uploads\/2022\/01\/P1100089-3-scaled.jpg","width":2560,"height":1920,"caption":"liangqi"},"logo":{"@id":"https:\/\/liangqi.org\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/liangqi.org"],"url":"https:\/\/liangqi.org\/?author=1"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/posts\/205","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/liangqi.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=205"}],"version-history":[{"count":12,"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/posts\/205\/revisions"}],"predecessor-version":[{"id":217,"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/posts\/205\/revisions\/217"}],"wp:attachment":[{"href":"https:\/\/liangqi.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/liangqi.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/liangqi.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}