How-To exchange events between applications using different protocols
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:
For the AMQP side, both Java and .NET provide built-in ways to convert strings to and from UTF-8 byte sequences. The Microsoft AMQP clients represent events as a class named EventData.
Java AMPQ UTF-8 string producer
Java AMPQ UTF-8 string consumer