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 2022/05/19 06:12:59 UTC

[GitHub] [rocketmq] odbozhou commented on a diff in pull request #4324: [ISSUE #4323] Rpc example add the default NamesrvAddr

odbozhou commented on code in PR #4324:
URL: https://github.com/apache/rocketmq/pull/4324#discussion_r876639381


##########
example/src/main/java/org/apache/rocketmq/example/rpc/RequestProducer.java:
##########
@@ -23,23 +23,28 @@
 import org.apache.rocketmq.remoting.common.RemotingHelper;
 
 public class RequestProducer {
+    public static final String PRODUCER_GROUP = "please_rename_unique_group_name";
+    public static final String DEFAULT_NAMESRVADDR = "127.0.0.1:9876";
+    public static final String TOPIC = "RequestTopic";
+    public static final String TAG = "Tag";
+    public static final long TTL = 3000L;
+
     public static void main(String[] args) throws MQClientException, InterruptedException {
-        String producerGroup = "please_rename_unique_group_name";
-        String topic = "RequestTopic";
-        long ttl = 3000;
 
-        DefaultMQProducer producer = new DefaultMQProducer(producerGroup);
+        DefaultMQProducer producer = new DefaultMQProducer(PRODUCER_GROUP);
+        //You need to set namesrvAddr to the address of the local namesrv
+        producer.setNamesrvAddr(DEFAULT_NAMESRVADDR);

Review Comment:
   May cause the official website quick start to set namesrv through the command line to fail.
   
   ![image](https://user-images.githubusercontent.com/14222167/169222247-c94c3a0d-2a74-4a72-9253-afdaf04e313c.png)
   



##########
example/src/main/java/org/apache/rocketmq/example/rpc/AsyncRequestProducer.java:
##########
@@ -28,36 +28,40 @@
 public class AsyncRequestProducer {
     private static final InternalLogger log = ClientLogger.getLog();
 
+    public static final String PRODUCER_GROUP = "please_rename_unique_group_name";
+    public static final String DEFAULT_NAMESRVADDR = "127.0.0.1:9876";
+    public static final String TOPIC = "RequestTopic";
+    public static final String TAG = "Tag";
+    public static final long TTL = 3000L;
+
     public static void main(String[] args) throws MQClientException, InterruptedException {
-        String producerGroup = "please_rename_unique_group_name";
-        String topic = "RequestTopic";
-        long ttl = 3000;
 
-        DefaultMQProducer producer = new DefaultMQProducer(producerGroup);
+        DefaultMQProducer producer = new DefaultMQProducer(PRODUCER_GROUP);
+        //You need to set namesrvAddr to the address of the local namesrv
+        producer.setNamesrvAddr(DEFAULT_NAMESRVADDR);

Review Comment:
   May cause the official website quick start to set namesrv through the command line to fail.
   
   ![image](https://user-images.githubusercontent.com/14222167/169222247-c94c3a0d-2a74-4a72-9253-afdaf04e313c.png)
   



##########
example/src/main/java/org/apache/rocketmq/example/rpc/ResponseConsumer.java:
##########
@@ -33,46 +31,50 @@
 import org.apache.rocketmq.remoting.exception.RemotingException;
 
 public class ResponseConsumer {
+
+    public static final String PRODUCER_GROUP = "please_rename_unique_group_name";
+    public static final String CONSUMER_GROUP = "please_rename_unique_group_name";
+    public static final String DEFAULT_NAMESRVADDR = "127.0.0.1:9876";
+    public static final String TOPIC = "RequestTopic";
+
     public static void main(String[] args) throws InterruptedException, MQClientException {
-        String producerGroup = "please_rename_unique_group_name";
-        String consumerGroup = "please_rename_unique_group_name";
-        String topic = "RequestTopic";
 
         // create a producer to send reply message
-        DefaultMQProducer replyProducer = new DefaultMQProducer(producerGroup);
+        DefaultMQProducer replyProducer = new DefaultMQProducer(PRODUCER_GROUP);
+        // You need to set namesrvAddr to the address of the local namesrv
+        replyProducer.setNamesrvAddr(DEFAULT_NAMESRVADDR);

Review Comment:
   May cause the official website quick start to set namesrv through the command line to fail.
   
   ![image](https://user-images.githubusercontent.com/14222167/169222247-c94c3a0d-2a74-4a72-9253-afdaf04e313c.png)
   



##########
example/src/main/java/org/apache/rocketmq/example/rpc/ResponseConsumer.java:
##########
@@ -33,46 +31,50 @@
 import org.apache.rocketmq.remoting.exception.RemotingException;
 
 public class ResponseConsumer {
+
+    public static final String PRODUCER_GROUP = "please_rename_unique_group_name";
+    public static final String CONSUMER_GROUP = "please_rename_unique_group_name";
+    public static final String DEFAULT_NAMESRVADDR = "127.0.0.1:9876";
+    public static final String TOPIC = "RequestTopic";
+
     public static void main(String[] args) throws InterruptedException, MQClientException {
-        String producerGroup = "please_rename_unique_group_name";
-        String consumerGroup = "please_rename_unique_group_name";
-        String topic = "RequestTopic";
 
         // create a producer to send reply message
-        DefaultMQProducer replyProducer = new DefaultMQProducer(producerGroup);
+        DefaultMQProducer replyProducer = new DefaultMQProducer(PRODUCER_GROUP);
+        // You need to set namesrvAddr to the address of the local namesrv
+        replyProducer.setNamesrvAddr(DEFAULT_NAMESRVADDR);
         replyProducer.start();
 
         // create consumer
-        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(consumerGroup);
+        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(CONSUMER_GROUP);
+        // You need to set namesrvAddr to the address of the local namesrv
+        consumer.setNamesrvAddr(DEFAULT_NAMESRVADDR);
         consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET);

Review Comment:
   May cause the official website quick start to set namesrv through the command line to fail.
   
   ![image](https://user-images.githubusercontent.com/14222167/169222247-c94c3a0d-2a74-4a72-9253-afdaf04e313c.png)
   



-- 
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