Connecting to RabbitMq gives console error message

My first attempt to connect my ServiceStack based API to a RabbitMq instance.
I have defined a dummyUser on the RabbitMq side


and added the following in my Configure routine:

        container.Register<IMessageService>(c => new RabbitMqServer("amqp://dummyUser:P4ssw0rd@localhost:5672"));
        var mqServer = container.Resolve<IMessageService>();

        mqServer.RegisterHandler<ServiceModel.Hello>(ExecuteMessage);
        mqServer.S`indent preformatted text by 4 spaces`tart();

When I start my API I get the following error message in the console:

fail: ServiceStack.RabbitMq.RabbitMqServer[0]
  Exception in Rabbit MQ Server: The AMQP operation was interrupted: AMQP close-reason, initiated by Peer, code=403, text="ACCESS_REFUSED - access to exchange 'mx.servicestack' in vhost '/' refused for user 'dummyUser'", classId=40, methodId=10, cause=
RabbitMQ.Client.Exceptions.OperationInterruptedException: The AMQP operation was interrupted: AMQP close-reason, initiated by Peer, code=403, text="ACCESS_REFUSED - access to exchange 'mx.servicestack' in vhost '/' refused for user 'dummyUser'", classId=40, methodId=10, cause=
   at RabbitMQ.Client.Impl.SimpleBlockingRpcContinuation.GetReply(TimeSpan timeout)
   at RabbitMQ.Client.Impl.ModelBase.ModelRpc(MethodBase method, ContentHeaderBase header, Byte[] body)
   at RabbitMQ.Client.Framing.Impl.Model._Private_ExchangeDeclare(String exchange, String type, Boolean passive, Boolean durable, Boolean autoDelete, Boolean internal, Boolean nowait, IDictionary`2 arguments)
   at RabbitMQ.Client.Impl.AutorecoveringModel.ExchangeDeclare(String exchange, String type, Boolean durable, Boolean autoDelete, IDictionary`2 arguments)
   at ServiceStack.RabbitMq.RabbitMqExtensions.OpenChannel(IConnection connection)
   at ServiceStack.RabbitMq.RabbitMqServer.Init()
   at ServiceStack.RabbitMq.RabbitMqServer.Start()
Hosting environment: Development

However I do manage to get a connection:

What am I doing wrong? Why do I get this error in the console?

OS: win10
Framework: .Net Core 2.1
ServiceStack: 5.4.1
RabbitMq: see pictures.

The error message suggests the dummyUser you’re using doesn’t have access to the exchange, this StackOverflow answer provides a solution to give the user permission:

1 Like

:sweat_smile:
Thank you mythz :thumbsup:

Would there be in the community a good example / tutorial where ServiceStack is combined with RabbitMQ in a “Work Queue” system?

The Email Contacts example App uses Rabbit MQ.

Other than that you could look at integration tests that use Rabbit MQ:

The last 2 implement a common test fixture that’s run against all MQ Servers to test compliance.

I read from https://stackoverflow.com/a/21748196/4655624 that ServiceStack integration of RabbitMQ is based on their “Work Queue” model. Can I use it for communication between 2 APIs built on ServicStack framework?

Right just have each Service register handlers for the Message/Request DTO they handle, e.g. you can have the Services doing the work handle the DoWork Request DTO:

mqServer.RegisterHandler<DoWork>(ExecuteMessage);

class MyServices : Service
{
    public object Any(DoWork request) => new DoWorkResponse { ... };
}

The other Service that can register DoWorkResponse:

mqServer.RegisterHandler<DoWorkResponse>(ExecuteMessage);

class MyServices : Service
{
    public object Any(DoWorkResponse request) => ...;
}

Which as per the Message Workflow will get called with the DoWorkResponse Response DTO after the DoWork request is processed.