Azure Event Hubs supports three protocols for consumers and producers: AMQP, Kafka, and HTTPS : Azure Event Hubs - Exchange events using different protocols - Azure Event Hubs | Microsoft Docs
Event Body
All of the Microsoft AMQP clients represent the event body as an uninterpreted bag of bytes.
Kafka byte[] producer
final Properties properties = new Properties(); // add other properties properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, ByteArraySerializer.class.getName()); final KafkaProducer<Long, byte[]> producer = new KafkaProducer<Long, byte[]>(properties); final byte[] eventBody = new byte[] { 0x01, 0x02, 0x03, 0x04 }; ProducerRecord<Long, byte[]> pr = new ProducerRecord<Long, byte[]>(myTopic, myPartitionId, myTimeStamp, eventBody);
Kafka byte[] consumer
final Properties properties = new Properties(); // add other properties properties.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, ByteArrayDeserializer.class.getName()); final KafkaConsumer<Long, byte[]> consumer = new KafkaConsumer<Long, byte[]>(properties); ConsumerRecord<Long, byte[]> cr = /* receive event */ // cr.value() is a byte[] with values { 0x01, 0x02, 0x03, 0x04 }
Kafka UTF-8 string producer
The Kafka producer or consumer can take advantage of the provided StringSerializer as shown in the following code:
final Properties properties = new Properties(); // add other properties properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName()); final KafkaProducer<Long, String> producer = new KafkaProducer<Long, String>(properties); final String exampleJson = "{\"name\":\"John\", \"number\":9001}"; ProducerRecord<Long, String> pr = new ProducerRecord<Long, String>(myTopic, myPartitionId, myTimeStamp, exampleJson);
Kafka UTF-8 string consumer
The Kafka producer or consumer can take advantage of the provided StringDeSerializer as shown in the following code:
final Properties properties = new Properties(); // add other properties properties.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName()); final KafkaConsumer<Long, String> consumer = new KafkaConsumer<Long, String>(properties); ConsumerRecord<Long, Bytes> cr = /* receive event */ final String receivedJson = cr.value();