Today I pushed a new feature of Postal.NET: composition. What is this? Well, think of it as (very) lightweight sagas; a subscription is only fired when a number of messages, with certain characteristics, have been received. Let’s see some examples.
First, the most basic one:
Here, we wait for two messages to arrive, on two different channel/topic pairs. Only after the second does arrive do we trigger the subscriber action.
Next, a timed composition:
Now we give our composition 5 seconds, from the first condition until the last one. Because we are waiting for slightly longer than that, the subscriber action will never get triggered.
Finally, a composition with conditions:
On each of the steps, here represented by When and And, we can supply conditions, over an Envelope. If any of these conditions is not met, then the composition fails. Of course, we can add any number of conditions.
The Subscribe method must be called when we have all the conditions in place, and, as usual, it returns an IDisposable. When we want to cancel this subscription, we just dispose of it.
Hope you find this cool, as I did!