You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by ji...@apache.org on 2022/09/13 12:36:13 UTC

[rocketmq] branch develop updated: [ISSUE #4941] Producer example add the default NamesrvAddr (#5032)

This is an automated email from the ASF dual-hosted git repository.

jinrongtong pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git


The following commit(s) were added to refs/heads/develop by this push:
     new 8c22bcad4 [ISSUE #4941] Producer example add the default NamesrvAddr (#5032)
8c22bcad4 is described below

commit 8c22bcad481f180c64295131997063cd3ed65c6c
Author: mxsm <lj...@gmail.com>
AuthorDate: Tue Sep 13 20:36:06 2022 +0800

    [ISSUE #4941] Producer example add the default NamesrvAddr (#5032)
---
 .../apache/rocketmq/example/simple/Producer.java   | 25 ++++++++++++----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/example/src/main/java/org/apache/rocketmq/example/simple/Producer.java b/example/src/main/java/org/apache/rocketmq/example/simple/Producer.java
index 448f8ee9f..2b838a2eb 100644
--- a/example/src/main/java/org/apache/rocketmq/example/simple/Producer.java
+++ b/example/src/main/java/org/apache/rocketmq/example/simple/Producer.java
@@ -23,22 +23,25 @@ import org.apache.rocketmq.common.message.Message;
 import org.apache.rocketmq.remoting.common.RemotingHelper;
 
 public class Producer {
+
+    public static final String PRODUCER_GROUP = "ProducerGroupName";
+    public static final String DEFAULT_NAMESRVADDR = "127.0.0.1:9876";
+    public static final String TOPIC = "TopicTest";
+    public static final String TAG = "TagA";
+
     public static void main(String[] args) throws MQClientException, InterruptedException {
 
-        DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName");
-        producer.start();
+        DefaultMQProducer producer = new DefaultMQProducer(PRODUCER_GROUP);
 
+        // Uncomment the following line while debugging, namesrvAddr should be set to your local address
+        //producer.setNamesrvAddr(DEFAULT_NAMESRVADDR);
+
+        producer.start();
         for (int i = 0; i < 128; i++)
             try {
-                {
-                    Message msg = new Message("TopicTest",
-                        "TagA",
-                        "OrderID188",
-                        "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET));
-                    SendResult sendResult = producer.send(msg);
-                    System.out.printf("%s%n", sendResult);
-                }
-
+                Message msg = new Message(TOPIC, TAG, "OrderID188", "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET));
+                SendResult sendResult = producer.send(msg);
+                System.out.printf("%s%n", sendResult);
             } catch (Exception e) {
                 e.printStackTrace();
             }