1 /*
2 * Copyright 2013-2019 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.springframework.cloud.aws.messaging.listener;
18
19 /**
20 * Defines the policy that must be used for the deletion of SQS messages once they were
21 * processed. The deletion policy can be set individually on every listener method using
22 * the
23 * {@link org.springframework.cloud.aws.messaging.listener.annotation.SqsListener @SqsListener}
24 * annotation. The default policy is {@code NO_REDRIVE} because it is the safest way to
25 * avoid poison messages and have a safe way to avoid the loss of messages (i.e. using a
26 * dead letter queue).
27 * <p>
28 * The following deletion policies are available:
29 * </p>
30 * <ul>
31 * <li><b>ALWAYS</b>: Always deletes message in case of success (no exception thrown) or
32 * failure (exception thrown) during message processing by the listener method.</li>
33 * <li><b>NEVER</b>: Never deletes message automatically. The receiving listener method
34 * must acknowledge each message manually by using the acknowledgment parameter.</li>
35 * <li><b>NO_REDRIVE</b>: Deletes message if no redrive policy is defined.</li>
36 * <li><b>ON_SUCCESS</b>: Deletes message when successfully executed by the listener
37 * method. If an exception is thrown by the listener method, the message will not be
38 * deleted.</li>
39 * </ul>
40 *
41 * @author Alain Sahli
42 * @since 1.1
43 * @see org.springframework.cloud.aws.messaging.listener.annotation.SqsListener
44 */
45 public enum SqsMessageDeletionPolicy {
46
47 /**
48 * Always deletes message in case of success (no exception thrown) or failure
49 * (exception thrown) during message processing by the listener method.
50 */
51 ALWAYS,
52
53 /**
54 * Never deletes message automatically. The receiving listener method must acknowledge
55 * each message manually by using the acknowledgment parameter.
56 * <p>
57 * <b>IMPORTANT</b>: When using this policy the listener method must take care of the
58 * deletion of the messages. If not, it will lead to an endless loop of messages
59 * (poison messages).
60 * </p>
61 *
62 * @see Acknowledgment
63 */
64 NEVER,
65
66 /**
67 * Deletes message if no redrive policy is defined.
68 */
69 NO_REDRIVE,
70
71 /**
72 * Deletes message when successfully executed by the listener method. If an exception
73 * is thrown by the listener method, the message will not be deleted.
74 */
75 ON_SUCCESS
76
77 }
78