You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+49Lines changed: 49 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -226,6 +226,55 @@ val kafkaConfig = KafkaTransportConfig(
226
226
}
227
227
```
228
228
229
+
## MessageRegistry & Message Serialization
230
+
231
+
The **MessageRegistry** is a core component of KCommand that provides a centralized mechanism for registering message types along with their corresponding serializers. This allows the system to automatically handle the (de)serialization of messages across different transports without requiring manual conversion for each message type.
232
+
233
+
### Key Features
234
+
235
+
-**Type Safety:** By registering each message type (typically using Kotlinx.serialization), you ensure that only known and supported message types are processed.
236
+
-**Polymorphic Serialization:** When using sealed classes or polymorphic hierarchies, the MessageRegistry enables correct serialization/deserialization by associating a unique identifier (or type name) with each subtype.
237
+
-**Centralized Configuration:** Instead of scattering serialization logic across your application, the MessageRegistry consolidates it, making it easier to update or extend the supported message types.
238
+
239
+
### How It Works
240
+
241
+
1.**Register Message Types:** The user defines and registers each message type with a unique identifier and its corresponding serializer.
242
+
2.**Lookup at Runtime:** When a message is sent or received, the registry is used to look up the correct serializer based on the message’s type.
243
+
3.**Integration with Transports:** Transports use the registry to convert messages to/from their serialized (typically JSON) form before sending to or after receiving from remote systems.
244
+
245
+
### Example
246
+
247
+
Below is an example of how to define a sealed class for messages and register its subtypes in the MessageRegistry:
0 commit comments