上一篇部落格從使用的角度了解了spring cloud stream。現在得知道為什麼其可以生效。
我們針對分區做了下面的配置:
# cloud stream 相關
spring.cloud.stream.bindings.input.destination=streamfenqu
spring.cloud.stream.bindings.input.group=stream_receiver
## 消費組
spring.profiles.active=
## 分區
spring.cloud.stream.bindings.input.consumer.partitioned=true
spring.cloud.stream.instance-count=3
spring.cloud.stream.instance-index=
于是,在消息隊列中,生成了三個隊列和一個 exchange
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiI0gTMx81dsQWZ4lmZf1GLlpXazVmcvwFciV2dsQXYtJ3bm9CX9s2RkBnVHFmb1clWvB3MaVnRtp1XlBXe0xCMy81dvRWYoNHLwEzX5xCMx8FesU2cfdGLwMzX0xiRGZkRGZ0Xy9GbvNGLpZTY1EmMZVDUSFTU4VFRR9Fd4VGdsYTMfVmepNHLrJXYtJXZ0F2dvwVZnFWbp1zczV2YvJHctM3cv1Ce-cmbw5SM4gDN5YjY3QTOzgDNyMjNzYzX1MjNxATMzAzLcFTMyIDMy8CXn9Gbi9CXzV2Zh1WavwVbvNmLvR3YxUjLyM3Lc9CX6MHc0RHaiojIsJye.png)
不言而喻,可以得出上面的關系圖
是以,如果我們需要同時搞兩個消費組,且具有各自的分區,那麼應該修改exchange的名字,來看看是哪裡定義的streamfenqu:
spring.cloud.stream.bindings.input.destination=streamfenqu
這是指的通道的目的地,修改exchange隻能在此處進行修改,如果現在我有這樣一個需求,對于發到exchange:streamfenqu中的消息,我需要分别給兩個消費組進行分區消費,那麼通道綁定的目的地應該都為 streamfenqu才行,按照道理,這裡的路由鍵由cloud stream生成就重複了。下面我建立一個路由組,并對其進行分區,看有什麼結果。(注意這裡采用了相同的通道)
使用下面的配置:
# cloud stream 相關
spring.cloud.stream.bindings.input.destination=streamfenqu
spring.cloud.stream.bindings.input.group=stream_receiver_2
## 消費組
spring.profiles.active=
## 分區
spring.cloud.stream.bindings.input.consumer.partitioned=true
spring.cloud.stream.instance-count=3
spring.cloud.stream.instance-index=
# 應用本身相關
spring.application.name=stream-receiver_2
打開執行個體
另外生成了幾個隊列
同時也添加了路由,來測試一下
消費組stream_receiver_2的分區驗證截圖:
消費組stream_receiver的分區驗證截圖