WebSocket转Kafka主题Scala API [英] WebSocket to Kafka Topic Scala API
问题描述
我有一个要求,其中我需要将WebSocket用作数据源,并希望将数据从WebSocket推送到Kafka主题中以进行进一步处理.我不确定scala中是否有任何api可以实现它.因此,请坚持使用此方法以开始解决方案.
I have a requirement where I have WebSocket as the data source and want to push data from WebSocket into Kafka topic for further processing. I am not sure if any apis is there in scala to achieve it. So stuck with this to get start with the solution.
推荐答案
In one of my hobby projects (play-binding-petstore) I used:
Alpakka Kafka
PathMsgProducer.scala 可以满足您的要求-从网络套接字获取输入并将其推送到 Kafka
.
PathMsgProducer.scala does what you are asking for - takes the input from a websocket and pushing it to Kafka
.
以下是将消息推送到 Kafka
的方法:
Here is how to push a message to Kafka
:
ProducerMessage.Message(
new ProducerRecord(comps.config.kafkaWsPathMsgTopic, msg.username, msg.route),
"passThrough"
)
有关如何在Websocket中使用它的信息,请参见 PathMsgProducer.scala
.
See PathMsgProducer.scala
on how to use it in the Websocket.
这篇关于WebSocket转Kafka主题Scala API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!