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 2019/03/25 17:06:59 UTC

[GitHub] [rocketmq-client-cpp] jonnxu commented on a change in pull request #105: [ISSUE #88] select slave broker when master broker is unavailable.

jonnxu commented on a change in pull request #105: [ISSUE #88] select slave broker when master broker is unavailable.
URL: https://github.com/apache/rocketmq-client-cpp/pull/105#discussion_r268752686
 
 

 ##########
 File path: src/MQClientFactory.cpp
 ##########
 @@ -631,35 +631,36 @@ string MQClientFactory::findBrokerAddressInPublish(const string& brokerName) {
   return "";
 }
 
-FindBrokerResult* MQClientFactory::findBrokerAddressInSubscribe(
-    const string& brokerName, int brokerId, bool onlyThisBroker) {
-  string brokerAddr;
-  bool slave = false;
-  bool found = false;
-  BrokerAddrMAP brokerTable(getBrokerAddrMap());
-
-  if (brokerTable.find(brokerName) != brokerTable.end()) {
-    map<int, string> brokerMap(brokerTable[brokerName]);
-    map<int, string>::iterator it1 = brokerMap.find(brokerId);
-    if (it1 != brokerMap.end()) {
-      brokerAddr = it1->second;
-      slave = (brokerId != MASTER_ID);
-      found = true;
-    } else  // from master
-    {
-      it1 = brokerMap.find(MASTER_ID);
-      if (it1 != brokerMap.end()) {
-        brokerAddr = it1->second;
-        slave = false;
-        found = true;
-      }
+FindBrokerResult *MQClientFactory::findBrokerAddressInSubscribe(const string &brokerName,
+                                                                int brokerId,
+                                                                bool onlyThisBroker) {
+    string brokerAddr;
+    bool slave = false;
+    bool found = false;
+    BrokerAddrMAP brokerTable(getBrokerAddrMap());
+
+    if (brokerTable.find(brokerName) != brokerTable.end()) {
+        map<int, string> brokerMap(brokerTable[brokerName]);
+        auto iter = brokerMap.find(brokerId);
+        if (iter != brokerMap.end()) {
+            brokerAddr = iter->second;
+            slave = (brokerId != MASTER_ID);
+            found = true;
+        } else if (!onlyThisBroker) {  // not only from master
+            iter = brokerMap.begin();
+            brokerAddr = iter->second;
 
 Review comment:
   i think here need add if(iter != brokerMap.end()) 

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services