/*
 * Copyright 2014 Red Hat, Inc.
 *
 * Red Hat licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package io.vertx.reactivex.kafka.client.producer;

import java.util.Map;
import io.reactivex.Observable;
import io.reactivex.Flowable;
import io.reactivex.Single;
import io.reactivex.Completable;
import io.reactivex.Maybe;
import io.vertx.kafka.client.producer.RecordMetadata;
import io.vertx.kafka.client.common.PartitionInfo;
import java.util.List;
import java.util.Map;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;

Vert.x Kafka producer.

The provides global control over writing a record.

NOTE: This class has been automatically generated from the original non RX-ified interface using Vert.x codegen.
/** * Vert.x Kafka producer. * <p> * The provides global control over writing a record. * * <p/> * NOTE: This class has been automatically generated from the {@link io.vertx.kafka.client.producer.KafkaProducer original} non RX-ified interface using Vert.x codegen. */
@io.vertx.lang.rx.RxGen(io.vertx.kafka.client.producer.KafkaProducer.class) public class KafkaProducer<K,V> implements io.vertx.reactivex.core.streams.WriteStream<io.vertx.reactivex.kafka.client.producer.KafkaProducerRecord<K, V>> { @Override public String toString() { return delegate.toString(); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; KafkaProducer that = (KafkaProducer) o; return delegate.equals(that.delegate); } @Override public int hashCode() { return delegate.hashCode(); } public static final io.vertx.lang.rx.TypeArg<KafkaProducer> __TYPE_ARG = new io.vertx.lang.rx.TypeArg<>( obj -> new KafkaProducer((io.vertx.kafka.client.producer.KafkaProducer) obj), KafkaProducer::getDelegate ); private final io.vertx.kafka.client.producer.KafkaProducer<K,V> delegate; public final io.vertx.lang.rx.TypeArg<K> __typeArg_0; public final io.vertx.lang.rx.TypeArg<V> __typeArg_1; public KafkaProducer(io.vertx.kafka.client.producer.KafkaProducer delegate) { this.delegate = delegate; this.__typeArg_0 = io.vertx.lang.rx.TypeArg.unknown(); this.__typeArg_1 = io.vertx.lang.rx.TypeArg.unknown(); } public KafkaProducer(io.vertx.kafka.client.producer.KafkaProducer delegate, io.vertx.lang.rx.TypeArg<K> typeArg_0, io.vertx.lang.rx.TypeArg<V> typeArg_1) { this.delegate = delegate; this.__typeArg_0 = typeArg_0; this.__typeArg_1 = typeArg_1; } public io.vertx.kafka.client.producer.KafkaProducer getDelegate() { return delegate; } private io.vertx.reactivex.WriteStreamObserver<io.vertx.reactivex.kafka.client.producer.KafkaProducerRecord<K, V>> observer; private io.vertx.reactivex.WriteStreamSubscriber<io.vertx.reactivex.kafka.client.producer.KafkaProducerRecord<K, V>> subscriber; public synchronized io.vertx.reactivex.WriteStreamObserver<io.vertx.reactivex.kafka.client.producer.KafkaProducerRecord<K, V>> toObserver() { if (observer == null) { java.util.function.Function<io.vertx.reactivex.kafka.client.producer.KafkaProducerRecord, io.vertx.kafka.client.producer.KafkaProducerRecord<K,V>> conv = io.vertx.reactivex.kafka.client.producer.KafkaProducerRecord<K, V>::getDelegate; observer = io.vertx.reactivex.RxHelper.toObserver(getDelegate(), conv); } return observer; } public synchronized io.vertx.reactivex.WriteStreamSubscriber<io.vertx.reactivex.kafka.client.producer.KafkaProducerRecord<K, V>> toSubscriber() { if (subscriber == null) { java.util.function.Function<io.vertx.reactivex.kafka.client.producer.KafkaProducerRecord, io.vertx.kafka.client.producer.KafkaProducerRecord<K,V>> conv = io.vertx.reactivex.kafka.client.producer.KafkaProducerRecord<K, V>::getDelegate; subscriber = io.vertx.reactivex.RxHelper.toSubscriber(getDelegate(), conv); } return subscriber; }
Ends the stream.

Once the stream has ended, it cannot be used any more.

/** * Ends the stream. * <p> * Once the stream has ended, it cannot be used any more. */
public void end() { delegate.end(); }
Same as WriteStream.end but with an handler called when the operation completes
Params:
  • handler –
/** * Same as {@link io.vertx.reactivex.core.streams.WriteStream#end} but with an <code>handler</code> called when the operation completes * @param handler */
public void end(Handler<AsyncResult<Void>> handler) { delegate.end(handler); }
Same as WriteStream.end but with an handler called when the operation completes
Returns:
/** * Same as {@link io.vertx.reactivex.core.streams.WriteStream#end} but with an <code>handler</code> called when the operation completes * @return */
public Completable rxEnd() { return io.vertx.reactivex.impl.AsyncResultCompletable.toCompletable(handler -> { end(handler); }); }
Same as WriteStream.end but writes some data to the stream before ending.
Params:
  • data – the data to write
/** * Same as {@link io.vertx.reactivex.core.streams.WriteStream#end} but writes some data to the stream before ending. * @param data the data to write */
public void end(io.vertx.reactivex.kafka.client.producer.KafkaProducerRecord<K, V> data) { delegate.end(data.getDelegate()); }
Same as but with an handler called when the operation completes
Params:
  • data –
  • handler –
/** * Same as but with an <code>handler</code> called when the operation completes * @param data * @param handler */
public void end(io.vertx.reactivex.kafka.client.producer.KafkaProducerRecord<K, V> data, Handler<AsyncResult<Void>> handler) { delegate.end(data.getDelegate(), handler); }
Same as but with an handler called when the operation completes
Params:
  • data –
Returns:
/** * Same as but with an <code>handler</code> called when the operation completes * @param data * @return */
public Completable rxEnd(io.vertx.reactivex.kafka.client.producer.KafkaProducerRecord<K, V> data) { return io.vertx.reactivex.impl.AsyncResultCompletable.toCompletable(handler -> { end(data, handler); }); }
Get or create a KafkaProducer instance which shares its stream with any other KafkaProducer created with the same name
Params:
  • vertx – Vert.x instance to use
  • name – the producer name to identify it
  • config – Kafka producer configuration
Returns:an instance of the KafkaProducer
/** * Get or create a KafkaProducer instance which shares its stream with any other KafkaProducer created with the same <code>name</code> * @param vertx Vert.x instance to use * @param name the producer name to identify it * @param config Kafka producer configuration * @return an instance of the KafkaProducer */
public static <K, V> io.vertx.reactivex.kafka.client.producer.KafkaProducer<K, V> createShared(io.vertx.reactivex.core.Vertx vertx, String name, Map<String, String> config) { io.vertx.reactivex.kafka.client.producer.KafkaProducer<K, V> ret = io.vertx.reactivex.kafka.client.producer.KafkaProducer.newInstance(io.vertx.kafka.client.producer.KafkaProducer.createShared(vertx.getDelegate(), name, config), io.vertx.lang.rx.TypeArg.unknown(), io.vertx.lang.rx.TypeArg.unknown()); return ret; }
Get or create a KafkaProducer instance which shares its stream with any other KafkaProducer created with the same name
Params:
  • vertx – Vert.x instance to use
  • name – the producer name to identify it
  • config – Kafka producer configuration
  • keyType – class type for the key serialization
  • valueType – class type for the value serialization
Returns:an instance of the KafkaProducer
/** * Get or create a KafkaProducer instance which shares its stream with any other KafkaProducer created with the same <code>name</code> * @param vertx Vert.x instance to use * @param name the producer name to identify it * @param config Kafka producer configuration * @param keyType class type for the key serialization * @param valueType class type for the value serialization * @return an instance of the KafkaProducer */
public static <K, V> io.vertx.reactivex.kafka.client.producer.KafkaProducer<K, V> createShared(io.vertx.reactivex.core.Vertx vertx, String name, Map<String, String> config, Class<K> keyType, Class<V> valueType) { io.vertx.reactivex.kafka.client.producer.KafkaProducer<K, V> ret = io.vertx.reactivex.kafka.client.producer.KafkaProducer.newInstance(io.vertx.kafka.client.producer.KafkaProducer.createShared(vertx.getDelegate(), name, config, io.vertx.lang.reactivex.Helper.unwrap(keyType), io.vertx.lang.reactivex.Helper.unwrap(valueType)), io.vertx.lang.rx.TypeArg.of(keyType), io.vertx.lang.rx.TypeArg.of(valueType)); return ret; }
Create a new KafkaProducer instance
Params:
  • vertx – Vert.x instance to use
  • config – Kafka producer configuration
Returns:an instance of the KafkaProducer
/** * Create a new KafkaProducer instance * @param vertx Vert.x instance to use * @param config Kafka producer configuration * @return an instance of the KafkaProducer */
public static <K, V> io.vertx.reactivex.kafka.client.producer.KafkaProducer<K, V> create(io.vertx.reactivex.core.Vertx vertx, Map<String, String> config) { io.vertx.reactivex.kafka.client.producer.KafkaProducer<K, V> ret = io.vertx.reactivex.kafka.client.producer.KafkaProducer.newInstance(io.vertx.kafka.client.producer.KafkaProducer.create(vertx.getDelegate(), config), io.vertx.lang.rx.TypeArg.unknown(), io.vertx.lang.rx.TypeArg.unknown()); return ret; }
Create a new KafkaProducer instance
Params:
  • vertx – Vert.x instance to use
  • config – Kafka producer configuration
  • keyType – class type for the key serialization
  • valueType – class type for the value serialization
Returns:an instance of the KafkaProducer
/** * Create a new KafkaProducer instance * @param vertx Vert.x instance to use * @param config Kafka producer configuration * @param keyType class type for the key serialization * @param valueType class type for the value serialization * @return an instance of the KafkaProducer */
public static <K, V> io.vertx.reactivex.kafka.client.producer.KafkaProducer<K, V> create(io.vertx.reactivex.core.Vertx vertx, Map<String, String> config, Class<K> keyType, Class<V> valueType) { io.vertx.reactivex.kafka.client.producer.KafkaProducer<K, V> ret = io.vertx.reactivex.kafka.client.producer.KafkaProducer.newInstance(io.vertx.kafka.client.producer.KafkaProducer.create(vertx.getDelegate(), config, io.vertx.lang.reactivex.Helper.unwrap(keyType), io.vertx.lang.reactivex.Helper.unwrap(valueType)), io.vertx.lang.rx.TypeArg.of(keyType), io.vertx.lang.rx.TypeArg.of(valueType)); return ret; } public io.vertx.reactivex.kafka.client.producer.KafkaProducer<K, V> exceptionHandler(Handler<Throwable> handler) { delegate.exceptionHandler(handler); return this; } public io.vertx.reactivex.kafka.client.producer.KafkaProducer<K, V> write(io.vertx.reactivex.kafka.client.producer.KafkaProducerRecord<K, V> kafkaProducerRecord) { delegate.write(kafkaProducerRecord.getDelegate()); return this; } public io.vertx.reactivex.kafka.client.producer.KafkaProducer<K, V> setWriteQueueMaxSize(int i) { delegate.setWriteQueueMaxSize(i); return this; } public boolean writeQueueFull() { boolean ret = delegate.writeQueueFull(); return ret; } public io.vertx.reactivex.kafka.client.producer.KafkaProducer<K, V> drainHandler(Handler<Void> handler) { delegate.drainHandler(handler); return this; } public io.vertx.reactivex.kafka.client.producer.KafkaProducer<K, V> write(io.vertx.reactivex.kafka.client.producer.KafkaProducerRecord<K, V> data, Handler<AsyncResult<Void>> handler) { delegate.write(data.getDelegate(), handler); return this; } public Completable rxWrite(io.vertx.reactivex.kafka.client.producer.KafkaProducerRecord<K, V> data) { return io.vertx.reactivex.impl.AsyncResultCompletable.toCompletable(handler -> { write(data, handler); }); }
Asynchronously write a record to a topic
Params:
  • record – record to write
Returns:current KafkaWriteStream instance
/** * Asynchronously write a record to a topic * @param record record to write * @return current KafkaWriteStream instance */
public io.vertx.reactivex.kafka.client.producer.KafkaProducer<K, V> send(io.vertx.reactivex.kafka.client.producer.KafkaProducerRecord<K, V> record) { delegate.send(record.getDelegate()); return this; }
Asynchronously write a record to a topic
Params:
  • record – record to write
  • handler – handler called on operation completed
Returns:current KafkaWriteStream instance
/** * Asynchronously write a record to a topic * @param record record to write * @param handler handler called on operation completed * @return current KafkaWriteStream instance */
public io.vertx.reactivex.kafka.client.producer.KafkaProducer<K, V> send(io.vertx.reactivex.kafka.client.producer.KafkaProducerRecord<K, V> record, Handler<AsyncResult<RecordMetadata>> handler) { delegate.send(record.getDelegate(), handler); return this; }
Asynchronously write a record to a topic
Params:
  • record – record to write
Returns:current KafkaWriteStream instance
/** * Asynchronously write a record to a topic * @param record record to write * @return current KafkaWriteStream instance */
public Single<RecordMetadata> rxSend(io.vertx.reactivex.kafka.client.producer.KafkaProducerRecord<K, V> record) { return io.vertx.reactivex.impl.AsyncResultSingle.toSingle(handler -> { send(record, handler); }); }
Get the partition metadata for the give topic.
Params:
  • topic – topic partition for which getting partitions info
  • handler – handler called on operation completed
Returns:current KafkaProducer instance
/** * 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.reactivex.kafka.client.producer.KafkaProducer<K, V> partitionsFor(String topic, Handler<AsyncResult<List<PartitionInfo>>> handler) { delegate.partitionsFor(topic, handler); return this; }
Get the partition metadata for the give topic.
Params:
  • topic – topic partition for which getting partitions info
Returns:current KafkaProducer instance
/** * Get the partition metadata for the give topic. * @param topic topic partition for which getting partitions info * @return current KafkaProducer instance */
public Single<List<PartitionInfo>> rxPartitionsFor(String topic) { return io.vertx.reactivex.impl.AsyncResultSingle.toSingle(handler -> { partitionsFor(topic, handler); }); }
Invoking this method makes all buffered records immediately available to write
Params:
  • completionHandler – handler called on operation completed
Returns:current KafkaProducer instance
/** * 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.reactivex.kafka.client.producer.KafkaProducer<K, V> flush(Handler<Void> completionHandler) { delegate.flush(completionHandler); return this; }
Close the producer
/** * Close the producer */
public void close() { delegate.close(); }
Close the producer
Params:
  • completionHandler – handler called on operation completed
/** * Close the producer * @param completionHandler handler called on operation completed */
public void close(Handler<AsyncResult<Void>> completionHandler) { delegate.close(completionHandler); }
Close the producer
Returns:
/** * Close the producer * @return */
public Completable rxClose() { return io.vertx.reactivex.impl.AsyncResultCompletable.toCompletable(handler -> { close(handler); }); }
Close the producer
Params:
  • timeout – timeout to wait for closing
  • completionHandler – handler called on operation completed
/** * 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
Params:
  • timeout – timeout to wait for closing
Returns:
/** * Close the producer * @param timeout timeout to wait for closing * @return */
public Completable rxClose(long timeout) { return io.vertx.reactivex.impl.AsyncResultCompletable.toCompletable(handler -> { close(timeout, handler); }); } public static <K,V>KafkaProducer<K,V> newInstance(io.vertx.kafka.client.producer.KafkaProducer arg) { return arg != null ? new KafkaProducer<K,V>(arg) : null; } public static <K,V>KafkaProducer<K,V> newInstance(io.vertx.kafka.client.producer.KafkaProducer arg, io.vertx.lang.rx.TypeArg<K> __typeArg_K, io.vertx.lang.rx.TypeArg<V> __typeArg_V) { return arg != null ? new KafkaProducer<K,V>(arg, __typeArg_K, __typeArg_V) : null; } }