未验证 提交 162dd3cd 编写于 作者: sangshuduo's avatar sangshuduo 提交者: GitHub

docs: update cloud tmq sample code (#16430)

* docs: update rust cloud tmq sample code

* docs: update rust tmq sample code

* docs: comment off other languages code
上级 58821426
......@@ -9,7 +9,6 @@ import TabItem from "@theme/TabItem";
import Java from "./_sub_java.mdx";
import Python from "./_sub_python.mdx";
import Go from "./_sub_go.mdx";
import Rust from "./_sub_rust.mdx";
import Node from "./_sub_node.mdx";
import CSharp from "./_sub_cs.mdx";
import CDemo from "./_sub_c.mdx";
......@@ -92,6 +91,8 @@ The method of specifying these parameters depends on the language used:
<Tabs defaultValue="java" groupId="lang">
<TabItem value="c" label="C">
Will be available soon
<!-- temporarily comment off
```c
/* Create consumer groups on demand (group.id) and enable automatic commits (enable.auto.commit),
an automatic commit interval (auto.commit.interval.ms), and a username (td.connect.user) and password (td.connect.pass) */
......@@ -109,10 +110,13 @@ tmq_conf_set_auto_commit_cb(conf, tmq_commit_cb_print, NULL);
tmq_t* tmq = tmq_consumer_new(conf, NULL, 0);
tmq_conf_destroy(conf);
```
-->
</TabItem>
<TabItem value="java" label="Java">
Will be available soon
<!-- temporarily comment off
Java programs use the following parameters:
| Parameter | Type | Description | Remarks |
......@@ -143,11 +147,14 @@ import com.taosdata.jdbc.tmq.ReferenceDeserializer;
public class MetersDeserializer extends ReferenceDeserializer<Meters> {
}
```
-->
</TabItem>
<TabItem label="Go" value="Go">
Will be available soon
<!-- temporarily comment off
```go
config := tmq.NewConfig()
defer config.Destroy()
......@@ -194,13 +201,14 @@ if err != nil {
panic(err)
}
```
-->
</TabItem>
<TabItem label="Rust" value="Rust">
```rust
let mut dsn: Dsn = "taos://".parse()?;
let mut dsn = std::env::var("TDENGINE_CLOUD_DSN").parse()?;
dsn.set("group.id", "group1");
dsn.set("client.id", "test");
dsn.set("auto.offset.reset", "earliest");
......@@ -214,6 +222,8 @@ let mut consumer = tmq.build()?;
<TabItem value="Python" label="Python">
Will be available soon
<!-- temporarily comment off
Python programs use the following parameters:
| Parameter | Type | Description | Remarks |
......@@ -233,9 +243,12 @@ Python programs use the following parameters:
| `timeout` | int | Consumer pull timeout | |
</TabItem>
-->
<TabItem label="Node.JS" value="Node.JS">
Will be available soon
<!-- temporarily comment off
```js
// Create consumer groups on demand (group.id) and enable automatic commits (enable.auto.commit),
// an automatic commit interval (auto.commit.interval.ms), and a username (td.connect.user) and password (td.connect.pass)
......@@ -252,11 +265,14 @@ let consumer = taos.consumer({
'td.connect.port','6030'
});
```
-->
</TabItem>
<TabItem value="C#" label="C#">
Will be available soon
<!-- temporarily comment off
```csharp
using TDengineTMQ;
......@@ -278,6 +294,7 @@ var cfg = new ConsumerConfig
var consumer = new ConsumerBuilder(cfg).Build();
```
-->
</TabItem>
......@@ -292,6 +309,8 @@ A single consumer can subscribe to multiple topics.
<Tabs defaultValue="java" groupId="lang">
<TabItem value="c" label="C">
Will be available soon
<!-- temporarily comment off
```c
// Create a list of subscribed topics
tmq_list_t* topicList = tmq_list_new();
......@@ -301,19 +320,25 @@ tmq_subscribe(tmq, topicList);
tmq_list_destroy(topicList);
```
-->
</TabItem>
<TabItem value="java" label="Java">
Will be available soon
<!-- temporarily comment off
```java
List<String> topics = new ArrayList<>();
topics.add("tmq_topic");
consumer.subscribe(topics);
```
-->
</TabItem>
<TabItem value="Go" label="Go">
Will be available soon
<!-- temporarily comment off
```go
consumer, err := tmq.NewConsumer(config)
if err != nil {
......@@ -324,6 +349,7 @@ if err != nil {
panic(err)
}
```
-->
</TabItem>
<TabItem value="Rust" label="Rust">
......@@ -336,14 +362,19 @@ consumer.subscribe(["tmq_meters"]).await?;
<TabItem value="Python" label="Python">
Will be available soon
<!-- temporarily comment off
```python
consumer = TaosConsumer('topic_ctb_column', group_id='vg2')
```
-->
</TabItem>
<TabItem label="Node.JS" value="Node.JS">
Will be available soon
<!-- temporarily comment off
```js
// Create a list of subscribed topics
let topics = ['topic_test']
......@@ -351,11 +382,14 @@ let topics = ['topic_test']
// Enable subscription
consumer.subscribe(topics);
```
-->
</TabItem>
<TabItem value="C#" label="C#">
Will be available soon
<!-- temporarily comment off
```csharp
// Create a list of subscribed topics
List<String> topics = new List<string>();
......@@ -363,6 +397,7 @@ topics.add("tmq_topic");
// Enable subscription
consumer.Subscribe(topics);
```
-->
</TabItem>
......@@ -375,6 +410,8 @@ The following code demonstrates how to consume the messages in a queue.
<Tabs defaultValue="java" groupId="lang">
<TabItem value="c" label="C">
Will be available soon
<!-- temporarily comment off
```c
## Consume data
while (running) {
......@@ -384,10 +421,13 @@ while (running) {
```
The `while` loop obtains a message each time it calls `tmq_consumer_poll()`. This message is exactly the same as the result returned by a query, and the same deserialization API can be used on it.
-->
</TabItem>
<TabItem value="java" label="Java">
Will be available soon
<!-- temporarily comment off
```java
while(running){
ConsumerRecords<Meters> meters = consumer.poll(Duration.ofMillis(100));
......@@ -396,11 +436,14 @@ while(running){
}
}
```
-->
</TabItem>
<TabItem value="Go" label="Go">
Will be available soon
<!-- temporarily comment off
```go
for {
result, err := consumer.Poll(time.Second)
......@@ -412,6 +455,7 @@ for {
consumer.FreeMessage(result.Message)
}
```
-->
</TabItem>
......@@ -450,17 +494,22 @@ for {
</TabItem>
<TabItem value="Python" label="Python">
Will be available soon
<!-- temporarily comment off
```python
for msg in consumer:
for row in msg:
print(row)
```
-->
</TabItem>
<TabItem label="Node.JS" value="Node.JS">
Will be available soon
<!-- temporarily comment off
```js
while(true){
msg = consumer.consume(200);
......@@ -470,11 +519,14 @@ while(true){
console.log(msg.fields)
}
```
-->
</TabItem>
<TabItem value="C#" label="C#">
Will be available soon
<!-- temporarily comment off
```csharp
## Consume data
while (true)
......@@ -485,6 +537,7 @@ while (true)
consumer.Commit(consumerRes);
}
```
-->
</TabItem>
......@@ -496,6 +549,8 @@ A single consumer can subscribe to multiple topics.
<Tabs defaultValue="java" groupId="lang">
<TabItem value="c" label="C">
Will be available soon
<!-- temporarily comment off
```c
// Create a list of subscribed topics
......@@ -506,19 +561,25 @@ tmq_subscribe(tmq, topicList);
tmq_list_destroy(topicList);
```
-->
</TabItem>
<TabItem value="java" label="Java">
Will be available soon
<!-- temporarily comment off
```java
List<String> topics = new ArrayList<>();
topics.add("tmq_topic");
consumer.subscribe(topics);
```
-->
</TabItem>
<TabItem value="Go" label="Go">
Will be available soon
<!-- temporarily comment off
```go
consumer, err := tmq.NewConsumer(config)
if err != nil {
......@@ -529,6 +590,7 @@ if err != nil {
panic(err)
}
```
-->
</TabItem>
<TabItem value="Rust" label="Rust">
......@@ -540,13 +602,18 @@ consumer.subscribe(["tmq_meters"]).await?;
</TabItem>
<TabItem value="Python" label="Python">
Will be available soon
<!-- temporarily comment off
```python
consumer = TaosConsumer('topic_ctb_column', group_id='vg2')
```
-->
</TabItem>
Will be available soon
<!-- temporarily comment off
<TabItem label="Node.JS" value="Node.JS">
```js
......@@ -556,10 +623,13 @@ let topics = ['topic_test']
// Enable subscription
consumer.subscribe(topics);
```
-->
</TabItem>
<TabItem value="C#" label="C#">
Will be available soon
<!-- temporarily comment off
```csharp
// Create a list of subscribed topics
......@@ -568,6 +638,7 @@ topics.add("tmq_topic");
// Enable subscription
consumer.Subscribe(topics);
```
-->
</TabItem>
......@@ -581,6 +652,8 @@ The following code demonstrates how to consume the messages in a queue.
<Tabs defaultValue="java" groupId="lang">
<TabItem value="c" label="C">
Will be available soon
<!-- temporarily comment off
```c
## Consume data
while (running) {
......@@ -588,12 +661,15 @@ while (running) {
msg_process(msg);
}
```
-->
The `while` loop obtains a message each time it calls `tmq_consumer_poll()`. This message is exactly the same as the result returned by a query, and the same deserialization API can be used on it.
</TabItem>
<TabItem value="java" label="Java">
Will be available soon
<!-- temporarily comment off
```java
while(running){
ConsumerRecords<Meters> meters = consumer.poll(Duration.ofMillis(100));
......@@ -602,11 +678,14 @@ while(running){
}
}
```
-->
</TabItem>
<TabItem value="Go" label="Go">
Will be available soon
<!-- temporarily comment off
```go
for {
result, err := consumer.Poll(time.Second)
......@@ -618,6 +697,7 @@ for {
consumer.FreeMessage(result.Message)
}
```
-->
</TabItem>
......@@ -656,17 +736,22 @@ for {
</TabItem>
<TabItem value="Python" label="Python">
Will be available soon
<!-- temporarily comment off
```python
for msg in consumer:
for row in msg:
print(row)
```
-->
</TabItem>
<TabItem label="Node.JS" value="Node.JS">
Will be available soon
<!-- temporarily comment off
```js
while(true){
msg = consumer.consume(200);
......@@ -676,11 +761,14 @@ while(true){
console.log(msg.fields)
}
```
-->
</TabItem>
<TabItem value="C#" label="C#">
Will be available soon
<!-- temporarily comment off
```csharp
## Consume data
while (true)
......@@ -692,6 +780,7 @@ while (true)
}
```
-->
</TabItem>
</Tabs>
......@@ -703,6 +792,8 @@ After message consumption is finished, the consumer is unsubscribed.
<Tabs defaultValue="java" groupId="lang">
<TabItem value="c" label="C">
Will be available soon
<!-- temporarily comment off
```c
/* Unsubscribe */
tmq_unsubscribe(tmq);
......@@ -711,9 +802,12 @@ tmq_unsubscribe(tmq);
tmq_consumer_close(tmq);
```
-->
</TabItem>
<TabItem value="java" label="Java">
Will be available soon
<!-- temporarily comment off
```java
/* Unsubscribe */
consumer.unsubscribe();
......@@ -721,14 +815,18 @@ consumer.unsubscribe();
/* Close consumer */
consumer.close();
```
-->
</TabItem>
<TabItem value="Go" label="Go">
Will be available soon
<!-- temporarily comment off
```go
consumer.Close()
```
-->
</TabItem>
......@@ -742,24 +840,32 @@ consumer.unsubscribe().await;
<TabItem value="Python" label="Python">
Will be available soon
<!-- temporarily comment off
```py
# Unsubscribe
consumer.unsubscribe()
# Close consumer
consumer.close()
```
-->
</TabItem>
<TabItem label="Node.JS" value="Node.JS">
Will be available soon
<!-- temporarily comment off
```js
consumer.unsubscribe();
consumer.close();
```
-->
</TabItem>
<TabItem value="C#" label="C#">
Will be available soon
<!-- temporarily comment off
```csharp
// Unsubscribe
......@@ -768,6 +874,7 @@ consumer.Unsubscribe();
// Close consumer
consumer.Close();
```
-->
</TabItem>
......@@ -780,6 +887,8 @@ After message consumption is finished, the consumer is unsubscribed.
<Tabs defaultValue="java" groupId="lang">
<TabItem value="c" label="C">
Will be available soon
<!-- temporarily comment off
```c
/* Unsubscribe */
......@@ -788,10 +897,13 @@ tmq_unsubscribe(tmq);
/* Close consumer object */
tmq_consumer_close(tmq);
```
-->
</TabItem>
<TabItem value="java" label="Java">
Will be available soon
<!-- temporarily comment off
```java
/* Unsubscribe */
consumer.unsubscribe();
......@@ -799,14 +911,18 @@ consumer.unsubscribe();
/* Close consumer */
consumer.close();
```
-->
</TabItem>
<TabItem value="Go" label="Go">
Will be available soon
<!-- temporarily comment off
```go
consumer.Close()
```
-->
</TabItem>
......@@ -819,6 +935,8 @@ consumer.unsubscribe().await;
</TabItem>
<TabItem value="Python" label="Python">
Will be available soon
<!-- temporarily comment off
```py
# Unsubscribe
......@@ -826,18 +944,24 @@ consumer.unsubscribe()
# Close consumer
consumer.close()
```
-->
</TabItem>
<TabItem label="Node.JS" value="Node.JS">
Will be available soon
<!-- temporarily comment off
```js
consumer.unsubscribe();
consumer.close();
```
-->
</TabItem>
<TabItem value="C#" label="C#">
Will be available soon
<!-- temporarily comment off
```csharp
// Unsubscribe
......@@ -846,6 +970,7 @@ consumer.Unsubscribe();
// Close consumer
consumer.Close();
```
-->
</TabItem>
......@@ -876,4 +1001,4 @@ SHOW TOPICS;
```sql
SHOW CONSUMERS;
```
\ No newline at end of file
```
......@@ -35,7 +35,7 @@ async fn prepare(taos: Taos) -> anyhow::Result<()> {
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let dsn = "taosws://localhost:6030";
let mut dsn = std::env::var("TDENGINE_CLOUD_DSN").parse()?;
let builder = TaosBuilder::from_dsn(dsn)?;
let taos = builder.build()?;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册