當前位置: 首頁>>代碼示例>>Java>>正文


Java Schema.INT32_SCHEMA屬性代碼示例

本文整理匯總了Java中org.apache.kafka.connect.data.Schema.INT32_SCHEMA屬性的典型用法代碼示例。如果您正苦於以下問題:Java Schema.INT32_SCHEMA屬性的具體用法?Java Schema.INT32_SCHEMA怎麽用?Java Schema.INT32_SCHEMA使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.apache.kafka.connect.data.Schema的用法示例。


在下文中一共展示了Schema.INT32_SCHEMA屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: withSchema

@Test
public void withSchema() {
    final HoistField<SinkRecord> xform = new HoistField.Key<>();
    xform.configure(Collections.singletonMap("field", "magic"));

    final SinkRecord record = new SinkRecord("test", 0, Schema.INT32_SCHEMA, 42, null, null, 0);
    final SinkRecord transformedRecord = xform.apply(record);

    assertEquals(Schema.Type.STRUCT, transformedRecord.keySchema().type());
    assertEquals(record.keySchema(),  transformedRecord.keySchema().field("magic").schema());
    assertEquals(42, ((Struct) transformedRecord.key()).get("magic"));
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:12,代碼來源:HoistFieldTest.java

示例2: poll

@Override
public List<SourceRecord> poll() throws InterruptedException {
    long sendStartMs = System.currentTimeMillis();
    if (throttler.shouldThrottle(seqno - startingSeqno, sendStartMs))
        throttler.throttle();

    long nowMs = System.currentTimeMillis();

    Map<String, Object> data = new HashMap<>();
    data.put("name", name);
    data.put("task", id);
    data.put("topic", this.topic);
    data.put("time_ms", nowMs);
    data.put("seqno", seqno);
    String dataJson;
    try {
        dataJson = JSON_SERDE.writeValueAsString(data);
    } catch (JsonProcessingException e) {
        dataJson = "Bad data can't be written as json: " + e.getMessage();
    }
    System.out.println(dataJson);

    Map<String, Long> ccOffset = Collections.singletonMap(SEQNO_FIELD, seqno);
    SourceRecord srcRecord = new SourceRecord(partition, ccOffset, topic, Schema.INT32_SCHEMA, id, Schema.INT64_SCHEMA, seqno);
    List<SourceRecord> result = Arrays.asList(srcRecord);
    seqno++;
    return result;
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:28,代碼來源:VerifiableSourceTask.java


注:本文中的org.apache.kafka.connect.data.Schema.INT32_SCHEMA屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。