Event Registry - Validating message structure

Hi

I have a new requirement - to validate the incoming event messages from RabbitMQ against a json-schema or AsyncApi specification. We want to have a central location for our message definitions - and have all servers build/validate messages based on those definitions.

I managed to do so by setting my own Deserializer on my inbound channel - and in that Deserializer - i added the validation of the json against the schema before the Deserialization.

I was wondering if this is the correct solution - or is there a better solution that enables adding a Validator in some place in the pipeline.

Since i’m not experienced working with queues - any advice will be appreciated.
Thanks
Inbal

Hi Inbal

You could also write your own custom RabbitChannelMessageListenerAdapter and do the validation in the onMessage(org.springframework.amqp.core.Message message) method. This gives you the opportunity to do the validation in the very beginning and you will also have access to all the information of the origin message (org.springframework.amqp.core.Message).

Regards,
Simon

Thanks you Simon for the answer
Just had a look at RabbitChannelMessageListenerAdapter a few minutes ago - I agree it might be a better place for my validations - will be trying that
How can i configure flowable to use my adapter instead of the default one ?
For the Deserializer - i could configure it in the channel definition

If you are using Spring Boot you could create your own CustomRabbitChannelDefinitionProcessor bean which extends the RabbitChannelDefinitionProcessor and overrides createMessageListener(...).

Thanks again for answering Simon
Will be trying that solution