<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [TOC] # 多方測試 ?個發送者和 N 個接收者或者 N 個發送者和 N 個接收者會出現什么情況呢? ## 一對多發送 ### 注冊隊列 ~~~ package com.jdxia.rabbitmq; import org.springframework.amqp.core.Queue; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; //定義隊列 @Configuration public class RabbitConfig { @Bean public Queue neoQueue() { return new Queue("neo"); } } ~~~ ### 發送者 一個發送者 ~~~ import org.springframework.amqp.core.AmqpTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component public class NeoSender { @Autowired private AmqpTemplate rabbitTemplate; public void send(int i) { String context = "spirng boot neo queue"+" ****** "+i; System.out.println("Sender1 : " + context); this.rabbitTemplate.convertAndSend("neo", context); } } ~~~ ### 接收者 接收者 1 示例,接收者 2 和 1基本?致 ~~~ import org.springframework.amqp.rabbit.annotation.RabbitHandler; import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.stereotype.Component; @Component @RabbitListener(queues = "neo") public class NeoReceiver1 { @RabbitHandler public void process(String neo) { System.out.println("Receiver 1: " + neo); } } ~~~ ### 測試 我們設計了?個發送者,兩個接收者,發送?百個消息看看效果. ?個發送者,N 個接收者,經過測試接收端均勻接收到消息,也說明接收端?動進?了**均衡負載**,我們也可以利?這個特性做流量分發。 ~~~ @Autowired private NeoSender neoSender; @Test public void test() throws InterruptedException { for (int i = 0; i < 100; i++) { neoSender.send(i); } Thread.sleep(10000l); } ~~~ ~~~ Sender1 : spirng boot neo queue ****** 99 Receiver 1: spirng boot neo queue ****** 0 Receiver 2: spirng boot neo queue ****** 1 Receiver 1: spirng boot neo queue ****** 2 Receiver 2: spirng boot neo queue ****** 3 Receiver 1: spirng boot neo queue ****** 4 Receiver 2: spirng boot neo queue ****** 5 ~~~ ## 多對多發送 復?以上的發送者和接收者,再增加?個發送者 2 加?標記,在?百個循環中相互交替發送。 發送者?法如下: ~~~ public void send(int i) { String context = "spirng boot neo queue"+" ****** "+i; System.out.println("Sender2 : " + context); this.rabbitTemplate.convertAndSend("neo", context); } ~~~ ### 測試 發送端交替發送消息,接收端仍然會均勻接收到消息 ~~~ @Autowired private NeoSender neoSender; @Autowired private NeoSender2 neoSender2; @Test public void test() throws InterruptedException { for (int i = 0; i < 100; i++) { neoSender.send(i); neoSender2.send(i); } Thread.sleep(10000l); } ~~~ ~~~ Receiver 2: Spring boot neo queue ****** 0 Receiver 1: Spring boot neo queue ****** 0 Receiver 2: Spring boot neo queue ****** 1 Receiver 1: Spring boot neo queue ****** 1 Receiver 2: Spring boot neo queue ****** 2 Receiver 1: Spring boot neo queue ****** 2 ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看