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

  • 相关阅读:
    jmeter--同步定时器
    手机配置jmete器
    jmeter---http授权管理器
    jmeter---http信息头管理器
    mysql---聚合函数
    jmeter---BeanSheel提取数组
    简述MYSQL的优化
    java常用设计模式
    什么是java序列化,如何实现java序列化?或者请解释Serializable接口的作用?
    String s = new String("xyz");创建了几个String Object? 二者之间有什么区别?
  • 原文地址:https://www.cnblogs.com/changeCode/p/11313264.html
Copyright © 2011-2022 走看看