Search in sources :

Example 1 with InstantSerializer

use of org.apache.beam.sdk.io.kafka.serialization.InstantSerializer in project beam by apache.

the class ResumeFromCheckpointStreamingTest method produce.

private static void produce(Map<String, Instant> messages) {
    Properties producerProps = new Properties();
    producerProps.putAll(EMBEDDED_KAFKA_CLUSTER.getProps());
    producerProps.put("request.required.acks", 1);
    producerProps.put("bootstrap.servers", EMBEDDED_KAFKA_CLUSTER.getBrokerList());
    Serializer<String> stringSerializer = new StringSerializer();
    Serializer<Instant> instantSerializer = new InstantSerializer();
    try (@SuppressWarnings("unchecked") KafkaProducer<String, Instant> kafkaProducer = new KafkaProducer(producerProps, stringSerializer, instantSerializer)) {
        for (Map.Entry<String, Instant> en : messages.entrySet()) {
            kafkaProducer.send(new ProducerRecord<>(TOPIC, en.getKey(), en.getValue()));
        }
        kafkaProducer.close();
    }
}
Also used : KafkaProducer(org.apache.kafka.clients.producer.KafkaProducer) InstantSerializer(org.apache.beam.sdk.io.kafka.serialization.InstantSerializer) Instant(org.joda.time.Instant) Properties(java.util.Properties) StringSerializer(org.apache.kafka.common.serialization.StringSerializer) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 InstantSerializer (org.apache.beam.sdk.io.kafka.serialization.InstantSerializer)1 KafkaProducer (org.apache.kafka.clients.producer.KafkaProducer)1 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)1 Instant (org.joda.time.Instant)1