Operate Channel

启动或停止数据读取通道或数据写入通道。

前提条件

已存在数据读取通道或数据写入通道。

请求格式

POST https://{apigw-address}/data-federation/v2.0/channels/{channelId}

请求参数(URI)

名称 位置(Path/Query) 必需/可选 数据类型 描述
orgId Query 必需 String 用户所属的组织ID。如何获取orgId信息>>
channelId Path 必需 String 通道ID。
action Query 必需 String 对通道的操作(start:启动通道;stop:停止通道)。
resource Query 非必需 String 通道所使用的资源ID

请求参数(Body)

名称 必需/可选 数据类型 描述
resource 可选 List<JSONObject> 启动通道时,指定运行通道所需的资源配置,详见 资源结构体

资源结构体

名称 必需/可选 数据类型 描述
resourceId 必需 String 指定运行通道所需的数据联邦资源ID(通过 EnOS 资源管理 页面申请)。
resourceConfig 必需 Integer 指定运行通道所需的数据资源数量(单位为CU)。
ifMultiResourceAnalysis 必需 Boolean 指定是否开启跨源分析功能(true:开启;false:不开启)

示例

请求示例

url: https://{apigw-address}/data-federation/v2.0/channels/{channelId}?orgId={}&action=start

method: POST

request body

{
  "resource": {
    "resourceId": "federation_3n6nb7",
    "resourceConfig": "2",
    "ifMultiResourceAnalysis": "false"
  }
}

返回示例

{
  "msg": "OK",
  "code": 0
}

Java SDK调用示例

import com.alibaba.fastjson.JSONObject;
import com.envision.apim.poseidon.config.PConfig;
import com.envision.apim.poseidon.core.Poseidon;
import com.envision.apim.poseidon.request.PoseidonRequest;
import com.google.common.net.HttpHeaders;
import org.apache.commons.codec.binary.Hex;
import org.junit.Test;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;

public class Sample {

    private static String accessKey = "AccessKey of your APP";
    private static String secretKey = "SecretKey of your APP";
    private static String orgId = "yourOrgId";
    private static String chId = "yourChannelId";
    private static String action = "start";
    private static String url = "https://{domain_url}";

    private static class Request extends PoseidonRequest {

        public void setQueryParam(String key, Object value) {
            queryEncodeParams().put(key, value);
        }

        public void setMethod(String method) {
            this.method = method;
        }

        public void setBodyParams(String key, Object value) {
            bodyParams().put(key, value);
        }

        private String method;

        @Override
        public String baseUri() {
            return "";
        }

        @Override
        public String method() {
            return method;
        }
    }

    @Test
    public void operateChannel() {
        Request request = new Request();
        request.setQueryParam("orgId", orgId);
        request.setQueryParam("action", action);
        Map<String, Object> resource = new HashMap<>();
        resource.put("resourceId", "federation_2n6nb7");
        resource.put("resourceConfig", "2");
        resource.put("ifMultiResourceAnalysis", false);
        request.setQueryParam("resource", resource);
        request.setMethod("POST");
        try {
            JSONObject response = Poseidon.config(PConfig.init().appKey(accessKey).appSecret(secretKey))
                    .url(url + "/data-federation/v2.0/channels/" + chId)
                    .getResponse(request, JSONObject.class);
            System.out.println(response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}