-
-
Notifications
You must be signed in to change notification settings - Fork 338
Add FilteringAdapter in SQS #1388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 13 commits
89084dd
2f0917f
2408678
a353fc4
ace28e9
8d0e377
cae2dab
3ea1f5c
708de95
d5cecc7
dcb93e9
37e7ee7
1f97ca4
5b8099a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.awspring.cloud.sqs.listener.sink; | ||
|
||
import io.awspring.cloud.sqs.listener.MessageProcessingContext; | ||
import io.awspring.cloud.sqs.support.filter.MessageFilter; | ||
import org.springframework.messaging.Message; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class FilteredBatchMessageSink<T> extends BatchMessageSink<T> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The In practical terms, it can extend from Makes sense? |
||
|
||
private final MessageFilter<T> filter; | ||
|
||
public FilteredBatchMessageSink(MessageFilter<T> filter) { | ||
this.filter = filter; | ||
} | ||
|
||
@Override | ||
protected CompletableFuture<Void> doEmit(Collection<Message<T>> messages, MessageProcessingContext<T> context) { | ||
List<Message<T>> filtered = new ArrayList<>(messages.size()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part of the code needs to be non-blocking, otherwise it may block the polling thread e.g. if the filter makes a request or DB query. I'm not 100% sure what's the best approach, but we could:
I would probably go with the first approach. For that, we'd probably need to have the Let me know your thoughts. |
||
for (Message<T> message : messages) { | ||
if (filter.process(message)) { | ||
filtered.add(message); | ||
} | ||
} | ||
|
||
if (filtered.isEmpty()) { | ||
return CompletableFuture.completedFuture(null); | ||
} | ||
|
||
return super.doEmit(filtered, context); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.awspring.cloud.sqs.listener.sink; | ||
|
||
import io.awspring.cloud.sqs.listener.MessageProcessingContext; | ||
import io.awspring.cloud.sqs.support.filter.MessageFilter; | ||
import org.springframework.messaging.Message; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class FilteredFanOutMessageSink<T> extends FanOutMessageSink<T> { | ||
|
||
private final MessageFilter<T> filter; | ||
|
||
public FilteredFanOutMessageSink(MessageFilter<T> filter) { | ||
this.filter = filter; | ||
} | ||
|
||
@Override | ||
protected CompletableFuture<Void> doEmit(Collection<Message<T>> messages, MessageProcessingContext<T> context) { | ||
List<Message<T>> filtered = new ArrayList<>(messages.size()); | ||
for (Message<T> message : messages) { | ||
if (filter.process(message)) { | ||
filtered.add(message); | ||
} | ||
} | ||
|
||
if (filtered.isEmpty()) { | ||
return CompletableFuture.completedFuture(null); | ||
} | ||
|
||
return super.doEmit(filtered, context); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.