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

  • Home
  • SEARCH
  • 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 4256806
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:24:19+00:00 2026-05-21T05:24:19+00:00

How do you integrate to NServiceBus when using NEventStore? I’m new to NSB ans

  • 0

How do you integrate to NServiceBus when using NEventStore?

I’m new to NSB ans ES and trying to figure out the best setup for NSB when using ES and CQRS.

I’m hooking into NSB the same way as DispatchCommit in example,
https://github.com/joliver/EventStore/blob/master/doc/EventStore.Example/MainProgram.cs

  1. Do you publish the whole Commit or Commit.Events?
  2. Do you create a wrapper around your messages because NSB requires IMessage on your messages? How do you publish to the correct queue then? Because wrapper is generic in contrast to OrderSubmittedEvent for example. If possible I don’t want dependency to NSB for my events because then I also have that in my domain.

Some code or guidance is really appreciated.

  • 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-21T05:24:20+00:00Added an answer on May 21, 2026 at 5:24 am

    Here’s what I’m using in production:

    public sealed class NServiceBusPublisher : IPublishMessages
    {
        private const string AggregateIdKey = "AggregateId";
        private const string CommitVersionKey = "CommitVersion";
        private const string EventVersionKey = "EventVersion";
        private const string BusPrefixKey = "Bus.";
        private readonly IBus bus;
    
        public NServiceBusPublisher(IBus bus)
        {
            this.bus = bus;
        }
    
        public void Dispose()
        {
            GC.SuppressFinalize(this);
        }
    
        public void Publish(Commit commit)
        {
            for (var i = 0; i < commit.Events.Count; i++)
            {
                var eventMessage = commit.Events[i];
                var busMessage = eventMessage.Body as IMessage;
                AppendHeaders(busMessage, commit.Headers); // optional
                AppendHeaders(busMessage, eventMessage.Headers); // optional
                AppendVersion(commit, i); // optional
                this.bus.Publish(busMessage);
            }
        }
        private static void AppendHeaders(IMessage message, IEnumerable<KeyValuePair<string, object>> headers)
        {
            headers = headers.Where(x => x.Key.StartsWith(BusPrefixKey));
            foreach (var header in headers)
            {
                var key = header.Key.Substring(BusPrefixKey.Length);
                var value = (header.Value ?? string.Empty).ToString();
                message.SetHeader(key, value);
            }
        }
        private static void AppendVersion(Commit commit, int index)
        {
            var busMessage = commit.Events[index].Body as IMessage;
            busMessage.SetHeader(AggregateIdKey, commit.StreamId.ToString());
            busMessage.SetHeader(CommitVersionKey, commit.StreamRevision.ToString());
            busMessage.SetHeader(EventVersionKey, GetSpecificEventVersion(commit, index).ToString());
        }
        private static int GetSpecificEventVersion(Commit commit, int index)
        {
            // e.g. (StreamRevision: 120) - (5 events) + 1 + (index @ 4: the last index) = event version: 120
            return commit.StreamRevision - commit.Events.Count + 1 + index;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are trying to integrate tests in our daily builds using TestComplete, so far
I'm trying to integrate a Facebook send button into my site using Facebook app.
We are trying to integrate the System.Web.Providers membership management into a transaction using System.Transactions.TransactionScope
I'm trying to integrate twitter in iOS5 app. Using Twitter framework in my app,
I am trying to integrate twitter into devise using this guide . I basically
I am trying to integrate NLog into our application which is C# based using
I'm trying to integrate running Fitnesse tests from MSBuild im my nightly build on
I'm trying to integrate a public message board service into an existing web site.
I'm trying to integrate a NSURLConnection object with UIProgressView, so I can update the
I am trying to integrate NHibernate.Search into a multi-lingual website. Now, this website contains

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.