public static <K, V>io.vertx.kafka.client.producer.KafkaProducerRecord<java.lang.Object,java.lang.Object> create(io.vertx.kafka.client.producer.KafkaProducerRecord<Object, Object> j_receiver, java.lang.String topic, java.lang.Object value) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.kafka.client.producer.KafkaProducerRecord.create(topic, io.vertx.core.impl.ConversionHelper.toObject(value))); } }
/** * Create a concrete instance of a Vert.x producer record * @param topic the topic this record is being sent to * @param key the key (or null if no key is specified) * @param value the value * @return Vert.x producer record */ public static <K, V> io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord<K, V> create(String topic, K key, V value) { io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord<K, V> ret = io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord.newInstance(io.vertx.kafka.client.producer.KafkaProducerRecord.create(topic, key, value), io.vertx.lang.rx.TypeArg.unknown(), io.vertx.lang.rx.TypeArg.unknown()); return ret; }
/** * Create a concrete instance of a Vert.x producer record * @param topic the topic this record is being sent to * @param value the value * @return Vert.x producer record */ public static <K, V> io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord<K, V> create(String topic, V value) { io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord<K, V> ret = io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord.newInstance(io.vertx.kafka.client.producer.KafkaProducerRecord.create(topic, value), io.vertx.lang.rx.TypeArg.unknown(), io.vertx.lang.rx.TypeArg.unknown()); return ret; }
public static <K, V>io.vertx.kafka.client.producer.KafkaProducerRecord<java.lang.Object,java.lang.Object> create(io.vertx.kafka.client.producer.KafkaProducerRecord<Object, Object> j_receiver, java.lang.String topic, java.lang.Object key, java.lang.Object value, java.lang.Long timestamp, java.lang.Integer partition) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.kafka.client.producer.KafkaProducerRecord.create(topic, io.vertx.core.impl.ConversionHelper.toObject(key), io.vertx.core.impl.ConversionHelper.toObject(value), timestamp, partition)); } public static <K, V>io.vertx.kafka.client.producer.KafkaProducerRecord<java.lang.Object,java.lang.Object> create(io.vertx.kafka.client.producer.KafkaProducerRecord<Object, Object> j_receiver, java.lang.String topic, java.lang.Object key, java.lang.Object value) {
public static <K, V>io.vertx.kafka.client.producer.KafkaProducerRecord<java.lang.Object,java.lang.Object> create(io.vertx.kafka.client.producer.KafkaProducerRecord<Object, Object> j_receiver, java.lang.String topic, java.lang.Object key, java.lang.Object value) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.kafka.client.producer.KafkaProducerRecord.create(topic, io.vertx.core.impl.ConversionHelper.toObject(key), io.vertx.core.impl.ConversionHelper.toObject(value))); } public static <K, V>io.vertx.kafka.client.producer.KafkaProducerRecord<java.lang.Object,java.lang.Object> create(io.vertx.kafka.client.producer.KafkaProducerRecord<Object, Object> j_receiver, java.lang.String topic, java.lang.Object value) {
/** * Create a concrete instance of a Vert.x producer record * @param topic the topic this record is being sent to * @param key the key (or null if no key is specified) * @param value the value * @param timestamp the timestamp of this record * @param partition the partition to which the record will be sent (or null if no partition was specified) * @return Vert.x producer record */ public static <K, V> io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord<K, V> create(String topic, K key, V value, Long timestamp, Integer partition) { io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord<K, V> ret = io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord.newInstance(io.vertx.kafka.client.producer.KafkaProducerRecord.create(topic, key, value, timestamp, partition), io.vertx.lang.rx.TypeArg.unknown(), io.vertx.lang.rx.TypeArg.unknown()); return ret; }
/** * Create a concrete instance of a Vert.x producer record * @param topic the topic this record is being sent to * @param key the key (or null if no key is specified) * @param value the value * @return Vert.x producer record */ public static <K, V> io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord<K, V> create(String topic, K key, V value) { io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord<K, V> ret = io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord.newInstance(io.vertx.kafka.client.producer.KafkaProducerRecord.create(topic, key, value), io.vertx.lang.rx.TypeArg.unknown(), io.vertx.lang.rx.TypeArg.unknown()); return ret; }
/** * Create a concrete instance of a Vert.x producer record * @param topic the topic this record is being sent to * @param value the value * @return Vert.x producer record */ public static <K, V> io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord<K, V> create(String topic, V value) { io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord<K, V> ret = io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord.newInstance(io.vertx.kafka.client.producer.KafkaProducerRecord.create(topic, value), io.vertx.lang.rx.TypeArg.unknown(), io.vertx.lang.rx.TypeArg.unknown()); return ret; }
/** * Create a concrete instance of a Vert.x producer record * @param topic the topic this record is being sent to * @param key the key (or null if no key is specified) * @param value the value * @param timestamp the timestamp of this record * @param partition the partition to which the record will be sent (or null if no partition was specified) * @return Vert.x producer record */ public static <K, V> io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord<K, V> create(String topic, K key, V value, Long timestamp, Integer partition) { io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord<K, V> ret = io.vertx.rxjava.kafka.client.producer.KafkaProducerRecord.newInstance(io.vertx.kafka.client.producer.KafkaProducerRecord.create(topic, key, value, timestamp, partition), io.vertx.lang.rx.TypeArg.unknown(), io.vertx.lang.rx.TypeArg.unknown()); return ret; }
@Test public void testExceptionHandler(TestContext ctx) throws Exception { Async async = ctx.async(); Properties props = new Properties(); props.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092"); props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class); props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class); Date invalidValue = new Date(); KafkaProducer.create(Vertx.vertx(), props). exceptionHandler(exception -> async.complete()). write(KafkaProducerRecord.create("topic", "key", invalidValue)); }
@Test public void testEmptyHeaders() { List<KafkaHeader> kafkaHeaders = KafkaProducerRecord.create("topic", "key", "value").headers(); assertEquals(Collections.emptyList(), kafkaHeaders); }
@Test public void testEmptyHeaders() { List<KafkaHeader> kafkaHeaders = KafkaProducerRecord.create("topic", "key", "value").headers(); assertEquals(Collections.emptyList(), kafkaHeaders); }
@Override public void start() throws Exception { KafkaProducer<String, String> producer = KafkaProducer.create(vertx, config); producerRef.set(producer); producer.write(KafkaProducerRecord.create("the_topic", "the_value"), ctx.asyncAssertSuccess()); } }, ctx.asyncAssertSuccess(id -> {
@Test public void testExceptionHandler(TestContext ctx) throws Exception { Async async = ctx.async(); Properties props = new Properties(); props.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092"); props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class); props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class); Date invalidValue = new Date(); KafkaProducer.create(Vertx.vertx(), props). exceptionHandler(exception -> async.complete()). write(KafkaProducerRecord.create("topic", "key", invalidValue)); }
@Override public void start() throws Exception { KafkaProducer<String, String> producer = KafkaProducer.create(vertx, config); producerRef.set(producer); producer.write(KafkaProducerRecord.create("the_topic", "the_value"), ctx.asyncAssertSuccess()); } }, ctx.asyncAssertSuccess(id -> {
@Override public void start(Future<Void> startFuture) throws Exception { Properties config = new Properties(); config.putAll(context.config().getMap()); KafkaProducer<String, String> producer = KafkaProducer.createShared(vertx, "the-name", config); producer.write(KafkaProducerRecord.create("the_topic", "the_value"), ar -> startFuture.handle(ar.map((Void) null))); } }
@Override public void start(Future<Void> startFuture) throws Exception { Properties config = new Properties(); config.putAll(context.config().getMap()); KafkaProducer<String, String> producer = KafkaProducer.createShared(vertx, "the-name", config); producer.write(KafkaProducerRecord.create("the_topic", "the_value"), ar -> startFuture.handle(ar.map((Void) null))); } }
@Test public void testProducerProduce(TestContext ctx) throws Exception { String topicName = "testProducerProduce"; Properties config = kafkaCluster.useTo().getProducerProperties("testProducerProduce_producer"); config.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class); config.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class); producer = producer(Vertx.vertx(), config); producer.exceptionHandler(ctx::fail); KafkaProducer<String, String> producer = new KafkaProducerImpl<>(this.producer); int numMessages = 100000; for (int i = 0;i < numMessages;i++) { producer.write(KafkaProducerRecord.create(topicName, "key-" + i, "value-" + i, 0) .addHeader("header_key", "header_value-" + i)); } assertReceiveMessages(ctx, topicName, numMessages); }
@Test public void testWriteWithSimulatedError(TestContext ctx) { TestProducerWriteError mock = new TestProducerWriteError(); KafkaProducer<String, String> prod = KafkaProducer.create(vertx, mock); KafkaProducerRecord<String, String> record = KafkaProducerRecord.create("myTopic", "test"); vertx.exceptionHandler(h -> { if(!(h instanceof SimulatedWriteException)) { ctx.fail(h); } }); prod.write(record); } }
@Test public void testWriteWithSimulatedError(TestContext ctx) { TestProducerWriteError mock = new TestProducerWriteError(); KafkaProducer<String, String> prod = KafkaProducer.create(vertx, mock); KafkaProducerRecord<String, String> record = KafkaProducerRecord.create("myTopic", "test"); vertx.exceptionHandler(h -> { if(!(h instanceof SimulatedWriteException)) { ctx.fail(h); } }); prod.write(record); } }