문제

if i want to describe a event in nservicebus i would create an interface that gets published from a service and is consumed by one or more subscribers.

let's call the event "systemerror". this event is published every time when a point in the code is reached where we cannot execute something further.

so this event can eventually be published by multiple different logical services. lets look at a config file from our subscriber in a case when there is only one service that publishes this "systemerror"

<UnicastBusConfig>
    <MessageEndpointMappings>
        <add Messages="SystemErrorMessages" Endpoint="appserviceQueue" />
    </MessageEndpointMappings>
</UnicastBusConfig>

ok so far no problem. but what if we have two services that publish this event?

<UnicastBusConfig>
    <MessageEndpointMappings>
        <add Messages="SystemErrorMessages" Endpoint="appserviceQueue" />
        <add Messages="SystemErrorMessages" Endpoint="transportQueue" />
    </MessageEndpointMappings>
</UnicastBusConfig>

this is not a valid configuration since there are 2 message entries with the name "SystemErrorMessages".

we could inherit from the "systemerror" event so that each logical service would publish their own "systemerror" for example the "appservice_systemerror" and the "transportservice_systemerror".

the configuration for the subscriber would look like:

<UnicastBusConfig>
    <MessageEndpointMappings>
        <add Messages="AppService_SystemErrorMessages" Endpoint="appserviceQueue" />
        <add Messages="TransportService_SystemErrorMessages" Endpoint="transportQueue" />
    </MessageEndpointMappings>
</UnicastBusConfig>

but what would be the approach if we install the logical service "transportservice" on two or more different machines? so we have two logical services where one of these services is installed in two physical locations.

<UnicastBusConfig>
    <MessageEndpointMappings>
        <add Messages="AppService_SystemErrorMessages" Endpoint="appserviceQueue" />
        <add Messages="TransportService_SystemErrorMessages" Endpoint="transportQueue1" />
        <add Messages="TransportService_SystemErrorMessages" Endpoint="transportQueue2" />
    </MessageEndpointMappings>
</UnicastBusConfig>

what could be a possible solution for such a problem? are there any nservicebus components that handle such cases? should i just send the messages instead of publishing them - regardless of the fact that these messages indicate events instead of commands?

도움이 되었습니까?

해결책

NServiceBus deliberately makes things hard in certain cases when you rub against the strong opinions baked into the framework. This is one such case.

The issue that you're hitting is in this statement: "this event can...be published by multiple different logical services." In NServiceBus, each event has exactly one logical owner.

The good news is that we are still able to publish this event from multiple physical locations despite there being a single logical owner, as you have mentioned. In this case it appears that you have a cross-cutting business component--something akin to an "operations" component. This component is responsible for detecting failure conditions in the various endpoints and publishing when something goes wrong. Does that sound right?

There is nothing wrong with having a single component distributed to multiple physical endpoints. In fact, this is almost a best practice in NServiceBus.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top