0

I want to check some constraints on messages and "canonicalize" them accordingly on the way to the final consumer.

I need to listen to any event of any type , load the rules (based on the type of the message) from IoC apply changes to the messages and let all of them pass.

Am I in a true rode? Am I allowed to change the messages in the middleware or I should do the following steps?

  1. Listen to the events
  2. Create commands
  3. Send them
  4. Handle the commands(apply the rules by the consumer)
  5. Create new events from the changed messages
  6. And finally publish new events from them
Alexey Zimarev
  • 17,944
  • 2
  • 55
  • 83
Mohsen
  • 4,000
  • 8
  • 42
  • 73
  • It depends on your design but you can update stuff in your middleware if you want. I probably wouldn't do it but I don't understand your problem so I cannot advise accordingly. – Alexey Zimarev Nov 04 '17 at 17:00
  • @Alexey Zimarev:I have some stored data. The data is published as events which should be processed by multiple middlewares in order to be ready as "read models" (which finally will be created by some sagas), Some regex rules should be applied to them on their way to the next stage.The events can get the read model before "canonicalization" and the read models should update themselves in the final destination after "canonicalization" reactively. I want this middleware to be configurable as a separate microservice (and potentially on a separate machine). – Mohsen Nov 06 '17 at 05:38
  • @Alexey Zimarev:The order of rules is not important. I don't want to hard code the event types in consumers because the event types might change frequently so I guess the rules would be better to be injected as `IConsumer` plugins into the middleware and let an `IOC` take care of them.Thank you – Mohsen Nov 06 '17 at 05:44
  • @Alexey Zimarev:The rules example : If string starts with 'c' replace the 'c' with 'd'. So I guess the `Consume` method can be a pure function which returns another instance of the same event type. – Mohsen Nov 06 '17 at 05:59
  • 1
    It is completely up to you to do it as a middleware or as a message pipeline via consumers. Middleware is a completely legit way to do it. Hence that serialisation is also middleware. – Alexey Zimarev Nov 06 '17 at 08:01
  • @Alexey Zimarev: One more thing is that I want the middle ware to be an independent unit of deployment. – Mohsen Nov 06 '17 at 09:52

0 Answers0