Search in sources :

Example 1 with BytesSerializer

use of org.apache.kafka.common.serialization.BytesSerializer in project flink by apache.

the class KafkaContainerClient method sendMessages.

public <T> void sendMessages(String topic, Serializer<T> valueSerializer, T... messages) {
    Properties props = new Properties();
    props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, container.getBootstrapServers());
    props.put(ProducerConfig.ACKS_CONFIG, "all");
    try (Producer<Bytes, T> producer = new KafkaProducer<>(props, new BytesSerializer(), valueSerializer)) {
        for (T message : messages) {
            producer.send(new ProducerRecord<>(topic, message));
        }
    }
}
Also used : KafkaProducer(org.apache.kafka.clients.producer.KafkaProducer) Bytes(org.apache.kafka.common.utils.Bytes) BytesSerializer(org.apache.kafka.common.serialization.BytesSerializer) Properties(java.util.Properties)

Aggregations

Properties (java.util.Properties)1 KafkaProducer (org.apache.kafka.clients.producer.KafkaProducer)1 BytesSerializer (org.apache.kafka.common.serialization.BytesSerializer)1 Bytes (org.apache.kafka.common.utils.Bytes)1