zoukankan      html  css  js  c++  java
  • rabbitmq学习之路(六)

    上一次说到了消息的消费,今天具体说一下消息消费有哪几种形式

    消息有两种模式来消费

    第一种:Subscribe订阅的方式

    这种也是我们比较熟悉的方式,例如前面我们写的代码,用@RabbitListener这样的方式去监听某一个队列,一旦队列中有消息,就会自动下发给消费者

    第二种:Poll拉取消息

    这一种是消费者主动去队列中拉取消息进行消费,是可控的,主动的

    参考APi

    Message receive() throws AmqpException;

    Message receive(String queueName) throws AmqpException;

    Message receive(long timeoutMillis) throws AmqpException;

    Message receive(String queueName, long timeoutMillis) throws AmqpException;

    同样的,这种方式也可以获取对象

    Object receiveAndConvert() throws AmqpException;

    Object receiveAndConvert(String queueName) throws AmqpException;

    Object receiveAndConvert(long timeoutMillis) throws AmqpException;

    Object receiveAndConvert(String queueName, long timeoutMillis) throws AmqpException;

    <T> T receiveAndConvert(ParameterizedTypeReference<T> type) throws AmqpException;

    <T> T receiveAndConvert(String queueName, ParameterizedTypeReference<T> type) throws AmqpException;

    <T> T receiveAndConvert(long timeoutMillis, ParameterizedTypeReference<T> type) throws AmqpException;

    <T> T receiveAndConvert(String queueName, long timeoutMillis, ParameterizedTypeReference<T> type)

    throws AmqpException;

    用这种泛型的方式

    使用这四个方法需要配置org.springframework.amqp.support.converter.SmartMessageConverter,这是一个接口,Jackson2JsonMessageConverter已经实现了这个接口,所以只要将Jackson2JsonMessageConverter设置到RabbitTemplate中即可。

    rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());

    原文链接:https://blog.csdn.net/weixin_38380858/article/details/84258507

  • 相关阅读:
    [BZOJ2729]排队
    [BZOJ2839]集合计数
    [BZOJ2111] Perm 排列计数
    Unet 项目部分代码学习
    数据增强代码
    论文阅读笔记五:U-Net: Convolutional Networks for Biomedical Image Segmentation(CVPR2015)
    CTPN项目部分代码学习
    论文阅读笔记四:CTPN: Detecting Text in Natural Image with Connectionist Text Proposal Network(ECCV2016)
    R2CNN项目部分代码学习
    VOC数据集生成代码使用说明
  • 原文地址:https://www.cnblogs.com/changeCode/p/11313264.html
Copyright © 2011-2022 走看看