This sample demonstrates how to use Docker Linux containers to host NServiceBus endpoints communicating over the RabbitMQ transport.
This sample requires that the following tools are installed:
- .NET Core 2.0 SDK
- Docker Community Edition or higher
- If using Windows, configure Docker to use Linux containers to support the Linux-based RabbitMQ container
Running the sample involves building the code, preparing it for deployment, building container images and finally starting the multi-container application.
The first step is to build the binaries using the .NET Core command line tools:
$ dotnet build
The compiled binaries need to be prepared for deployment into the container:
$ dotnet publish
The prepared binaries and container image definitions (Dockerfiles) are enough to build container images for both the
Sender and the
$ docker-compose build
When the container images are ready, the containers can be started:
$ docker-compose up -d
Both containers log to the console. These logs can be inspected:
$ docker-compose logs sender $ docker-compose logs receiver
The containers can be stopped and removed:
$ docker-compose down
This sample consists of
Publisher endpoints exchanging messages using the RabbitMQ transport. Each of these three components runs in a separate Docker Linux container.
Each endpoint is a container built on top of the official
microsoft/ image from Docker Hub. The container image is built using endpoint binaries from the
FROM microsoft/dotnet:2.0-runtime WORKDIR /Receiver COPY ./bin/Debug/netcoreapp2.0/publish . ENTRYPOINT ["dotnet", "Receiver.dll"]
dotnet publishcommands to generate endpoint binaries before creating the image.
version: "3" services: sender: image: sender build: context: ./Sender/ dockerfile: Dockerfile depends_on: - rabbitmq receiver: image: receiver build: context: ./Receiver/ dockerfile: Dockerfile depends_on: - rabbitmq rabbitmq: image: "rabbitmq:3-management" ports: - "15672:15672" healthcheck: test: ["CMD-SHELL", "if rabbitmqctl status; then \nexit 0 \nfi \nexit 1"] interval: 10s retries: 5
Endpoints configure the RabbitMQ transport to use the broker instance running in the
var transport = endpointConfiguration.UseTransport<RabbitMQTransport>(); transport.ConnectionString("host=rabbitmq"); transport.UseConventionalRoutingTopology();
This sample takes advantage of Docker healthchecks to ensure RabbitMQ is available before starting the endpoints.