gorabbitmqmicroservicesmessagebrokergo-micro

Consume from one broker and produce to another using Go Micro


I am trying to write a microservice using the Go Micro framework which is going to consume from a RabbitMQ broker and Write to another.

Go Micro has a RabbitMQ plugin however it seems that if one wants to use the Go Micro abstractions (Such as micro.RegisterSubscriber), one has to rely on a lot of global states internal to the library. I ended up setting up a consumer using micro.RegisterSubscriber and then manually creating a separate broker with care to not use any internal global state (Such as default exchange) and then call broker.Publish within the consumer function which meant I had to Marshal the message manually before shipping it.

Is this not a supported pattern in Go Micro? Is there any better way of going about doing something like this?

I should mention that the main reason for choosing Go Micro in this particular case is because it seems to have a reliable RabbitMQ abstraction with reconnect support which seems to be hard to come by in Go, not necessarily because I needed RPC support in this one case.


Solution

  • Go Micro was designed to be single process per service and initialise one of each abstraction. This is the design for 99% usecase of how we write software. There are a few who would like multi-transport, multi-broker, etc but this is outside the scope of the project and I think something that someone else can easily design e.g a broker which loads multiple brokers and then switches based on an option or prefix.

    Separately, I developed a service which loads multiple brokers to do message federation. This may be of interest to you https://github.com/microhq/federation-srv