You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by di...@apache.org on 2019/08/21 02:46:48 UTC

[rocketmq-ons-cpp] branch master updated: Use Cloud as default onschanel (#7)

This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new 56a2c08  Use Cloud as default onschanel (#7)
56a2c08 is described below

commit 56a2c0854167ea2a21b0d350654c2b898f0a0346
Author: dinglei <li...@163.com>
AuthorDate: Wed Aug 21 10:46:44 2019 +0800

    Use Cloud as default onschanel (#7)
    
    * Use Cloud as default onschanel
    
    * Reduce strict check if not using AIYUN chanel
    
    * Reduce strict check if not using AIYUN chanel
---
 src/main/cpp/sdk/ONSFactory.cpp           | 30 ++++++++----------------------
 src/main/cpp/sdk/common/UtilAll.cpp       |  8 +-------
 src/main/cpp/sdk/extern/CProducer.cpp     |  3 +++
 src/main/cpp/sdk/extern/CPushConsumer.cpp |  3 +++
 src/test/c/CProducerTest.cpp              |  7 ++++---
 5 files changed, 19 insertions(+), 32 deletions(-)

diff --git a/src/main/cpp/sdk/ONSFactory.cpp b/src/main/cpp/sdk/ONSFactory.cpp
index bf1686f..c0fb409 100644
--- a/src/main/cpp/sdk/ONSFactory.cpp
+++ b/src/main/cpp/sdk/ONSFactory.cpp
@@ -223,6 +223,7 @@ namespace ons {
         }
         return -1;
     }
+
     const int ONSFactoryProperty::getSuspendTimeMillis() const {
         map<string, string>::const_iterator it =
                 m_onsFactoryProperties.find(SuspendTimeMillis);
@@ -379,13 +380,13 @@ namespace ons {
 using namespace ons;
 
 int validateProperty(ONSFactoryProperty factoryProperty) throw(ons::ONSClientException) {
-    if (NULL_STRING == factoryProperty.getAccessKey()) {
+    if (ALIYUN == factoryProperty.getOnsChannel() && NULL_STRING == factoryProperty.getAccessKey()) {
         throw ONSClientException(
                 FAQ::errorMessage("AccessKey must be set, please set it.",
                                   FAQ::CLIENT_CHECK_MSG_EXCEPTION),
                 -1);
     }
-    if (NULL_STRING == factoryProperty.getSecretKey()) {
+    if (ALIYUN == factoryProperty.getOnsChannel() && NULL_STRING == factoryProperty.getSecretKey()) {
         throw ONSClientException(
                 FAQ::errorMessage("SecretKey must be set, please set it.",
                                   FAQ::CLIENT_CHECK_MSG_EXCEPTION),
@@ -422,11 +423,8 @@ ONSFactoryInstance::~ONSFactoryInstance() {
 }
 
 Producer *ONSFactoryInstance::createProducer(ons::ONSFactoryProperty factoryProperty) throw(ONSClientException) {
-    if (INNER == factoryProperty.getOnsChannel()) {
+    if (ALIYUN != factoryProperty.getOnsChannel()) {
         factoryProperty.setOnsTraceSwitch(false);
-        factoryProperty.setFactoryProperty(ONSFactoryProperty::AccessKey, "DefaultKey");
-        factoryProperty.setFactoryProperty(ONSFactoryProperty::SecretKey, "DefaultKey");
-        factoryProperty.setFactoryProperty(ONSFactoryProperty::NAMESRV_ADDR, "LocalDefault");
     }
     validateProperty(factoryProperty);
     ProducerImpl *producerImpl = new ProducerImpl(factoryProperty);
@@ -436,11 +434,8 @@ Producer *ONSFactoryInstance::createProducer(ons::ONSFactoryProperty factoryProp
 
 OrderProducer *ONSFactoryInstance::createOrderProducer(ons::ONSFactoryProperty factoryProperty) throw(
 ONSClientException) {
-    if (INNER == factoryProperty.getOnsChannel()) {
+    if (ALIYUN != factoryProperty.getOnsChannel()) {
         factoryProperty.setOnsTraceSwitch(false);
-        factoryProperty.setFactoryProperty(ONSFactoryProperty::AccessKey, "DefaultKey");
-        factoryProperty.setFactoryProperty(ONSFactoryProperty::SecretKey, "DefaultKey");
-        factoryProperty.setFactoryProperty(ONSFactoryProperty::NAMESRV_ADDR, "LocalDefault");
     }
     validateProperty(factoryProperty);
     OrderProducerImpl *orderProducerImpl = new OrderProducerImpl(factoryProperty);
@@ -451,11 +446,8 @@ ONSClientException) {
 
 OrderConsumer *ONSFactoryInstance::createOrderConsumer(ons::ONSFactoryProperty factoryProperty) throw(
 ONSClientException) {
-    if (INNER == factoryProperty.getOnsChannel()) {
+    if (ALIYUN != factoryProperty.getOnsChannel()) {
         factoryProperty.setOnsTraceSwitch(false);
-        factoryProperty.setFactoryProperty(ONSFactoryProperty::AccessKey, "DefaultKey");
-        factoryProperty.setFactoryProperty(ONSFactoryProperty::SecretKey, "DefaultKey");
-        factoryProperty.setFactoryProperty(ONSFactoryProperty::NAMESRV_ADDR, "LocalDefault");
     }
     validateProperty(factoryProperty);
     OrderConsumerImpl *consumer = new OrderConsumerImpl(factoryProperty);
@@ -466,11 +458,8 @@ ONSClientException) {
 TransactionProducer *ONSFactoryInstance::createTransactionProducer(
         ons::ONSFactoryProperty factoryProperty,
         ons::LocalTransactionChecker *checker) throw(ons::ONSClientException) {
-    if (INNER == factoryProperty.getOnsChannel()) {
+    if (ALIYUN != factoryProperty.getOnsChannel()) {
         factoryProperty.setOnsTraceSwitch(false);
-        factoryProperty.setFactoryProperty(ONSFactoryProperty::AccessKey, "DefaultKey");
-        factoryProperty.setFactoryProperty(ONSFactoryProperty::SecretKey, "DefaultKey");
-        factoryProperty.setFactoryProperty(ONSFactoryProperty::NAMESRV_ADDR, "LocalDefault");
     }
     validateProperty(factoryProperty);
     if (checker == NULL) {
@@ -490,11 +479,8 @@ ONSFactoryInstance::createPullConsumer(ons::ONSFactoryProperty factoryProperty)
 
 PushConsumer *
 ONSFactoryInstance::createPushConsumer(ons::ONSFactoryProperty factoryProperty) throw(ons::ONSClientException) {
-    if (INNER == factoryProperty.getOnsChannel()) {
+    if (ALIYUN != factoryProperty.getOnsChannel()) {
         factoryProperty.setOnsTraceSwitch(false);
-        factoryProperty.setFactoryProperty(ONSFactoryProperty::AccessKey, "DefaultKey");
-        factoryProperty.setFactoryProperty(ONSFactoryProperty::SecretKey, "DefaultKey");
-        factoryProperty.setFactoryProperty(ONSFactoryProperty::NAMESRV_ADDR, "LocalDefault");
     }
     validateProperty(factoryProperty);
     ConsumerImpl *consumer = new ConsumerImpl(factoryProperty);
diff --git a/src/main/cpp/sdk/common/UtilAll.cpp b/src/main/cpp/sdk/common/UtilAll.cpp
index 9288f77..9a4fc59 100644
--- a/src/main/cpp/sdk/common/UtilAll.cpp
+++ b/src/main/cpp/sdk/common/UtilAll.cpp
@@ -90,16 +90,10 @@ void UtilAll::init_factory_property(const ons::ONSFactoryProperty &factoryProper
             ons_channel = "ALIYUN";
             break;
         case CLOUD:
-            ons_channel = "CLOUD";
-            break;
         case ALL:
-            ons_channel = "ALL";
-            break;
         case LOCAL:
-            ons_channel = "LOCAL";
-            break;
         case INNER:
-            ons_channel = "INNER";
+            ons_channel = "CLOUD";
             break;
         default:
             ons_channel = "ALIYUN";
diff --git a/src/main/cpp/sdk/extern/CProducer.cpp b/src/main/cpp/sdk/extern/CProducer.cpp
index b048ef5..1ead006 100644
--- a/src/main/cpp/sdk/extern/CProducer.cpp
+++ b/src/main/cpp/sdk/extern/CProducer.cpp
@@ -284,6 +284,9 @@ int SetProducerSessionCredentials(CProducer *producer,
     }
     ((DefaultProducer *) producer)->factoryInfo.setFactoryProperty(ONSFactoryProperty::AccessKey, accessKey);
     ((DefaultProducer *) producer)->factoryInfo.setFactoryProperty(ONSFactoryProperty::SecretKey, secretKey);
+    if (onsChannel != NULL){
+        ((DefaultProducer *) producer)->factoryInfo.setFactoryProperty(ONSFactoryProperty::OnsChannel, onsChannel);
+    }
     return OK;
 }
 int SetProducerLogPath(CProducer *producer, const char *logPath) {
diff --git a/src/main/cpp/sdk/extern/CPushConsumer.cpp b/src/main/cpp/sdk/extern/CPushConsumer.cpp
index 3ad19cc..74b7753 100644
--- a/src/main/cpp/sdk/extern/CPushConsumer.cpp
+++ b/src/main/cpp/sdk/extern/CPushConsumer.cpp
@@ -244,6 +244,9 @@ int SetPushConsumerSessionCredentials(CPushConsumer *consumer,
     }
     ((DefaultPushConsumer *) consumer)->factoryInfo.setFactoryProperty(ONSFactoryProperty::AccessKey, accessKey);
     ((DefaultPushConsumer *) consumer)->factoryInfo.setFactoryProperty(ONSFactoryProperty::SecretKey, secretKey);
+    if (channel != NULL) {
+        ((DefaultPushConsumer *) consumer)->factoryInfo.setFactoryProperty(ONSFactoryProperty::OnsChannel, channel);
+    }
     return OK;
 }
 
diff --git a/src/test/c/CProducerTest.cpp b/src/test/c/CProducerTest.cpp
index 4bde86e..4dd8946 100644
--- a/src/test/c/CProducerTest.cpp
+++ b/src/test/c/CProducerTest.cpp
@@ -14,7 +14,7 @@ protected:
     void SetUp() override {
         producer_ = CreateProducer("GID_opensource_unit_test");
         SetProducerNameServerAddress(producer_, "47.100.33.127:9876");
-        SetProducerSessionCredentials(producer_, "AK", "SK", "LOCAL");
+        //SetProducerSessionCredentials(producer_, "AK", "SK", "LOCAL");
         StartProducer(producer_);
     }
 
@@ -37,7 +37,8 @@ TEST_F(CProducerTest, testSendMessage_Normal) {
     SetMessageTags(message, "TAG");
     SetMessageBody(message, "This is Message Body.");
     CSendResult sendResult;
-    SendMessageSync(producer_, message, &sendResult);
-    std::cout<<"Send OK,MessageID:"<< sendResult.msgId<<std::endl;
+    int ret = SendMessageSync(producer_, message, &sendResult);
+    std::cout << "Send Ret:" << ret << ", Result:" << sendResult.sendStatus << ", MessageID:" << sendResult.msgId
+              << std::endl;
     ASSERT_TRUE(E_SEND_OK == sendResult.sendStatus);
 }
\ No newline at end of file