@Override public void stop() throws Exception { if (producer != null) { producer.close(); } } }
@Override public void start() throws Exception { systemMBean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class); // A random identifier String pid = UUID.randomUUID().toString(); // Get the kafka producer config JsonObject config = config(); // Create the producer producer = KafkaWriteStream.create(vertx, config.getMap(), String.class, JsonObject.class); // Publish the metircs in Kafka vertx.setPeriodic(1000, id -> { JsonObject metrics = new JsonObject(); metrics.put("CPU", systemMBean.getProcessCpuLoad()); metrics.put("Mem", systemMBean.getTotalPhysicalMemorySize() - systemMBean.getFreePhysicalMemorySize()); producer.write(new ProducerRecord<>("the_topic", new JsonObject().put(pid, metrics))); }); }
/** * Close the producer * @param completionHandler handler called on operation completed */ public void close(Handler<AsyncResult<Void>> completionHandler) { delegate.close(completionHandler); }
/** * @return the buffer key */ public String key() { if (cached_0 != null) { return cached_0; } String ret = delegate.key(); cached_0 = ret; return ret; }
/** * Like {@link io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord#addHeader} but with a key/value pair * @param key * @param value * @return */ public io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord<K, V> addHeader(String key, String value) { delegate.addHeader(key, value); return this; }
/** * @return the partition to which the record will be sent (or null if no partition was specified) */ public Integer partition() { Integer ret = delegate.partition(); return ret; }
/** * @return the topic this record is being sent to */ public String topic() { String ret = delegate.topic(); return ret; }
/** * Get the partition metadata for the give topic. * @param topic topic partition for which getting partitions info * @param handler handler called on operation completed * @return current KafkaProducer instance */ public io.vertx.rxjava.kafka.client.producer.KafkaProducer<K, V> partitionsFor(String topic, Handler<AsyncResult<List<PartitionInfo>>> handler) { delegate.partitionsFor(topic, handler); return this; }
/** * @return the timestamp of this record */ public Long timestamp() { Long ret = delegate.timestamp(); return ret; }
/** * Invoking this method makes all buffered records immediately available to write * @param completionHandler handler called on operation completed * @return current KafkaProducer instance */ public io.vertx.rxjava.kafka.client.producer.KafkaProducer<K, V> flush(Handler<Void> completionHandler) { delegate.flush(completionHandler); return this; }
public io.vertx.rxjava.kafka.client.producer.KafkaProducer<K, V> setWriteQueueMaxSize(int i) { delegate.setWriteQueueMaxSize(i); return this; }
/** * Close the producer */ public void close() { delegate.close(); }
/** * @return the buffer key */ public String key() { if (cached_0 != null) { return cached_0; } String ret = delegate.key(); cached_0 = ret; return ret; }
/** * Like {@link io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord#addHeader} but with a key/value pair * @param key * @param value * @return */ public io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord<K, V> addHeader(String key, String value) { delegate.addHeader(key, value); return this; }
/** * @return the partition to which the record will be sent (or null if no partition was specified) */ public Integer partition() { Integer ret = delegate.partition(); return ret; }
/** * @return the topic this record is being sent to */ public String topic() { String ret = delegate.topic(); return ret; }
/** * @return the timestamp of this record */ public Long timestamp() { Long ret = delegate.timestamp(); return ret; }
/** * Close the producer * @param timeout timeout to wait for closing * @param completionHandler handler called on operation completed */ public void close(long timeout, Handler<AsyncResult<Void>> completionHandler) { delegate.close(timeout, completionHandler); }
/** * Close the producer * @param timeout timeout to wait for closing * @param completionHandler handler called on operation completed */ public void close(long timeout, Handler<AsyncResult<Void>> completionHandler) { delegate.close(timeout, completionHandler); }