为什么 KSQL 不流式传输 return/show 来自代理主题消息的数据?
Why doesn't a KSQL stream not return/show data from messages on topic in broker?
我有一个简单的 Kafka 代理 运行 一个主题 raw_events
。
通过 kafka-console-producer --topic raw_events --broker-list kafka:29092 < event.json
,我将事件添加到成功显示为 kafka-console-consumer --bootstrap-server kafka:29092 --topic raw_events
的主题。所以,我知道事件在代理中(在正确的主题中)并且也可以从代理中使用**)。
在这种情况下,event.json
文件包含一个非常简单的 JSON:
{'event_type': 'issue',
'project': 'sample',
'user': {'name': 'John Doe', 'username': 'jdoe'}
}
在KSQL中,题目在那里:
ksql> show topics;
Kafka Topic | Registered | Partitions | Partition Replicas | Consumers | ConsumerGroups
--------------------------------------------------------------------------------------------------
raw_events | true | 1 | 1 | 3 | 3
包含早期尝试的一些事件:
ksql> print 'raw_events';
Format:STRING
11/2/18 3:36:21 PM UTC , NULL , {'event_type': 'issue', 'project': 'sample', 'user': {'name': 'John Doe', 'username': 'jdoe'}}
11/2/18 3:43:05 PM UTC , NULL , {'event_type': 'issue', 'project': 'sample', 'user': {'name': 'John Doe', 'username': 'jdoe'}}
11/2/18 3:45:19 PM UTC , NULL , {'event_type': 'issue', 'project': 'sample', 'user': {'name': 'John Doe', 'username': 'jdoe'}}
11/2/18 3:45:43 PM UTC , NULL , {'event_type': 'issue', 'project': 'sample', 'user': {'name': 'John Doe', 'username': 'jdoe'}}
11/2/18 3:47:30 PM UTC , NULL , {'event_type': 'issue', 'project': 'sample', 'user': {'name': 'John Doe', 'username': 'jdoe'}}
(我正在关注 https://docs.confluent.io/current/ksql/docs/developer-guide/create-a-stream.html,但使用的是我自己的数据。)
现在,我在 KSQL 中创建了一个成功的流:
create stream new_events (event_type varchar, project varchar) with (kafka_topic='raw_events', value_format='JSON');
流已创建:
ksql> show streams;
Stream Name | Kafka Topic | Format
----------------------------------------
NEW_EVENTS | raw_events | JSON
----------------------------------------
然而(这是我的问题——它可能是 PEBKAC 或 KSQL 错误)该流上的 SELECT
只是停止并且不显示任何事件......即使我继续为主题添加事件:
ksql> select * from new_events;
[... nothing here ...]
选择特定的列,如 project
也不会 return 个条目。
**) 顺便说一句,我不清楚为什么 produce CLI 命令有一个参数 --broker-list
而 consume CLI 命令有 --bootstrap-server
似乎是同一件事。
按照 https://www.confluent.io/blog/troubleshooting-ksql-part-1 中的故障排除提示...
- 我在源主题中有数据
- 我有新数据*) 到达主题
- KSQL 正在使用正确偏移量的数据
- 数据匹配*) 指定的谓词
- 我在读取数据时没有出现反序列化错误...已报告 *)
你会注意到 *) 的......我发现问题是我在 JSON 中使用了单引号,而有效的 JSON 正式指定(你猜对了it) 引号只能是双引号,"
。 JSON 的某些内部表示被导出为 JSON-with-single-quotes.
因此,根据我的示例,正确的 JSON 应该是
{"event_type": "issue",
"project": "sample",
"user": {"name": "John Doe", "username": "jdoe"}}
一切都很好。
(尽管 KSQL 服务器的日志中没有任何内容表明这是问题的原因。幸运的是,如果其他人遇到此问题,这不会作为潜在的解决方案记录在案。)
我有一个简单的 Kafka 代理 运行 一个主题 raw_events
。
通过 kafka-console-producer --topic raw_events --broker-list kafka:29092 < event.json
,我将事件添加到成功显示为 kafka-console-consumer --bootstrap-server kafka:29092 --topic raw_events
的主题。所以,我知道事件在代理中(在正确的主题中)并且也可以从代理中使用**)。
在这种情况下,event.json
文件包含一个非常简单的 JSON:
{'event_type': 'issue',
'project': 'sample',
'user': {'name': 'John Doe', 'username': 'jdoe'}
}
在KSQL中,题目在那里:
ksql> show topics;
Kafka Topic | Registered | Partitions | Partition Replicas | Consumers | ConsumerGroups
--------------------------------------------------------------------------------------------------
raw_events | true | 1 | 1 | 3 | 3
包含早期尝试的一些事件:
ksql> print 'raw_events';
Format:STRING
11/2/18 3:36:21 PM UTC , NULL , {'event_type': 'issue', 'project': 'sample', 'user': {'name': 'John Doe', 'username': 'jdoe'}}
11/2/18 3:43:05 PM UTC , NULL , {'event_type': 'issue', 'project': 'sample', 'user': {'name': 'John Doe', 'username': 'jdoe'}}
11/2/18 3:45:19 PM UTC , NULL , {'event_type': 'issue', 'project': 'sample', 'user': {'name': 'John Doe', 'username': 'jdoe'}}
11/2/18 3:45:43 PM UTC , NULL , {'event_type': 'issue', 'project': 'sample', 'user': {'name': 'John Doe', 'username': 'jdoe'}}
11/2/18 3:47:30 PM UTC , NULL , {'event_type': 'issue', 'project': 'sample', 'user': {'name': 'John Doe', 'username': 'jdoe'}}
(我正在关注 https://docs.confluent.io/current/ksql/docs/developer-guide/create-a-stream.html,但使用的是我自己的数据。)
现在,我在 KSQL 中创建了一个成功的流:
create stream new_events (event_type varchar, project varchar) with (kafka_topic='raw_events', value_format='JSON');
流已创建:
ksql> show streams;
Stream Name | Kafka Topic | Format
----------------------------------------
NEW_EVENTS | raw_events | JSON
----------------------------------------
然而(这是我的问题——它可能是 PEBKAC 或 KSQL 错误)该流上的 SELECT
只是停止并且不显示任何事件......即使我继续为主题添加事件:
ksql> select * from new_events;
[... nothing here ...]
选择特定的列,如 project
也不会 return 个条目。
**) 顺便说一句,我不清楚为什么 produce CLI 命令有一个参数 --broker-list
而 consume CLI 命令有 --bootstrap-server
似乎是同一件事。
按照 https://www.confluent.io/blog/troubleshooting-ksql-part-1 中的故障排除提示...
- 我在源主题中有数据
- 我有新数据*) 到达主题
- KSQL 正在使用正确偏移量的数据
- 数据匹配*) 指定的谓词
- 我在读取数据时没有出现反序列化错误...已报告 *)
你会注意到 *) 的......我发现问题是我在 JSON 中使用了单引号,而有效的 JSON 正式指定(你猜对了it) 引号只能是双引号,"
。 JSON 的某些内部表示被导出为 JSON-with-single-quotes.
因此,根据我的示例,正确的 JSON 应该是
{"event_type": "issue",
"project": "sample",
"user": {"name": "John Doe", "username": "jdoe"}}
一切都很好。
(尽管 KSQL 服务器的日志中没有任何内容表明这是问题的原因。幸运的是,如果其他人遇到此问题,这不会作为潜在的解决方案记录在案。)