Azure Eventhub is changing the date from at consumer side

Sanjay Godiya 0 Reputation points
2025-01-30T08:43:24.6866667+00:00

Hi Community,

I am pretty new on Azure and able to build Azure Eventhub producer-consumer application in Java SpringBoot with the help of documentations but I am facing an issue with Eventhub communication, I am sending a message from producer using Java SpringBoot microservice and consuming it in a different Java SpringBoot microservice. At consumer side, I found date format in JSON message is converted into int array. Similarly, int value is getting changed to float.

If anyone faced such issue and able to resolve it, looking forward for suggestions.

Producer Message:
Example 1
{
"id" : 1,
"name" : "Hello World",
"date" : "2025-01-30T10:05:23.6068323"
}

Example 2

{

"score" : 400

}

Consumer Message:

Example 1
{
"id" : 1,
"name" : "Hello World",
"date" : [2025, 01, 30, 10, 05, 23, 6068323]
}

Example 2

{

"score" : 400.0

}

Thanks,

Sanjay

Azure Event Hubs
Azure Event Hubs
An Azure real-time data ingestion service.
685 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Chandra Boorla 7,490 Reputation points Microsoft Vendor
    2025-01-30T20:12:52.56+00:00

    Hi @Sanjay Godiya

    Greetings & Welcome to Microsoft Q&A forum! Thanks for posting your query!

    The issue you're facing with the date format being converted into an int array and the int value changing to float at the consumer side may be related to how the data is serialized and deserialized between the producer and consumer applications.

    In Azure Event Hubs, when sending events, the event body is treated as a sequence of bytes. The interpretation of this byte sequence happens within the application code. If the producer is serializing the JSON message in a specific way, the consumer must deserialize it correctly to maintain the intended data types.

    For example, when using JSON, the construction and interpretation of the JSON string should be handled at the application level. If the consumer is not correctly interpreting the incoming byte sequence as JSON, it may result in unexpected types, such as an array for dates or a float for integers.

    For more details, please refer: Exchange events between consumers and producers that use different protocols: AMQP, Kafka, and HTTPS

    Here are some steps and considerations to help you resolve the issue:

    Consistent Serialization/Deserialization - Ensure that both the producer and consumer use the same libraries and methods for serialization and deserialization. For JSON, libraries such as json in Python, Json.NET in C#, or Jackson in Java are commonly used.

    Explicit Data Formats - When serializing data, explicitly define the format for dates and numeric values. For instance, ISO 8601 is a standard format for dates in JSON. Ensure that numeric values are serialized in a way that matches the expected type on the consumer side. For example, if you're dealing with integers, make sure they're not inadvertently being serialized as floating-point numbers.

    Schema Validation - Consider using a schema definition (like JSON Schema) to validate the structure and data types of your JSON messages. This can help ensure that both producer and consumer agree on the expected data format.

    Handling Byte Sequences - Remember that Azure Event Hubs treats message bodies as byte sequences. Ensure that the consumer correctly decodes these byte sequences back into the intended string or JSON object. Use UTF-8 encoding when converting strings to byte sequences and vice versa, as this is the standard encoding for JSON.

    By carefully managing how data is serialized and deserialized, you can prevent issues with data type conversions in your Azure Event Hubs applications.

    I hope this information helps. Please do let us know if you have any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

    Thank you.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.