--- /dev/null
+SubscribeKafkaTopic <- function(consumer.base.uri, topic) {
+ response <- POST(url=paste(consumer.base.uri,
+ "subscription", sep="/"),
+ content_type("application/vnd.kafka.v2+json"),
+ body = paste0('{"topics":["',
+ topic,
+ '"]}')
+ )
+ if(response$status_code == 204) {
+ return(response)
+ } else stop(response)
+}
\ No newline at end of file
consumerDetails <- CreateKafkaConsumer(kafka.rest.proxy = kafka_rest_proxy, consumer = consumer, consumer_instance = consumer_instance)
# Subscribe it to topic
-response <- POST(url=paste(consumerDetails$base_uri,
- "subscription", sep="/"),
- content_type("application/vnd.kafka.v2+json"),
- body = paste0('{"topics":["',
- topic,
- '"]}')
- )
-response
+source("R/SubscribeKafkaTopic.R")
+response <- SubscribeKafkaTopic(consumerDetails$base_uri,topic = topic)
# Obtain all (or latest) messages on the topic
source("R/ConsumeKafkaMessages.R")