WebSocket转Kafka主题Scala API [英] WebSocket to Kafka Topic Scala API

查看:95
本文介绍了WebSocket转Kafka主题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

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆