New to Masstransit here and I wanted to correlate my message with an int value (let’s call it OrderId
of type INT
. I will use the same order management example from Masstransit).
I wanted to see if anyone was able to use an int to correlate events and messages in Masstransit.
I used this code in my events (both the events)
x.CorrelateById<int>(state => state.OrderId, context => context.Message.OrderId)
This compiles fine but then throws and exception
NotImplementedByDesignException. Masstransit doc says : "Redis only supports event correlation by CorrelationId, it does not support queries. If a saga uses expression-based correlation, a NotImplementedByDesignException will be thrown."
I am using CorrelateById()
so not sure why I am seeing this exception. I don’t see any query here (or is it this func that returns the OrderId
? The correlationId
has a similar expression although it takes only one argument of type: Func<ConsumeContext<TMessage>, Guid> selector
)
All I want is to be able to correlate message and event by an Int prop coming to my first event of the state machine. (That I have no control over by the way).
I feel creating another GUID just for Masstransit and link it to that OrderId
is not the best option here.
My other question: is there any out of the box way in MassTransit to get the all event data for a specific CorrelationId
(event sourcing style). I saw there was a MassTransit.EventStoreIntegration
repo on github but since we can get the last version of the state instance I thought there would be a way to see all state instances/ or messages being persisted then pulled.
Sure I can see that in the log but I would like to see only the state changes that were pushed.
Thanks
2
Answers
As per @Chris answer, and because I wanted to use an INT property and still use redis, I used Guid CorrelationId that was generated from that INT value with padded zeros.
I am aware of the Guid vs int discussion in distributed systems. For my case this works with no issues since that Int value is generated by a unique source of truth (that I consume and don't have control over).
Correlation by anything other than the
Guid CorrelationId
property is a query. And, as you’ve found out, Redis doesn’t support queries. If you need to correlate events using a type other than aGuid
, Redis is not an option.