Normalizers
🧪 Normalizers
What is a Normalizer?
A Normalizer is a component that transforms messages between different formats before sending and after receiving. It plays a crucial role in serialization and deserialization—ensuring that messages are properly encoded for transmission and correctly decoded when received.
This is especially helpful when integrating with systems that require specific data formats like Protobuf, Base64, or custom JSON structures.
🧩 Why Use a Normalizer?
You may want to use a custom normalizer to:
Work with binary formats like Protobuf
Encode messages in Base64 or another custom format
Encrypt/decrypt messages
Support custom serialization logic not handled by default JSON
⚙️ Defining a Normalizer
To create a normalizer, implement the MessageNormalizer
interface and decorate the class with @MessagingNormalizer()
.
Example: Base64 Normalizer
🔄 How It Works
Normalize
Called before sending. Converts a message object into a transport-safe string (e.g., Base64).
Denormalize
Called after receiving. Converts the raw string back into a message object.
🎯 Usage Per Channel
You can assign a normalizer per channel in your messaging configuration. This allows different channels to use different formats as needed:
💡 Each channel can use a different normalizer depending on the protocol or service it interacts with.
Summary
normalize()
Transforms message before it’s sent
denormalize()
Parses message after it’s received
Per-channel config
Apply specific format handling per communication channel
Last updated