配置生产者

/**
 * @author BNTang
 */
@Configuration
public class WorkConfig {

    @Bean
    public Queue work() {
        return new Queue("work");
    }

}

发送消息

@Test
public void testWork() {
    for (int i = 0; i <= 10; i++) {
        this.rabbitTemplate.convertAndSend("work", "hello Work → " + i);
    }
    System.out.println("消息发送成功");
}

消费者

/**
 * @author BNTang
 */
@Component
public class WorkConsumer {

    @RabbitListener(queuesToDeclare = {@Queue("work")})
    public void receive1(String message) {
        System.out.println("消费者【1】接收到消息:" + message);
    }

    @RabbitListener(queuesToDeclare = {@Queue("work")})
    public void receive2(String message) {
        System.out.println("消费者【2】接收到消息:" + message);
    }
}

测试方式和前面章节中的一样自行测试即可。

相关文章:

  • 2021-09-21
  • 2021-09-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-11
  • 2022-12-23
  • 2022-02-26
猜你喜欢
  • 2021-06-21
  • 2021-07-23
  • 2021-12-04
  • 2022-12-23
  • 2021-09-07
  • 2021-11-26
  • 2022-02-10
相关资源
相似解决方案