您的位置:首页 > 健康 > 养生 > 推广普通话ppt课件免费_网站设计开发方案_南京seo圈子_如何自己弄个免费网站

推广普通话ppt课件免费_网站设计开发方案_南京seo圈子_如何自己弄个免费网站

2024/12/23 16:26:14 来源:https://blog.csdn.net/qq_45722630/article/details/143466375  浏览:    关键词:推广普通话ppt课件免费_网站设计开发方案_南京seo圈子_如何自己弄个免费网站
推广普通话ppt课件免费_网站设计开发方案_南京seo圈子_如何自己弄个免费网站

1. 交换机

在这里插入图片描述

2. Fanout交换机

广播。生产者向exchange发消息

@SpringBootTest
public class SpringAmqpTest {@Autowiredpublic RabbitTemplate rabbitTemplate;@Testvoid testSimple() {String exchangName = "hmall.fabout";rabbitTemplate.convertAndSend(exchangName, null,"hello, w");}
}

消费者监听exchange绑定的队列即可。

@Component
@Slf4j
public class SpringAmqbListener {@AutowiredRabbitTemplate rabbitTemplate;@RabbitListener(queues = "simple.queue")public void Lister(String msg) {log.info(msg);}@RabbitListener(queues = "fanout.q1")public void Lister1(String msg) {System.out.println("q1:" + msg);}@RabbitListener(queues = "fanout.q2")public void Lister2(String msg) {System.out.println("q2:" + msg);}
}

3. Direct 直连交换机

在这里插入图片描述
生产者,需要指定exchange和key

@SpringBootTest
public class SpringAmqpTest {@Autowiredpublic RabbitTemplate rabbitTemplate;@Testvoid testSimple() {String exchangName = "hmall.direct";rabbitTemplate.convertAndSend(exchangName, "yellow", "hello, w");}
}

消费者指定对列

@Component
@Slf4j
public class SpringAmqbListener {@AutowiredRabbitTemplate rabbitTemplate;@RabbitListener(queues = "simple.queue")public void Lister(String msg) {log.info(msg);}@RabbitListener(queues = "direct.q1")public void Lister1(String msg) {System.out.println("q1:" + msg);}@RabbitListener(queues = "direct.q2")public void Lister2(String msg) {System.out.println("q2:" + msg);}@RabbitListener(queues = "direct.q3")public void Lister3(String msg) {System.out.println("q3" + msg);}
}

4. Topic交换机

在这里插入图片描述
生产者

@SpringBootTest
public class SpringAmqpTest {@Autowiredpublic RabbitTemplate rabbitTemplate;@Testvoid testSimple() {String exchangName = "hmall.topic";rabbitTemplate.convertAndSend(exchangName, "china.news", "hello, w");}
}

消费者

    @RabbitListener(queues = "topic.q1")public void topicLister1(String msg) {System.out.println("q1:" + msg);}@RabbitListener(queues = "topic.q2")public void topicLister2(String msg) {System.out.println("q2:" + msg);}

5. 代码生成交换机

在这里插入图片描述
基于注解绑定,在消费者的@Component中写。

 	@RabbitListener(bindings = @QueueBinding(value = @Queue(name = "direct.queue1"),exchange = @Exchange(name = "hmall.direct", type = ExchangeTypes.DIRECT),key = {"red", "yellow"}))public void topicLister1(String msg) {System.out.println("q1:" + msg);}@RabbitListener(bindings = @QueueBinding(value = @Queue(name = "direct.queue2"),exchange = @Exchange(name = "hmall.direct", type = ExchangeTypes.DIRECT),key = {"red", "yellow"}))public void topicLister2(String msg) {System.out.println("q2:" + msg);}

6. 修改默认序列化器

  1. 依赖
        <!--jackson--><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId></dependency>
  1. 注册为Bean
    @Beanpublic MessageConverter messageConverter() {return new Jackson2JsonMessageConverter();}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com