dskpywvki951583595 2019-02-11 20:26
浏览 244

使用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.

  • 写回答

1条回答 默认 最新

  • duanjiuhong5843 2019-02-12 16:23

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



    • ¥20 如何利用C语言实现用最小二乘法选配两个经验公式
    • ¥50 vue-codemirror如何对指定行 指定位置的 字符进行背景颜色或者字体颜色的修改?
    • ¥15 有人会思科模拟器嘛?
    • ¥30 遇到一个的问题,请教各位
    • ¥20 matlab报错,vflux计算潜流通量
    • ¥15 我该如何实现鼠标按下GUI按钮时就执行按钮里面的操作的方法
    • ¥15 关于#硬件工程#的问题:我这边有个锁相环电路没有效果
    • ¥15 20款 27寸imac苹果一体机装win10后,蓝牙耳机和音响放歌曲卡顿断断续续.
    • ¥15 VB.NET 父窗体调取子窗体报错
    • ¥15 python海龟作图如何改代码使其最后画出来的是一个镜像翻转的图形