From 756f3340969a9de2225d292d9518d1175047e082 Mon Sep 17 00:00:00 2001 From: Huo Linhe Date: Mon, 15 Aug 2022 18:49:15 +0800 Subject: [PATCH] docs: fix subscribe topics doc style --- docs/zh/07-develop/07-tmq.mdx | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/docs/zh/07-develop/07-tmq.mdx b/docs/zh/07-develop/07-tmq.mdx index 8ab155948b..f36f76fd85 100644 --- a/docs/zh/07-develop/07-tmq.mdx +++ b/docs/zh/07-develop/07-tmq.mdx @@ -238,6 +238,9 @@ public class MetersDeserializer extends ReferenceDeserializer { 一个 consumer 支持同时订阅多个 topic。 + + + ```c // 创建订阅 topics 列表 tmq_list_t* topicList = tmq_list_new(); @@ -248,8 +251,23 @@ tmq_list_destroy(topicList); ``` + + + +```java +List topics = new ArrayList<>(); +topics.add("tmq_topic"); +consumer.subscribe(topics); +``` + + + + + ## 消费 +以下代码展示了不同语言下如何对 TMQ 消息进行消费。 + @@ -267,10 +285,6 @@ while (running) { ```java -List topics = new ArrayList<>(); -topics.add("tmq_topic"); -consumer.subscribe(topics); - while(running){ ConsumerRecords meters = consumer.poll(Duration.ofMillis(100)); for (Meters meter : meters) { @@ -284,6 +298,8 @@ while(running){ ## 结束消费 +消费结束后,应当取消订阅。 + -- GitLab