Shared Service Map

Shared Service Map

When Service Map is defined as separate shared library. It becomes explicit what Events is given Service interested in. This also makes the process of subscribing to new Event visible for everyone, therefore we avoid hidden coupling that could lead to broken integration.

Depending on how we share the events Queue vs Streaming, we may want to do additional changes to the Service Map

Explicit Mapping

To be as explicit as it's possible, we can use direct mapping for subscription keys

public function serviceMap(): DistributedServiceMap
{
    return DistributedServiceMap::initialize()
              ->withEventMapping(
                        channelName: "order_service_inbound_events",
                        subscriptionKeys: ["ticket_service.management.*"],
              )
}

This ensures that we won't receive Events that are not meant to be directed to given Service.

Non Explicit Mapping

In some cases, especially with existing Services, explicit mapping may not be possible, in this situations, we may need to use additional functionality to add filtering.

Queue Channel

In Queue Channel approach, it's external Service that owns that Channel, Publisher is only delivering his own Events there as part of Service Map contract. However, if we would put about "*" for receiving events, then if Publishing Service would also be the owner of the Channel we would republish his own Messages back to that Channel.

To avoid that we could use excludePublishingServices:

Streaming Channel

With Streaming Channel, the publishing Service, will actually be the owner of the Channel to which we want to deliver the Message. Therefore for this, if we are about to use the "*" to publish all the Messages there, reusing the Service Map in other Service would deliver other Events there too.

To avoid that and to be explicit that we want there only Events from particular Service, we can use includePublishingServices:

Last updated

Was this helpful?