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
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 @@
}
return -1;
}
+
const int ONSFactoryProperty::getSuspendTimeMillis() const {
map<string, string>::const_iterator it =
m_onsFactoryProperties.find(SuspendTimeMillis);
@@ -379,13 +380,13 @@
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 @@
}
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
}
((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 @@
}
((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 @@
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 @@
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