简体   繁体   English

在使用kafka-cassandra接收器连接器存储在cassandra中之前,是否有任何向我们的消息添加时间戳的功能?

[英]Is there any function for adding timestamp to our message before storing in cassandra using kafka-cassandra sink connector?

I'm setting up my logserver. 我正在设置我的日志服务器。 I'm forwarding logs using Fluentd to Kafka and then storing them in Cassandra for later use. 我正在使用Fluentd将日志转发到Kafka,然后将其存储在Cassandra中以备后用。 For this I'm using kafka-cassandra sink connector. 为此,我正在使用kafka-cassandra接收器连接器。 I have to store data chronologically for which I need to add timestamp to my messages in cassandra. 我必须按时间顺序存储数据,为此我需要在cassandra中为消息添加时间戳。 How can this be done? 如何才能做到这一点?

Datamountaineer connector uses kcql which i think doesn't support inserting timestamp to a log. Datamountaineer连接器使用kcql,我认为它不支持在日志中插入时间戳。

My connector configuration is as follows: 我的连接器配置如下:

name=cassandra-sink
connector.class=com.datamountaineer.streamreactor.connect.cassandra.sink.CassandraSinkConnector
tasks.max=1
topics=test_AF1
connect.cassandra.kcql=INSERT INTO test_event1 SELECT now() as id, message as msg FROM test_AF1 TIMESTAMP=sys_time()
connect.cassandra.port=9042
connect.cassandra.contact.points=localhost
connect.cassandra.key.space=demo

Kafka Connect's Single Message Transform can do this. Kafka Connect的单一消息转换可以做到这一点。 Here's an example: 这是一个例子:

{
  "connector.class": "com.datamountaineer.streamreactor.connect.cassandra.sink.CassandraSinkConnector",
  "topics": "test_AF1",
…
  "transforms": "addTS",
  "transforms.addTS.type": "org.apache.kafka.connect.transforms.InsertField$Value",
  "transforms.addTS.timestamp.field": "op_ts"
}'

This adds a field to the message payload called op_ts with the timestamp of the Kafka message. 这会将带有Kafka消息时间戳的名为op_ts的字段添加到消息有效负载中。

I don't know how this interacts with KCQL; 我不知道它如何与KCQL交互; you might want to check out the other two Cassandra sinks that I'm aware of: 您可能想查看我知道的其他两个Cassandra水槽:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM