Add function documentation and error handling.
authorFrederik Vanrenterghem <frederik@vanrenterghem.io>
Fri, 14 Sep 2018 13:19:36 +0000 (21:19 +0800)
committerFrederik Vanrenterghem <frederik@vanrenterghem.io>
Fri, 14 Sep 2018 13:19:36 +0000 (21:19 +0800)
Add documentation and basic error handling to CreateKafkaConsumer function.

R/CreateKafkaConsumer.R

index cf6edee6dd9066073489cec30476c3a16d5dc78f..71f9f729eebe8ea40d76c9f7d3c431dcb3d01c3d 100644 (file)
@@ -1,3 +1,15 @@
+#' Create Apache Kafka consumer using Confluent's REST Proxy API
+#' 
+#' \code{CreateKafkaConsumer} creates an Apache Kafka consumer using the rest proxy api provided by Confluence.
+#' 
+#' @param kafka.rest.proxy The URI of the REST Proxy. Defaults to \url{http://localhost:8082}.
+#' @param consumer A chr object with the name for the consumer.
+#' @param consumer_instance A chr object with the name for the consumer_instance.
+#' 
+#' @return If the operation succeeds, returns a list with the created consumer instance and its base URI.
+#'   If the operation fails, the received reply is returned. Use \code{jsonlite::fromJSON(content(response, "text"))}
+#'   to obtain a list with the error code and message.
+#'   
 CreateKafkaConsumer <- function(kafka.rest.proxy = "http://localhost:8082", consumer, consumer_instance) {
   response <- POST(url=paste(kafka_rest_proxy, "consumers", consumer, sep="/"),
                    content_type("application/vnd.kafka.v2+json"),
@@ -6,6 +18,7 @@ CreateKafkaConsumer <- function(kafka.rest.proxy = "http://localhost:8082", cons
                                consumer_instance,
                                '", "format": "json", "auto.offset.reset": "earliest"}')
   )
+  if(response$status_code!=200) stop(response) else
   consumerDetails <- fromJSON(content(response, "text"))
   return(consumerDetails)
 }
\ No newline at end of file