You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by li...@apache.org on 2022/07/28 08:01:06 UTC
[rocketmq-clients] 01/01: Make client-id unique in case container clients retart
This is an automated email from the ASF dual-hosted git repository.
lizhanhui pushed a commit to branch cpp_dev
in repository https://gitbox.apache.org/repos/asf/rocketmq-clients.git
commit e78c54c3f50a1f63e11ff0e66e094cf2c2df6d85
Author: Li Zhanhui <li...@gmail.com>
AuthorDate: Thu Jul 28 16:00:50 2022 +0800
Make client-id unique in case container clients retart
---
cpp/source/rocketmq/ClientImpl.cpp | 1 +
cpp/source/rocketmq/include/ClientImpl.h | 8 ++++++++
2 files changed, 9 insertions(+)
diff --git a/cpp/source/rocketmq/ClientImpl.cpp b/cpp/source/rocketmq/ClientImpl.cpp
index 0532d73..bccfe37 100644
--- a/cpp/source/rocketmq/ClientImpl.cpp
+++ b/cpp/source/rocketmq/ClientImpl.cpp
@@ -609,6 +609,7 @@ std::string ClientImpl::clientId() {
std::string processID = std::to_string(getpid());
ss << processID << "#";
ss << sequence.fetch_add(1, std::memory_order_relaxed);
+ ss << "_" << MixAll::millisecondsOf(std::chrono::system_clock::now().time_since_epoch());
return ss.str();
}
diff --git a/cpp/source/rocketmq/include/ClientImpl.h b/cpp/source/rocketmq/include/ClientImpl.h
index f0b29f7..78d2759 100644
--- a/cpp/source/rocketmq/include/ClientImpl.h
+++ b/cpp/source/rocketmq/include/ClientImpl.h
@@ -228,6 +228,14 @@ private:
void doVerify(std::string target, std::string command_id, MessageConstPtr message);
+ /**
+ * ClientID is required to remain unique in the following scenarios:
+ *
+ * 1. Create multiple clients;
+ * 2. Restart the client program in container deployments;
+ *
+ * @return Unique Client-ID
+ */
static std::string clientId();
std::string metricServiceEndpoint() const;