Exchange message definitions between NServiceBus services

Impressive setting

  • Multiple services
  • Everyone lives in their own repository.
  • Each designed separately
  • Each time deployed separately
  • They want to communicate through NServiceBus

Study

The NServiceBus base examples show how several applications that are part of the same solution share message definitions using another shared library project that they all reference. Here, if the services are not part of the same solution, everything becomes complicated.

I assume that the general project can be extracted into a separate repository, and then refer to other repositories as a DLL or as an order, for example, a NuGet package. But this creates a lot of difficulties during development and does not seem to be right.

In this example http://docs.particular.net/samples/step-by-step/ there is even a note:

Keeping all message definitions in one place is not the best practice, but serves to illustrate how everything works for this simple Example.

However, I have not yet been able to find what is the best practice.

Question How to distribute message definitions between services?

+5
source share
1 answer

Your creative attitude is good. However, instead of having one common message collection, each service can have its own message collection and then publish it as a NuGet package in a private repository.

So, if you have a sales service, for example, in the Sales repository, there will also be a Sales.Messages project. This is the simplest form, it will contain definitions for all teams processed by the sales service, and definitions for all events published by the sales service.

It is also useful for further splitting messages between Sales.InternalMessages and (let him just name it now) Sales.Contracts.

Internal messages are simply messages that travel within your service. Like private methods, you do not want other commands to be able to call those outside your service, and therefore you will not distribute these messages externally as a NuGet package.

Then Sales.Contracts will only contain messages that go beyond the service. Naming them β€œContracts” reminds you that they are a contract between services, and therefore you need to manage them as such. This means that changes to them must be carefully considered and versioned.

+6
source

All Articles