百度智能云

All Product Document

          Cloud Monitor

          BcmClient

          BcmClient serves as the client for BCM services, offering developers various methods to interact with BCM services.

          Create BcmClient

          Create a new BcmClient with AK/SK

          Users can refer to the following code to create a new BcmClient to access BCC with AK/SK:

          public class Sample {
          public static void main(String[] args) {
           String ACCESS_KEY_ID =<your-access-key-id>;                   // User’s Access Key ID
           String SECRET_ACCESS_KEY =<your-secret-access-key>;           // User’s Secret Access Key
                  
           // Initialize a BcmClient
              BcmClientConfiguration config = new BcmClientConfiguration();
              config.setCredentials(new DefaultBceCredentials(ACCESS_KEY_ID, SECRET_ACCESS_KEY));
              BcmClient client = new BcmClient(config);
              }
          }

          In the code above, ACCESS_KEY_ID corresponds to “Access Key ID” in the console. SECRET_ACCESS_KEY corresponds to “Access Key Secret” in the console. For the method to retrieve them, refer to the Guide - [Manage ACCESSKEY](Reference/Retrieve AK and SK/How to Obtain AKSK.md).

          The method above uses the default domain as the BCM service address. To use a custom domain, pass the ENDPOINT parameter.

          String ACCESS_KEY_ID =<your-access-key-id>;                   // User’s Access Key ID
           String SECRET_ACCESS_KEY =<your-secret-access-key>;           // User’s Secret Access Key
           String ENDPOINT = <domain-name>;                               // User-defined domain name
          BcmClientConfiguration config = new BcmClientConfiguration();
          config.setCredentials(new DefaultBceCredentials(ACCESS_KEY_ID,SECRET_ACCESS_KEY));
          config.setEndpoint(ENDPOINT);
          BcmClient client = new BcmClient(config);

          Note:The ENDPOINT parameter must use region-specific domains (e.g., http://aihc.bj.baidubce.com for Beijing). If unspecified, it defaults to the Beijing regionhttp://bcm.bj.baidubce.com.

          Configure HTTPS access to BCM

          BCM supports HTTPS transport protocol. You can use HTTPS to access the BCM service in the BCM Java SDK in the following two ways:

          • Specify HTTPS in the endpoint:

            String endpoint = "https://bcm.bj.baidubce.com";
            String ak = "ak";
            String sk = "sk";
            BcmClientConfiguration config = new BcmClientConfiguration();
            config.setCredentials(new DefaultBceCredentials(ak, sk));
            BcmClient client = new BcmClient(config);
          • Configure HTTPS by calling setProtocol:

            String endpoint = "bcm.bj.baidubce.com"; // endpoint without protocol
            String ak = "ak";
            String sk = "sk";
            BcmClientConfiguration config = new BcmClientConfiguration();
            config.setCredentials(new DefaultBceCredentials(ak, sk));
            config.setEndpoint(ENDPOINT);
             config.setProtocol(Protocol.HTTPS); // Defaults to HTTP if unspecified
            BcmClient client = new BcmClient(config);
            > **Note:** If the endpoint already includes a protocol, the protocol in the endpoint will take precedence, and the setProtocol() method will be ignored.
            String endpoint = "http://bcm.bj.baidubce.com";
            String ak = "ak";
            String sk = "sk";
            BcmClientConfiguration config = new BcmClientConfiguration();
            config.setCredentials(new DefaultBceCredentials(ak, sk));
            config.setEndpoint(ENDPOINT);    
             config.setProtocol(Protocol.HTTPS); // Invalid operation if specified in endpoint, applicable to HTTP cases
            BcmClient client = new BcmClient(config);

          Configure BcmClient

          If users need to configure detailed parameters for BcmClient, they can specify the BcmClientConfiguration object when creating BcmClient. BcmClientConfiguration is the configuration class for BCM services, allowing configuration of parameters like proxies or the maximum number of client connections.

          Use a proxy

          The following code snippet enables the client to access BCM service using a proxy:

          String ACCESS_KEY_ID =<your-access-key-id>;                   // User’s Access Key ID
           String SECRET_ACCESS_KEY =<your-secret-access-key>;           // User’s Secret Access Key
           String ENDPOINT = <domain-name>;                               // User-defined domain name
           // Create BcmClientConfiguration instance
          BcmClientConfiguration config = new BcmClientConfiguration();
           // Configure proxy to local port 8080
          config.setProxyHost("127.0.0.1");
          config.setProxyPort(8080);
           // Create BCM client
          config.setCredentials(new DefaultBceCredentials(ACCESS_KEY_ID,SECRET_ACCESS_KEY));
          config.setEndpoint(ENDPOINT);
          BcmClient client = new BcmClient(config);

          All client requests will then be routed through the proxy at 127.0.0.1:8080.

          For verified proxies, configure credentials:

          // Create BcmClientConfiguration instance
          BcmClientConfiguration config = new BcmClientConfiguration();
              
           // Configure proxy to local port 8080
          config.setProxyHost("127.0.0.1");
          config.setProxyPort(8080);
              
           // Set username and password
           config.setProxyUsername(<username>);                             // Username
           config.setProxyPassword(<password>);                             // Password

          Set network parameters

          Users may set the basic network parameters with BcmClientConfiguration:

          BcmClientConfiguration config = new BcmClientConfiguration();
              
           // Set maximum number of HTTP connections to 10
          config.setMaxConnections(10);
              
           // Set TCP connection timeout to 5,000 milliseconds
          config.setConnectionTimeoutInMillis(5000);
              
           // Set timeout for Socket data transmission to 2,000 milliseconds
          config.setSocketTimeout(2000);

          Parameter description

          The following parameters can be configured via BcmClientConfiguration:

          Parameters Description
          CnameEnabled Use CNAME to access BCM resources
          ConnectionTimeoutInMillis Timeout for establishing TCP connections (unit: ms)
          Credentials Client credentials for signing HTTP requests with BCE
          EnableHttpAsyncPut Asynchronous put
          Endpoint Access a domain name
          LocalAddress Local address
          MaxConnections Maximum allowable HTTP connections
          Protocol Connection protocol type
          ProxyDomain Windows domain for NTLM-verified proxy
          ProxyHost Proxy server host address
          ProxyPassword Proxy verification password
          ProxyPort Proxy server port
          ProxyPreemptiveAuthenticationEnabled Enable user agent verification or not
          ProxyUsername Proxy verification username
          ProxyWorkstation NTLM proxy workstation name
          Region Region
          RetryPolicy Retry policy for connections
          SocketBufferSizeInBytes Buffer size for socket operations
          SocketTimeoutInMillis Timeout for socket data transmission (unit: ms)
          StreamBufferSize Stream file buffer size
          UserAgent User agent, refers to HTTP’s User-Agent header
          RedirectsEnabled Whether HTTP redirection is enabled. Enabled by default.
          Previous
          Batch Query Monitoring Data Interface V2
          Next
          Dimension Value TopN and Monitoring Data Query Interface