Table of Contents
Note

This guide applies to Steeltoe v3. Please open an issue if you'd like to help update the content for Steeltoe v4.

Using Service Connectors with RabbitMQ

This tutorial takes you through setting up a .NET Core application with the RabbitMQ service connector.

Note

For more detailed examples, please refer to the RabbitMQ project in the Steeltoe Samples Repository.

First, start a RabbitMQ instance using the Steeltoe dockerfile.

docker run --publish 5672:5672 steeltoeoss/rabbitmq

Next, create a .NET Core WebAPI that interacts with RabbitMQ

  1. Create a new ASP.NET Core WebAPI app with the Steeltoe Initializr

  2. Name the project "RabbitMQConnector"

  3. Add the "RabbitMQ" dependency

  4. Click Generate to download a zip containing the new project

  5. Extract the zipped project and open in your IDE of choice

  6. Validate the correct logging level is set in appsettings.json

    {
      "Logging": {
        "LogLevel": {
          "Default": "Debug",
          "System": "Information",
          "Microsoft": "Information",
          "Steeltoe": "Debug",
          "RabbitMQ_Connector": "Debug"
        }
      }
    }
    
    Note

    Make sure the correct logging is set or you'll miss the output. The default logging level should be set to Information.

  7. Set the instance address in appsettings.json

    {
      "rabbitmq": {
        "client": {
          "server": "127.0.0.1",
          "port": "5672",
          "username": "guest",
          "password": "guest"
        }
      }
    }
    
    Tip

    If you would like to see how to customize the connection have a look at the docs

Run the application

dotnet run <PATH_TO>\RabbitMQConnector.csproj

Navigate to the endpoint (you may need to change the port number) http://localhost:5000/api/values

As the app loads in the browser it will create a message queue, listen for new messages on the queue, and write 5 messages. Once finished the output will let you know everything has completed - "Wrote 5 message to the info log. Have a look!". Looking at the app logs (console) you will see...

Received message: Message 1
Received message: Message 2
Received message: Message 3
Received message: Message 4
Received message: Message 5