You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2021/07/21 11:12:26 UTC

[GitHub] [rocketmq] caigy commented on a change in pull request #3072: [ISSUES #3057]Add Chinese version of Example_Simple.md

caigy commented on a change in pull request #3072:
URL: https://github.com/apache/rocketmq/pull/3072#discussion_r673878761



##########
File path: docs/cn/Example_Simple_cn.md
##########
@@ -0,0 +1,136 @@
+# Basic Sample 
+------
+基本示例中提供了以下两个功能
+* RocketMQ可用于以三种方式发送消息:可靠的同步、可靠的异步和单向传输。前两种消息类型是可靠的,因为无论它们是否成功发送都有响应。
+* RocketMQ可以用来消费消息。
+### 1 添加依赖
+maven:
+``` java
+<dependency>
+  <groupId>org.apache.rocketmq</groupId>
+  <artifactId>rocketmq-client</artifactId>
+  <version>4.3.0</version>
+</dependency>
+```
+gradle: 
+``` java 
+compile 'org.apache.rocketmq:rocketmq-client:4.3.0'
+```
+### 2 发送消息
+##### 2.1 使用Producer发送同步消息
+可靠的同步传输被广泛应用于各种场景,如重要的通知消息、短消息通知等。
+``` java
+public class SyncProducer {
+  public static void main(String[] args) throws Exception {
+    // Instantiate with a producer group name
+    DefaultMQProducer producer = new DefaultMQProducer("please_rename_unique_group_name");
+    // Specify name server addresses
+    producer.setNamesrvAddr("localhost:9876");
+    // Launch the producer instance
+    producer.start();
+    for (int i = 0; i < 100; i++) {
+      // Create a message instance with specifying topic, tag and message body
+      Message msg = new Message("TopicTest" /* Topic */,
+        "TagA" /* Tag */,
+        ("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET) /* Message body */
+        );
+      // Send message to one of brokers
+      SendResult sendResult = producer.send(msg);
+      // Check whether the message has been delivered by the callback of sendResult
+      System.out.printf("%s%n", sendResult);
+    }
+    // Shut down once the producer instance is not longer in use
+    producer.shutdown();
+  }
+}
+```
+##### 2.2 发送异步消息
+异步传输通常用于响应时间敏感的业务场景。这意味着发送方无法等待代理的响应太长时间。

Review comment:
       Not necessary to translate `broker`, eg. "发送方无法长时间等待 Broker 的响应"

##########
File path: docs/cn/Example_Simple_cn.md
##########
@@ -0,0 +1,136 @@
+# Basic Sample 
+------
+基本示例中提供了以下两个功能
+* RocketMQ可用于以三种方式发送消息:可靠的同步、可靠的异步和单向传输。前两种消息类型是可靠的,因为无论它们是否成功发送都有响应。
+* RocketMQ可以用来消费消息。
+### 1 添加依赖
+maven:
+``` java
+<dependency>
+  <groupId>org.apache.rocketmq</groupId>
+  <artifactId>rocketmq-client</artifactId>
+  <version>4.3.0</version>
+</dependency>
+```
+gradle: 
+``` java 
+compile 'org.apache.rocketmq:rocketmq-client:4.3.0'
+```
+### 2 发送消息
+##### 2.1 使用Producer发送同步消息
+可靠的同步传输被广泛应用于各种场景,如重要的通知消息、短消息通知等。
+``` java
+public class SyncProducer {
+  public static void main(String[] args) throws Exception {
+    // Instantiate with a producer group name
+    DefaultMQProducer producer = new DefaultMQProducer("please_rename_unique_group_name");
+    // Specify name server addresses
+    producer.setNamesrvAddr("localhost:9876");
+    // Launch the producer instance
+    producer.start();
+    for (int i = 0; i < 100; i++) {
+      // Create a message instance with specifying topic, tag and message body
+      Message msg = new Message("TopicTest" /* Topic */,
+        "TagA" /* Tag */,
+        ("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET) /* Message body */
+        );
+      // Send message to one of brokers
+      SendResult sendResult = producer.send(msg);
+      // Check whether the message has been delivered by the callback of sendResult
+      System.out.printf("%s%n", sendResult);
+    }
+    // Shut down once the producer instance is not longer in use
+    producer.shutdown();
+  }
+}
+```
+##### 2.2 发送异步消息
+异步传输通常用于响应时间敏感的业务场景。这意味着发送方无法等待代理的响应太长时间。
+``` java
+public class AsyncProducer {
+  public static void main(String[] args) throws Exception {
+    // Instantiate with a producer group name
+    DefaultMQProducer producer = new DefaultMQProducer("please_rename_unique_group_name");
+    // Specify name server addresses
+    producer.setNamesrvAddr("localhost:9876");
+    // Launch the producer instance
+    producer.start();
+    producer.setRetryTimesWhenSendAsyncFailed(0);
+    for (int i = 0; i < 100; i++) {
+      final int index = i;
+      // Create a message instance with specifying topic, tag and message body
+      Message msg = new Message("TopicTest",
+        "TagA",
+        "OrderID188",
+        "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET));
+      // SendCallback: receive the callback of the asynchronous return result.
+      producer.send(msg, new SendCallback() {
+        @Override
+        public void onSuccess(SendResult sendResult) {
+          System.out.printf("%-10d OK %s %n", index,
+            sendResult.getMsgId());
+        }
+        @Override
+        public void onException(Throwable e) {
+          System.out.printf("%-10d Exception %s %n", index, e);
+          e.printStackTrace();
+        }
+      });
+    }
+    // Shut down once the producer instance is not longer in use
+    producer.shutdown();
+  }
+}
+```
+##### 2.3 以单向模式发送消息
+单向传输用于需要中等可靠性的情况,如日志收集。

Review comment:
       Would "单向传输用于可靠性要求并不高的场景" be better?

##########
File path: docs/cn/Example_Simple_cn.md
##########
@@ -0,0 +1,136 @@
+# Basic Sample 
+------
+基本示例中提供了以下两个功能
+* RocketMQ可用于以三种方式发送消息:可靠的同步、可靠的异步和单向传输。前两种消息类型是可靠的,因为无论它们是否成功发送都有响应。
+* RocketMQ可以用来消费消息。
+### 1 添加依赖
+maven:
+``` java
+<dependency>
+  <groupId>org.apache.rocketmq</groupId>
+  <artifactId>rocketmq-client</artifactId>
+  <version>4.3.0</version>
+</dependency>
+```
+gradle: 
+``` java 
+compile 'org.apache.rocketmq:rocketmq-client:4.3.0'
+```
+### 2 发送消息
+##### 2.1 使用Producer发送同步消息
+可靠的同步传输被广泛应用于各种场景,如重要的通知消息、短消息通知等。

Review comment:
       More appropriate to translate SMS into '短信'




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org