如何动态更改AWS Spring Cloud SQS删除策略

当前,我有一个要求,即我们要监听一个SQS,但基于开发或测试环境,我应该将删除策略更改为on_SUCCESS或NEVER。 有什么办法可以动态处理它。我正在使用AWS开发工具包。

@SqsListener(value = "${application.marketplace.aws.queueName}",deletionPolicy =SqsMessageDeletionPolicy.NEVER)
    public void pollSQSMsgAscync(final String message) throws Exception {}
wuzhaohai000 回答:如何动态更改AWS Spring Cloud SQS删除策略

您可以通过确认来实现

@SqsListener(value = "${queue.res-notification}",deletionPolicy = SqsMessageDeletionPolicy.NEVER)
public void receiveMessage(@NotificationMessage String message,@NotificationSubject String subject,Acknowledgment acknowledgment,@Header("ApproximateReceiveCount") final int receiveCount) {
    try {
        if(<some condition>){
            acknowledgment.acknowledge(); // this will delete the message
        }else{
          //do not acknowledge so that message will not be deleted and stays in the queue for new round of reading
        }
    } catch (Exception e) {
        log.error("Error reading notification ",e);
    }
}
本文链接:https://www.f2er.com/3153718.html

大家都在问