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:
[email protected]


With regards,
Apache Git Services

Reply via email to