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
This is however not necessary for sync handlers. Events published from sync handlers are by default correlated with events that caused them.
57
+
58
+
## Correlating events published from async handlers
59
+
60
+
Events published from async handlers are not correlated with events that caused them by default. To enable that functionality you need to prepend `RailsEventStore::CorrelatedHandler`
61
+
62
+
```ruby
63
+
classSendOrderEmail < ActiveJob::Base
64
+
prependRailsEventStore::CorrelatedHandler
65
+
prependRailsEventStore::AsyncHandler
66
+
67
+
defperform(event)
68
+
event_store.publish(HappenedLater.new(data:{
69
+
user_id: event.data.fetch(:user_id),
70
+
}))
71
+
end
72
+
73
+
private
74
+
75
+
defevent_store
76
+
Rails.configuration.event_store
77
+
end
78
+
end
79
+
```
80
+
56
81
## Correlating an event with a command
57
82
58
83
If your command responds to `correlation_id` (can even always be `nil`) and `message_id` you can correlate your events also with commands.
@@ -126,6 +151,39 @@ class AddProductCommand < Struct.new(:message_id, :product_id)
126
151
end
127
152
```
128
153
154
+
## Building streams based on correlation id and causation id
155
+
156
+
You can use `RailsEventStore::LinkByCorrelationId` (`RubyEventStore::LinkByCorrelationId`) and `RailsEventStore::LinkByCausationId` (`RubyEventStore::LinkByCausationId`) to build streams of all events with certain correlation or causation id. This makes debugging and making sense of a large process easier to see.
0 commit comments