org.apache.kafka.common.serialization.DoubleDeserializer Java Examples
The following examples show how to use
org.apache.kafka.common.serialization.DoubleDeserializer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DataLoaderConfig.java From kafka-webview with MIT License | 6 votes |
/** * Creates default message formats. */ private void createDefaultMessageFormats() { final Map<String, String> defaultFormats = new HashMap<>(); defaultFormats.put("Short", ShortDeserializer.class.getName()); defaultFormats.put("ByteArray", ByteArrayDeserializer.class.getName()); defaultFormats.put("Bytes", BytesDeserializer.class.getName()); defaultFormats.put("Double", DoubleDeserializer.class.getName()); defaultFormats.put("Float", FloatDeserializer.class.getName()); defaultFormats.put("Integer", IntegerDeserializer.class.getName()); defaultFormats.put("Long", LongDeserializer.class.getName()); defaultFormats.put("String", StringDeserializer.class.getName()); defaultFormats.put("Bytes (Hex Encoded)", BytesToHexDeserializer.class.getName()); // Create if needed. for (final Map.Entry<String, String> entry : defaultFormats.entrySet()) { MessageFormat messageFormat = messageFormatRepository.findByName(entry.getKey()); if (messageFormat == null) { messageFormat = new MessageFormat(); } messageFormat.setName(entry.getKey()); messageFormat.setClasspath(entry.getValue()); messageFormat.setJar("n/a"); messageFormat.setDefaultFormat(true); messageFormatRepository.save(messageFormat); } }
Example #2
Source File: KafkaProducerInterceptorWrapper.java From pulsar with Apache License 2.0 | 6 votes |
static Deserializer getDeserializer(Serializer serializer) { if (serializer instanceof StringSerializer) { return new StringDeserializer(); } else if (serializer instanceof LongSerializer) { return new LongDeserializer(); } else if (serializer instanceof IntegerSerializer) { return new IntegerDeserializer(); } else if (serializer instanceof DoubleSerializer) { return new DoubleDeserializer(); } else if (serializer instanceof BytesSerializer) { return new BytesDeserializer(); } else if (serializer instanceof ByteBufferSerializer) { return new ByteBufferDeserializer(); } else if (serializer instanceof ByteArraySerializer) { return new ByteArrayDeserializer(); } else { throw new IllegalArgumentException(serializer.getClass().getName() + " is not a valid or supported subclass of org.apache.kafka.common.serialization.Serializer."); } }
Example #3
Source File: KafkaProducerInterceptorWrapperTest.java From pulsar with Apache License 2.0 | 6 votes |
@DataProvider(name = "serializers") public Object[][] serializers() { return new Object[][] { { new StringSerializer(), StringDeserializer.class }, { new LongSerializer(), LongDeserializer.class }, { new IntegerSerializer(), IntegerDeserializer.class, }, { new DoubleSerializer(), DoubleDeserializer.class, }, { new BytesSerializer(), BytesDeserializer.class }, { new ByteBufferSerializer(), ByteBufferDeserializer.class }, { new ByteArraySerializer(), ByteArrayDeserializer.class } }; }
Example #4
Source File: RunningAverageTest.java From kafka-tutorials with Apache License 2.0 | 5 votes |
@Test public void validateAverageRating() { TestInputTopic<Long, Rating> inputTopic = testDriver.createInputTopic(RATINGS_TOPIC_NAME, new LongSerializer(), ratingSpecificAvroSerde.serializer()); inputTopic.pipeKeyValueList(asList( new KeyValue<>(LETHAL_WEAPON_RATING_8.getMovieId(), LETHAL_WEAPON_RATING_8), new KeyValue<>(LETHAL_WEAPON_RATING_10.getMovieId(), LETHAL_WEAPON_RATING_10) )); final TestOutputTopic<Long, Double> outputTopic = testDriver.createOutputTopic(AVERAGE_RATINGS_TOPIC_NAME, new LongDeserializer(), new DoubleDeserializer()); final List<KeyValue<Long, Double>> keyValues = outputTopic.readKeyValuesToList(); // I sent two records to input topic // I expect second record in topic will contain correct result final KeyValue<Long, Double> longDoubleKeyValue = keyValues.get(1); System.out.println("longDoubleKeyValue = " + longDoubleKeyValue); assertThat(longDoubleKeyValue, equalTo(new KeyValue<>(362L, 9.0))); final KeyValueStore<Long, Double> keyValueStore = testDriver.getKeyValueStore("average-ratings"); final Double expected = keyValueStore.get(362L); Assert.assertEquals("Message", expected, 9.0, 0.0); }
Example #5
Source File: KafkaUsage.java From smallrye-reactive-messaging with Apache License 2.0 | 5 votes |
private void consumeDoubles(BooleanSupplier continuation, Runnable completion, Collection<String> topics, Consumer<ConsumerRecord<String, Double>> consumerFunction) { Deserializer<String> keyDes = new StringDeserializer(); Deserializer<Double> valDes = new DoubleDeserializer(); String randomId = UUID.randomUUID().toString(); this.consume(randomId, randomId, OffsetResetStrategy.EARLIEST, keyDes, valDes, continuation, null, completion, topics, consumerFunction); }
Example #6
Source File: DemoConsumerManualCommit.java From KafkaExample with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { args = new String[] { "kafka0:19092", "gender-amount", "group4", "consumer2" }; if (args == null || args.length != 4) { System.err.println( "Usage:\n\tjava -jar kafka_consumer.jar ${bootstrap_server} ${topic_name} ${group_name} ${client_id}"); System.exit(1); } String bootstrap = args[0]; String topic = args[1]; String groupid = args[2]; String clientid = args[3]; Properties props = new Properties(); props.put("bootstrap.servers", bootstrap); props.put("group.id", groupid); props.put("enable.auto.commit", "false"); props.put("key.deserializer", StringDeserializer.class.getName()); props.put("value.deserializer", DoubleDeserializer.class.getName()); props.put("max.poll.interval.ms", "300000"); props.put("max.poll.records", "500"); props.put("auto.offset.reset", "earliest"); KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props); consumer.subscribe(Arrays.asList(topic)); AtomicLong atomicLong = new AtomicLong(); while (true) { ConsumerRecords<String, String> records = consumer.poll(100); records.forEach(record -> { System.out.printf("client : %s , topic: %s , partition: %d , offset = %d, key = %s, value = %s%n", clientid, record.topic(), record.partition(), record.offset(), record.key(), record.value()); if (atomicLong.get() % 10 == 0) { // consumer.commitSync(); } }); } }