rocketmq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jinrongt...@apache.org
Subject [rocketmq-spring] branch master updated: [ISSUE #268] RocketMQMessageListener nameServer not work (#301)
Date Wed, 28 Oct 2020 01:49:33 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new 78dd2d9  [ISSUE #268] RocketMQMessageListener nameServer not work (#301)
78dd2d9 is described below

commit 78dd2d9d3ca2b3f225bbb0fb50c382d1f9121b45
Author: zhangjidi2016 <zhangjidi_yewu@cmss.chinamobile.com>
AuthorDate: Wed Oct 28 09:49:26 2020 +0800

    [ISSUE #268] RocketMQMessageListener nameServer not work (#301)
    
    * [ISSUE #268] RocketMQMessageListener nameServer not work
    
    * Use the separator '@'
---
 .../spring/support/DefaultRocketMQListenerContainer.java         | 2 ++
 .../java/org/apache/rocketmq/spring/support/RocketMQUtil.java    | 9 +++++++++
 .../org/apache/rocketmq/spring/support/RocketMQUtilTest.java     | 7 +++++++
 3 files changed, 18 insertions(+)

diff --git a/rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/support/DefaultRocketMQListenerContainer.java
b/rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/support/DefaultRocketMQListenerContainer.java
index 89b9b91..952b4e1 100644
--- a/rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/support/DefaultRocketMQListenerContainer.java
+++ b/rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/support/DefaultRocketMQListenerContainer.java
@@ -561,6 +561,8 @@ public class DefaultRocketMQListenerContainer implements InitializingBean,
                 this.applicationContext.getEnvironment().
                     resolveRequiredPlaceholders(this.rocketMQMessageListener.customizedTraceTopic()));
         }
+        
+        consumer.setInstanceName(RocketMQUtil.getInstanceName(nameServer));
 
         String customizedNameServer = this.applicationContext.getEnvironment().resolveRequiredPlaceholders(this.rocketMQMessageListener.nameServer());
         if (customizedNameServer != null) {
diff --git a/rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/support/RocketMQUtil.java
b/rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/support/RocketMQUtil.java
index 7d25acd..082b0f6 100644
--- a/rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/support/RocketMQUtil.java
+++ b/rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/support/RocketMQUtil.java
@@ -31,6 +31,7 @@ import org.apache.rocketmq.client.producer.TransactionMQProducer;
 import org.apache.rocketmq.client.trace.AsyncTraceDispatcher;
 import org.apache.rocketmq.client.trace.TraceDispatcher;
 import org.apache.rocketmq.client.trace.hook.SendMessageTraceHookImpl;
+import org.apache.rocketmq.common.UtilAll;
 import org.apache.rocketmq.common.message.Message;
 import org.apache.rocketmq.common.message.MessageConst;
 import org.apache.rocketmq.common.message.MessageExt;
@@ -275,5 +276,13 @@ public class RocketMQUtil {
 
         return producer;
     }
+    
+    public static String getInstanceName(String identify) {
+        char separator = '@';
+        StringBuilder instanceName = new StringBuilder();
+        instanceName.append(identify)
+                .append(separator).append(UtilAll.getPid());
+        return instanceName.toString();
+    }
 
 }
diff --git a/rocketmq-spring-boot/src/test/java/org/apache/rocketmq/spring/support/RocketMQUtilTest.java
b/rocketmq-spring-boot/src/test/java/org/apache/rocketmq/spring/support/RocketMQUtilTest.java
index 42439ad..e558483 100644
--- a/rocketmq-spring-boot/src/test/java/org/apache/rocketmq/spring/support/RocketMQUtilTest.java
+++ b/rocketmq-spring-boot/src/test/java/org/apache/rocketmq/spring/support/RocketMQUtilTest.java
@@ -130,4 +130,11 @@ public class RocketMQUtilTest {
         assertEquals("tagA", message.getHeaders().get(toRocketHeaderKey(RocketMQHeaders.TAGS)));
         assertEquals("key1", message.getHeaders().get(toRocketHeaderKey(RocketMQHeaders.KEYS)));
     }
+    
+    @Test
+    public void testGetInstanceName() {
+        String nameServer = "127.0.0.1:9876";
+        String expected = "127.0.0.1:9876@";
+        assertEquals(expected + UtilAll.getPid(), RocketMQUtil.getInstanceName(nameServer));
+    }
 }
\ No newline at end of file


Mime
View raw message