-
Notifications
You must be signed in to change notification settings - Fork 0
Publish Events
Ahmad Elassuty edited this page Jan 27, 2021
·
2 revisions
You can publish a single event using EventRouter.publish
method:
event = OrderPlaced.new(order: order, actor: actor)
EventRouter.publish(event)
Similarly, you can use EventRouter.publish
to publish multiple events by passing an array of events instead. Events will be delivered to their destinations in the same order they are passed to the publish
method.
event_1 = OrderPlaced.new(order: order_1, actor: actor)
event_2 = OrderPlaced.new(order: order_2, actor: actor)
EventRouter.publish([event_1, event_2])
By default EventRouter.publish
will use the configured default delivery adapter. You still can set the adapter per publish
call by referencing the adapter name in the adapter
attribute. Please make sure that the adapter is registered first.
event = OrderPlaced.new(order: order, actor: actor)
EventRouter.publish(event, adapter: :sidekiq)
You can also publish events using the event class publish
method:
OrderPlaced.publish(order: order, actor: actor)