Road rabbitmq learning (six)

The last time it comes to the consumption of news, today specifically about the news consumption, which has several forms

 

There are two modes to consume news

 

The first: Subscribe Subscribe way

This is the way we are more familiar, such as in front of us write code in such a way @RabbitListener to monitor a queue, there are messages in the queue once, automatically distributed to consumers under

 

The second: Poll pull message

This one is in the consumers take the initiative to pull message queue for consumption, it is controllable, active

 

Reference 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;

 

Also, this approach can also get the object

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;

 

In this way generic

Use these four methods to configure org.springframework.amqp.support.converter.SmartMessageConverter, which is an interface, Jackson2JsonMessageConverter already implements this interface, so long as RabbitTemplate in the Jackson2JsonMessageConverter set to.

rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());

 

 

Original link: https: //blog.csdn.net/weixin_38380858/article/details/84258507

Guess you like

Origin www.cnblogs.com/changeCode/p/11313264.html