You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The purpose is to attach current correlation id to distributed events, so we can relate events with HTTP requests and can trace all the related activities.
Attach the current correlation id (get using ICorrelationIdProvider.Get()) to distributed events as an additional property. This can be added to header of the message with provider's API. For example, RabbitMQ's BasicPublish method gets IBasicProperties which contains Headers while sending/receiving events. We can define a header and transfer the value with that header. Header name can be X-Correlation-Id as we already use it in HTTP headers.
Add correlation id to IncomingEventInfo and OutgoingEventInfo as an extra property (to the ExtraProperties collection) with the same header name (X-Correlation-Id).
Change current ICorrelationIdProvider implementations, so we can use the ambient context pattern (implemented with with AsyncLocal<T> internally) to set an arbitrary correlation id value with a using statement, just like we did at ICurrentPrincipalAccessor.Change. In this way, we can temporary override the current correlation id (it sets back to previous value after the using statement).
We will use the ICorrelationIdProvider.Change method while executing an incoming event. In this way, if we get the correlation id value inside our distributed event handler, we can get the value that is attached to the event. Also, if we make an HTTP call to another microservice, it will use the same correlation id value that is originally attached to the event by the sender.
We should also be able to get the correlation id value in global DistributedEventSent and DistributedEventReceived events. It should already work if we use ICorrelationIdProvider.Change before executing that local event (in the event handler, we can get from ICorrelationIdProvider.Get, no need to add value to the DistributedEventSent and DistributedEventReceived classes.
The text was updated successfully, but these errors were encountered:
The purpose is to attach current correlation id to distributed events, so we can relate events with HTTP requests and can trace all the related activities.
ICorrelationIdProvider.Get()
) to distributed events as an additional property. This can be added to header of the message with provider's API. For example, RabbitMQ'sBasicPublish
method getsIBasicProperties
which containsHeaders
while sending/receiving events. We can define a header and transfer the value with that header. Header name can beX-Correlation-Id
as we already use it in HTTP headers.IncomingEventInfo
andOutgoingEventInfo
as an extra property (to theExtraProperties
collection) with the same header name (X-Correlation-Id
).AsyncLocal<T>
internally) to set an arbitrary correlation id value with a using statement, just like we did atICurrentPrincipalAccessor.Change
. In this way, we can temporary override the current correlation id (it sets back to previous value after the using statement).ICorrelationIdProvider.Change
method while executing an incoming event. In this way, if we get the correlation id value inside our distributed event handler, we can get the value that is attached to the event. Also, if we make an HTTP call to another microservice, it will use the same correlation id value that is originally attached to the event by the sender.DistributedEventSent
andDistributedEventReceived
events. It should already work if we useICorrelationIdProvider.Change
before executing that local event (in the event handler, we can get fromICorrelationIdProvider.Get
, no need to add value to theDistributedEventSent
andDistributedEventReceived
classes.The text was updated successfully, but these errors were encountered: