the spring-rabbitmq config is like
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
<version>1.1.3.RELEASE</version>
I want to canceling a consumer , use channel.basicCannel(consumerTag)
when i use ChannelAwareMessageListener
in spring-rabbitmq 2.x version, consumerTag
are
in MessageProperties
,
but my online service is use 1.x version, there has no consumerTag
in MessageProperties
,
so i cant use the basicCancel api
my full listener code below
public class RPCListener implements ChannelAwareMessageListener {
private static final Logger log = LoggerFactory.getLogger(RPCListener.class);
@Autowired
private MessagePropertiesConverter messagePropertiesConverter;
private MessageConverter messageConverter = new SimpleMessageConverter();
@Autowired
private AmqpTemplate amqpTemplate;
private Boolean flag = false;
@Override
public void onMessage(Message message, Channel channel) throws Exception {
try {
log.error("DeliveryTag(): {}", message.getMessageProperties().getDeliveryTag());
if (flag) {
log.error("canceling....");
//If true, messages will be requeued and possibly
channel.basicRecover(true);
// there is no consumerTag property in MessageProperties
//channel.basicCancel(message.getMessageProperties().getConsumerTag());
return;
}
amqpTemplate.send(message.getMessageProperties().getReplyTo(), message);
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
} catch (Exception e) {
e.printStackTrace();
}
}
public Boolean getFlag() {
return flag;
}
public void setFlag(Boolean flag) {
this.flag = flag;
}
}
Is there any way to get consumerTag?
Thanks all!
1.1.3 is 7 years old; the consumerTag
was added to MessageProperties
in 1.4.2.
The only supported 1.x version is 1.7.14 - see the project page.
1.7.x will no longer be supported after this year.
However; you should NOT manually cancel the consumer; stop the container instead.