最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Need to use Apache Kafka in my React-Native app - Stack Overflow

programmeradmin1浏览0评论

I've used Apache Kafka in my project and need it integrated inside a react-native app which is also part of the project. Basically, my server is a Kafka producer and the app needs to listen to topics and be a consumer.

At first, I tried using this npm package. .
But this package relies on core modules of nodejs that are not part of the React Native bundle. Is there any other way so as I could municate using Kafka inside a React Native app? Thanks!

I've used Apache Kafka in my project and need it integrated inside a react-native app which is also part of the project. Basically, my server is a Kafka producer and the app needs to listen to topics and be a consumer.

At first, I tried using this npm package. https://github./SOHU-Co/kafka-node.
But this package relies on core modules of nodejs that are not part of the React Native bundle. Is there any other way so as I could municate using Kafka inside a React Native app? Thanks!

Share Improve this question edited Mar 1, 2017 at 14:54 filipst 1,5712 gold badges30 silver badges56 bronze badges asked Mar 1, 2017 at 12:25 Mustansir ZiaMustansir Zia 1,00411 silver badges18 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

A quick solution would be to put the Kafka cluster behind a simple REST API. Using a library like kafka-rest could be an easy way to connect your React Native app using the built in fetch function. You could go a step further and try to integrate the kafka-rest-node client into your React Native app; a cursory overview of the repo doesn't lead to any core Node dependencies.

Another method, one which would allow for "live" updates, might consist of putting Kafka behind a web server that converts the Kafka stream into a WebSocket connection. Libraries such as kafka-websocket allow clients to both consume and produce, whereas a more simple library like Microsoft's kafka-proxy-ws only allows for consuming messages.

It's worth noting that mobile clients don't always work well with streaming data, and you'd be advised to test your WebSocket-based implementation on a variety of uncertain network conditions (latency, dropped signals, etc).

Try DeepstreamIO.

It's a real-time socket server that integrates well with both React-Native and Kafka. It can use Kafka as a message broker to municate messages between distributed Deepstream nodes and push messages to other subscribed clients. They are open source so you can configure their connectors to your specific needs.

发布评论

评论列表(0)

  1. 暂无评论