全部产品
云市场

Client创建

更新时间:2019-11-04 15:59:11

引用SDK后,初始化Client示例如下。

注意: 实例域名(instanceDomain),端口(instanceDomainPort)以及AK信息(accessKey, accessSecret)需要SDK用户自行提供。

  1. String instanceDomain = "*****";
  2. int instanceDomainPort = **;
  3. String accessKey = "***";
  4. String accessSecret = "***";
  5. CredentialsManager credentialsManager = new CredentialsManager(accessKey, accessSecret);
  6. GryoMapper.Builder kryo = GryoMapper.build().addRegistry(MaxGraphIORegistry.getInstance());
  7. MessageSerializer serializer = new GryoMessageSerializerV1d0(kryo);
  8. try {
  9. cluster = Cluster.build()
  10. .addContactPoint(instanceDomain)
  11. .port(instanceDomainPort)
  12. .serializer(serializer)
  13. .credentials(credentialsManager.getUserName(), credentialsManager.getPassword())
  14. .create();
  15. } catch (Exception e) {
  16. throw new IllegalArgumentException("build credentials password fail", e);
  17. }
  18. client = cluster.connect();

instanceDomain和instancePort可以在DataWorks控制台的GraphCompute实例详情页面找到,图示如下:client001