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!
2 Answers
Reset to default 2A 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.