閱讀673 返回首頁    go 人物


快速指引__DataHub實時數據通道_大數據計算服務-阿裏雲

本節主要描述使用DataHub Java SDK進行數據的讀寫。

準備工作

  • 使用DataHub服務之前,需要注冊阿裏雲雲賬號,利用阿裏雲賬號的AccessId與AccessKey接入DataHub服務。

創建Project/Topic

發布數據/訂閱數據

發布/訂閱數據需要使用SDK完成, DataHub Java SDK使用說明

  1. // 新建client
  2. Account account = new AliyunAccount("your access id", "your access key");
  3. DatahubConfiguration conf = new DatahubConfiguration(account, "datahub endpoint");
  4. DatahubClient client = new DatahubClient(conf);
  5. String shardId = "0";
  6. // 構造需要上傳的records
  7. RecordSchema schema = client.getTopic("test_project", "test_topic").getRecordSchema();
  8. List<RecordEntry> recordEntries = new ArrayList<~>();
  9. RecordEntry entry = new RecordEntry(schema);
  10. for (int i=0; i<entry.getFieldCount(); i++) {
  11. entry.setBigint(i, 1); //set your fields' value according to the field's type
  12. }
  13. entry.setShardId(shardId);
  14. recordEntries.add(entry);
  15. // 數據寫入
  16. client.putRecords("test_project", "test_topic", recordEntries);
  17. // 數據讀取
  18. GetCursorResult cursor = client.getCursor("test_project", "test_topic", shardId, 1455869335000 /*ms*/);
  19. GetRecordsResult r = client.getRecords("test_project", "test_topic", shardId, cursor.getCursor(), 10);

最後更新:2016-11-23 16:04:20

  上一篇:go 限製描述__DataHub實時數據通道_大數據計算服務-阿裏雲
  下一篇:go SDK介紹__使用指南_DataHub實時數據通道_大數據計算服務-阿裏雲