@SuppressWarnings("unchecked") @Override public <T> Codec<T> newCodec(Class<T> objectClass) { return new SerializableCodec(); } }
protected KafkaLogTailer(Codec<M> codec, KafkaNamespace ns, String group, Properties consumerProps) { this.codec = codec; if (NO_CODEC.equals(codec)) { this.decodeCodec = new SerializableCodec<>(); } else { this.decodeCodec = codec; } Objects.requireNonNull(group); this.ns = ns; this.group = group; consumerProps.put(ConsumerConfig.GROUP_ID_CONFIG, ns.getKafkaGroup(group)); consumerProps.put(ConsumerConfig.CLIENT_ID_CONFIG, group + "-" + CONSUMER_CLIENT_ID_SEQUENCE.getAndIncrement()); this.consumer = new KafkaConsumer<>(consumerProps); }
private KafkaLogAppender(Codec<M> codec, KafkaNamespace ns, String name, Properties producerProperties, Properties consumerProperties) { Objects.requireNonNull(codec); this.codec = codec; if (NO_CODEC.equals(codec)) { this.encodingCodec = new SerializableCodec<>(); } else { this.encodingCodec = codec; } this.ns = ns; this.topic = ns.getTopicName(name); this.name = name; this.producerProps = producerProperties; this.consumerProps = consumerProperties; producerProps.setProperty(ProducerConfig.CLIENT_ID_CONFIG, name + "-" + PRODUCER_CLIENT_ID_SEQUENCE.getAndIncrement()); this.producer = new KafkaProducer<>(this.producerProps); this.size = producer.partitionsFor(topic).size(); if (log.isDebugEnabled()) { log.debug(String.format("Created appender: %s on topic: %s with %d partitions", name, topic, size)); } }
@SuppressWarnings("unchecked") protected Codec<Record> getRecordCodec(String codec) { if (codec == null) { return NO_CODEC; } switch (codec) { case "java": return new SerializableCodec<>(); case "avro": return new AvroMessageCodec<>(Record.class); case "avroJson": return new AvroJsonCodec<>(Record.class); case "avroBinary": return new AvroBinaryCodec<>(Record.class); default: throw new IllegalArgumentException("Unknown codec: " + codec); } }