Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kafka Producer on Android

Tags:

I would like to use an Android client as a Kafka Producer. When I try to send a record to the topic I'm getting following error:

Didn't find class "java.lang.management.ManagementFactory

on this line:

mProducer = new KafkaProducer(configProperties);

I am below the limit for the amount of methods:

Total methods in mobile-debug.apk: 52200 (79.65% used) 
Total fields in mobile-debug.apk:  21143 (32.26% used) 

What can be the reason that causes this error?

By the way, I wasn't able to find any example where kafka producer was used on an Android or iOS.

Update 1

In addition to the answer of Borys Zibrov, seems that nobody ported it successfully. These threads are also 2 years old.

  • https://qnalist.com/questions/5017593/has-anybody-successfully-integrated-kafka-jar-for-android-app

  • https://www.quora.com/In-Apache-Kafka-Can-we-have-mobiles-Android-or-IOS-Devices-as-Consumers-What-is-your-take-on-this

Update 2

Regarding the ManagementFactory class, see this question: android add java.lang.management API

like image 213
Azertiy Avatar asked Nov 04 '16 16:11

Azertiy


People also ask

What is Kafka in Android?

Apache Kafka is an open-source distributed event streaming platform used by thousands of companies for high-performance data pipelines, streaming analytics, data integration, and mission-critical applications.

Can Kafka producer and consumer be on different servers?

Yes, if you want to have your producer on Server A and your consumer on server B, you are in the right direction. You need to run a Broker on server A to make it work. The other commands are correct.


1 Answers

I'm actually not sure it's possible to use Kafka as a producer on Android (see for instance, this question, not answered at the moment of writing), because of the dependencies involved. So, someone might have ported Kafka to Android but I don't know that.

I could suggest a simple alternative: REST service that posts data to Kafka, and Android App will just call this service.

like image 101
borowis Avatar answered Sep 22 '22 16:09

borowis