-3

我有一个 Kafka 主题,其中包含客户、购买、产品等数据。我想从这个单一主题创建不同的流。

4

1 回答 1

0

让我假设您的 Kafka 主题的消息(JSON 格式),例如:

{
    "customer_id":value,
    "customer_name":value,
    "purchase_id":value,
    "purchase_desc":value,
    "product_id":value,
    "product_name":value
}

并假设主题名称是my_topic.

所以你可以这样做:

对于customer流:

CREATE STREAM customer (
    -- which 'customer_id' match the JSON key
    customer_id BIGINT,
    customer_name VARCHAR
) WITH (
    VALUE_FORMAT = 'JSON',
    KAFKA_TOPIC = 'my_topic'
);

对于purchase表:

CREATE STREAM purchase (
    purchase_id BIGINT,
    purchase_desc VARCHAR
) WITH (
    VALUE_FORMAT = 'JSON',
    KAFKA_TOPIC = 'my_topic'
);

对于product表:

CREATE STREAM product (
    product_id BIGINT,
    product_name VARCHAR
) WITH (
    VALUE_FORMAT = 'JSON',
    KAFKA_TOPIC = 'my_topic'
);
于 2018-09-30T04:22:38.110 回答