dselivanov / rscalaKafka

Tiny R kafka client with rscala
10 stars 3 forks source link
kafka kafka-client r

Experimental Apache Kafka client

Very experimental rscala based Kafka client.

This client is built for Scala 2.11.8 and Kafka 0.10.2.0. For instructions on how to build KafkaClient for your environment please refer to readme in rscala-kafka directory.

Simple setup

To create simple sett you need something like:

library(rscalaKafka)
producer = KafkaProducer$new(broker_list = "localhost:9092", 
                             config = list())
consumer = KafkaConsumer$new(topic = "test", 
                             bootstrap_servers = "localhost:9092", 
                             group_id = "dummy", 
                             config = list("max.poll.records" =  "2"))

producer$send(LETTERS[1:10], "test")

for (i in 1:5) 
  message(consumer$poll(100))
#AB
#CD
#EF
#GH
#IJ

consumer$unsubsribe()
producer$close()

NOTE(!). If you will interrupt loop above with CTRL+C/Esc R <-> Scala protocol will be corrupted and most probably you will need to restart R and rscalaKafka to fix the problem.