-
Notifications
You must be signed in to change notification settings - Fork 13
/
MessageResolver.java
44 lines (40 loc) · 1.84 KB
/
MessageResolver.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.jashmore.sqs.resolver;
import software.amazon.awssdk.services.sqs.model.Message;
import java.util.concurrent.CompletableFuture;
/**
* Will resolve the messages by deleting them from the SQS queue so that it does not get processed again.
*
* <p>This can internally figure out how the messages will be resolved, for example whether the message is deleted straight away or if it waits for a certain
* period before deleting the message from the queue.
*/
public interface MessageResolver {
/**
* Resolve the message by deleting it from the SQS queue.
*
* @param message the message to resolve
* @return a {@link CompletableFuture} that will be completed when the message has been successfully deleted
*/
CompletableFuture<?> resolveMessage(Message message);
/**
* Run the process that will actually perform the resolving of messages, this should be run on a background thread.
*
* <p>This method should not exit until it is interrupted by the container that has started this method. When the thread is interrupted the
* thread should make sure any unresolved messages are resolved and it should not exit until these are completed.
*
* <p>An example of starting this is the following:
*
* <pre class="code">
* final MessageResolver messageResolver = new SomeMessageResolverImpl(...);
* // start it on a background thread
* Future<?> resolverFuture = Executors.newCachedThreadPool().submit(messageResolver);
*
* // Now messages can be resolved
* messageResolver.resolveMessage(message)
* .thenAccept((response) -> log.info("Message resolved with id: {}", message.id());
*
* // Stop the message resolver when you are done
* resolverFuture.cancel(true);
* </pre>
*/
void run();
}