Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7681633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:23:11+00:00 2026-05-31T18:23:11+00:00

I have a use case with NServiceBus explained in this question. Essentially there is

  • 0

I have a use case with NServiceBus explained in this question. Essentially there is a message handler for a ImportProductCommand message. Typically a collection of these messages is sent to the handler after another handler receives an ImportProductsCommand which specifies the set of products to import. There is a requirement to know the status of a set import and so a saga is used to manage importing state. The handler for ImportProductCommand publishes a ProductImportedEvent message and ProductImportFailedEvent message upon completion. The saga subscribes to those messages correlating them to the initiating ImportProductsCommand message using an ID assigned to the message when it was first received.

public class ProductImportSaga : NServiceBus.Saga.Saga<ProductImportSagaData>,
    IAmStartedByMessages<ImportProductsCommand>,
    IHandleMessages<IProductImportedEvent>,
    IHandleMessages<IProductImportFailedEvent>
{
    public override void ConfigureHowToFindSaga()
    {
        ConfigureMapping<IProductImportedEvent>(x => x.ImportId, x => x.CorrelationId);
        ConfigureMapping<IProductImportFailedEvent>(x => x.ImportId, x => x.CorrelationId);
    }

    public void Handle(ImportProductsCommand message)
    {
        this.Data.ImportId = message.Id;
        this.Data.Total = message.SKUs.Length;
        foreach (var command in message.SKUs.Select(sku => new ImportProductCommand(message.SupplierId, sku, message.ImportImage, message.Id)))
            this.Bus.SendLocal(command);    // send to local handler shown below
    }

    public void Handle(IProductImportedEvent message)
    {
        this.Data.OnCompleted();
    }

    public void Handle(IProductImportFailedEvent message)
    {
        this.Data.OnFailed();
    }
}

And the handler of individual ImportProductCommand messages looks like this:

// handles messages sent by saga above (or sent individually by WCF service)
public class ImportProductHandler : IHandleMessages<ImportProductCommand>
{
    public IBus Bus { get; set; } 

    public void Handle(ImportProductCommand message)
    {
        // importing logic here and upon success:
        if (success)
        {
           this.Bus.Publish(new ProductImportedEvent(correlationId: message.Id));
        }
        else
        {
           this.Bus.Publish(new ProductImportFailedEvent(correlationId: message.Id));
        }
    }
}

This issue is that when the event messages are published they get placed on the queue associated with the process which is hosting both the individual handler and the saga. When this happens there may be a lot of messages in the queue that were originally sent by the saga in response to the ImportProductsMessage. This means that the saga won’t receive those events until after the queued ImportProductCommand messages have been handled and therefore processing status of the batch import won’t be updated in a timely manner. If I host the saga in a different process then it will receive the messages without having to wait for the command queue to process. Is there a way to achieve the same effect while hosting the handler and the saga in the same process? Basically, I would like for the event messages to be processed in an order different from the ImportProductCommand messages even though they are on the same queue so that the saga can handle those events and update its state accordingly. Is this possible or is there a better way to achieve this result? I’ve tried to specify message handler ordering using First<T> to no avail and it seems overkill to deploy two different hosts for closely related logic.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:23:12+00:00Added an answer on May 31, 2026 at 6:23 pm

    There is no concept of priority with NSB so it is typical to use another endpoint to perform the work. It sounds like what you are after is work distribution, you may want to take a look at the Distributor. In that model the Saga would maintain the state of the entire unit of work while each endpoint(s) would handle the actual processing. This would allow you to add additional endpoints dynamically if things were to start to slow down.

    If you didn’t want to implement the full Distributor, then at the very least pushing the actual work to another endpoint would alleviate any need for priority.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this use case scenario: there are places which are either playgrounds, restaurants,
I have this use case of an xml file with input like Input: <abc
I have the following use case: There's a class called Template and with that
I have this use case for which I am generating an image in the
I have this use case that is very similar to the robot-legs example of
I don't have a use case for this but I was recently asked this
In my app i have one use case Download Folder(s) from web server this
I have the following use case, my file contents look like this a b
I have a use case of this kind interface i { void method1(); void
I'm just starting to learn AspectJ, and I have use-case for say, User login.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.