I have a situation where I need applications to send messages to a message broker. Another client listening to the broker must then consume messages off the queue, determine what type of message they are, and pass the message off to the appropriate handler.
For instance if a Fizz
POJO is serialized as JSON and then sent to the broker, the other process must consume it, deserialize it from JSON back into a Fizz
instance, and then know to pass the Fizz
off to a FizzHandler
processor. Same for a Buzz
message: it should be deserialized back into a Buzz
and sent to the BuzzHandler
, etc.
I believe the pseudo-code for the route should look something like this:
from(broker)
.unmarshal().json(JsonLibrary.Gson)
.dynamicRouter(someMechanismForDeterminingHandler)
I believe a dynamic router is an appropriate processor for this problem, but not being an EIP expert, I may be out of my element.
The two big problems here:
- How could Camel-GSON know that one type of JSON represents a
Fizz
object, whereas another string of JSON represents aBuzz
object? - What EIP/Camel DSL/processor should be used to route the deserialized message off to the correct handler?