Public/Private events #326
Replies: 7 comments 22 replies
-
Hey, My convention on Public vs Private is slight different:
So the So that being said, what about your use case? |
Beta Was this translation helpful? Give feedback.
-
Seems to me we have the same understanding of Public and Private Events. Although in my case I have a modular monolith in which Bounded Contexts are fairly defined and each BC is treated as a single deployment unit on code level yet still deployed as one. That makes technical aspect to impact strategic design in a way I think may be to avoid. I will have to check, but can I be using Distributed Bus with monolitic architecture? I guess my problem here is using Event Bus for both public and private events due there is no actual difference between them at the moment unless we change architecture. Anyway, currently events publishing using Event Bus is one of the steps of aggregate flow. If Ecotone provide a possibility to declare which events are public and which are private it may create additional configuration for that flow which may put more focus on strategic design. What do you think? |
Beta Was this translation helpful? Give feedback.
-
Hi! It would be great to have multiple distributed bus instances with different AMQP exchanges or connections (different RabbitMQ instances). |
Beta Was this translation helpful? Give feedback.
-
Shouldn't Distributed Bus integrate BCs? IMO it should be Event Bus which is considered as local and associated with specific BC. Events which are considered as private should be associated only with one BC therefore, its Event Bus that should be used for broadcasting those locally. Events which are considered as public, can be broadcasted on Distributed Bus to integrate wich other BCs. Within aggregate flow, which is associated to a single BC, all events should be considered as private by default. Those should be published only in local BC using local Event Bus and, in case of ES Aggregates, persisted on Event Stream. However, one may want to describe some of those events as public, expecting them to be published on distributed bus once transaction is successfully closed. That would avoid having to call distributed bus directly. For those events it would be expected that they won't be persisted in case of ES Aggregates. On the other hand, I can imagine having particular events to be consudered both private and public therefore expectation for those would be to be published both in local BC and to Distributed Bus. Also in case of ES Aggregates those should be persisted. To keep backward compatibility, default configuration should provide single and default Event Bus and/or single Distributed Bus. |
Beta Was this translation helpful? Give feedback.
-
Multiple distributed event buses are not a popular case, but are real. For example, https://masstransit.io/documentation/configuration/multibus |
Beta Was this translation helpful? Give feedback.
-
@unixslayer Ye, I agree. By
@lifinsky I do see that someone could use both Synchronous and Amqp integration. But what would be the use case to actually use multiple Amqp Distributed Buses?
Yep, we could make Events considered as private by default. As by default we would only have one Bounded Context for single Application, therefore no difference to actual behaviour. With that we would have two ways to distribute events. Direct Distribution#[Distributed]
#[NamedEvent('order.was_placed')]
class OrderWasPlaced
{
// some data
} This would make Ecotone automatically distribute the Event use default DistributedBus. Indirect Distributionclass OrderWasPlaced
{
// some data
}
class DistributeHandler
{
// we subscribe to Event in our Bounded Context, and we distribute it the way we want
#[EventHandler]
public function handle(OrderWasPlaced $event, DistributedBus $distributedBus)
{
$distributedBus->distribute('order.was_placed', [
'order_id' => $event->id,
// we can add some other data, or skip some to not create coupling
]);
)
}
} |
Beta Was this translation helpful? Give feedback.
-
@lifinsky you can register multiple publishers with current Ecotone configuration. However there will be always one consumer per Service. |
Beta Was this translation helpful? Give feedback.
-
In the topic of integration between models, there is a need to distinguish between
private
andpublic
events.Private events should be understood as those that can be stored as state changes but not necessarily published. Using them for integration in a distributed architecture reveals implementation details that are part of an independent model.
Public events are part of the so-called published language and do not have to contain information about the state change, but only inform about some specific situation that occurred in the system during the handling of the command, such as a summary of the operation.
I propose to introduce the possibility to specify which events registered (e.g. by the aggregate) will be public and which private with the following assumptions:
Example:
To ensure backward compatibility, events that are not specified as private nor public will not change the current behavior of
AggregateFlow
- they will be both saved and published.The idea directly affects the Projections that handle published private events. The solution may be to configure an internal EventBus to allow private events to be sent only to channels defined on the projections.
Beta Was this translation helpful? Give feedback.
All reactions