문제

Does NServiceBus guarantee that a single message isn't handled by more than one thread?

I've been working under this assumption, however it seems that a single message was handled twice at the same time.

We do some non-transactional things in our handler so in our config we specify DoNotWrapHandlersExecutionInATransactionScope. Does this affect NServiceBus's ability to ensure that a message is only handled once? As I understand it, this just does exactly what it says and doesn't wrap with a transaction scope?

Can someone clear this up for me? What else could cause a duplicate message issue?

도움이 되었습니까?

해결책

Let's say your handler looks something like this:

public class SomeCommandHandler : IHandleMessages<SomeCommnand>
{
    public void Handle(SomeCommnand message)
    {
        // write to the database and save changes

        throw new Exception("Oh noes!");
    }
}

If you don't have your handler wrapped in a TransactionScope, I'm guessing (so please test on your own), that your data would be written but your message would be retried (rightfully so, because it failed). This would give you the impression that you got the message twice.

But why are you doing anything that's non-transactional? That kinda defeats the purpose of NServiceBus.

If you are doing things like HTTP requests or other long-running things along with your basic DB interaction, then you want to use a Saga, not a simple command handler.

다른 팁

Regarding

We do some non-transactional things in our handler so in our config we specify DoNotWrapHandlersExecutionInATransactionScope.

You can still do non-transactional things inside a handler without setting DoNotWrapHandlersExecutionInATransactionScope.

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