本文介绍如何使用C++ SDK删除一个事件规则下的一个或多个投递目标。

示例代码如下:

#include <alibabacloud/event_bridge.hpp>
#include <alibabacloud/sample.hpp>
#include <darabonba/console.hpp>
#include <darabonba/core.hpp>
#include <darabonba/util.hpp>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

using namespace Alibabacloud_Sample;

Alibabacloud_EventBridge::Client Alibabacloud_Sample::Client::createClient() {
  shared_ptr<Alibabacloud_EventBridge::Config> config =
      make_shared<Alibabacloud_EventBridge::Config>();
  //AccessKey ID。
  config->accessKeyId = make_shared<string>("<accessKeyId>");
  //AccessKey Secret。
  config->accessKeySecret = make_shared<string>("<accessKeySecret>");
  //接入点。
  config->endpoint = make_shared<string>("<endpoint>");
  return Alibabacloud_EventBridge::Client(config);
}

void Alibabacloud_Sample::Client::removeTargetsSample(
    shared_ptr<Alibabacloud_EventBridge::Client> client) {
  try {
    shared_ptr<Alibabacloud_EventBridge::DeleteTargetsRequest>
        removeTargetsRequest =
            make_shared<Alibabacloud_EventBridge::DeleteTargetsRequest>();
    removeTargetsRequest->eventBusName = make_shared<string>("demo-bus");
    removeTargetsRequest->ruleName = make_shared<string>("myRule");
    shared_ptr<vector<string>> list =
        make_shared<vector<string>>(vector<string>({"dingtalk.target"}));
    removeTargetsRequest->targetIds = list;
    shared_ptr<Alibabacloud_EventBridge::DeleteTargetsResponse> response =
        make_shared<Alibabacloud_EventBridge::DeleteTargetsResponse>(
            client->deleteTargets(removeTargetsRequest));
    Darabonba_Console::Client::log(make_shared<string>(
        "--------------------remove targets success--------------------"));
    Darabonba_Console::Client::log(
        make_shared<string>(Darabonba_Util::Client::toJSONString(
            make_shared<map<string, boost::any>>(response->toMap()))));
  } catch (std::exception &error) {
    Darabonba_Console::Client::log(error.message);
  }
}

void Alibabacloud_Sample::Client::main(shared_ptr<vector<string>> args) {
  shared_ptr<Alibabacloud_EventBridge::Client> client =
      make_shared<Alibabacloud_EventBridge::Client>(Client::createClient());
  Client::removeTargetsSample(client);
}