-
Notifications
You must be signed in to change notification settings - Fork 33
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
Issue #9 - Dead Letter Exchange, Dead Letter Routing and Alternative Exchange Policies #131
Open
RedMu
wants to merge
1
commit into
fridujo:master
Choose a base branch
from
RedMu:policy
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/main/java/com/github/fridujo/rabbitmq/mock/MockPolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.github.fridujo.rabbitmq.mock; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
import lombok.Singular; | ||
import lombok.ToString; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.function.Predicate; | ||
|
||
import static com.github.fridujo.rabbitmq.mock.MockPolicy.ApplyTo.ALL; | ||
import static com.github.fridujo.rabbitmq.mock.tool.ParameterMarshaller.getParameterAsExchangePointer; | ||
import static com.github.fridujo.rabbitmq.mock.tool.ParameterMarshaller.getParameterAsString; | ||
import static java.util.Arrays.asList; | ||
import static java.util.Collections.singletonList; | ||
|
||
@Getter | ||
@ToString | ||
public class MockPolicy { | ||
public static final String ALTERNATE_EXCHANGE = "alternate-exchange"; | ||
public static final String DEAD_LETTER_EXCHANGE = "dead-letter-exchange"; | ||
public static final String DEAD_LETTER_ROUTING_KEY = "dead-letter-routing-key"; | ||
|
||
private String name; | ||
private String pattern; | ||
private Integer priority; | ||
private Map<String, Object> definitions; | ||
private ApplyTo applyTo; | ||
|
||
static final Comparator<MockPolicy> comparator = Comparator.comparing(MockPolicy::getPriority).reversed(); | ||
|
||
final Predicate<Receiver> receiverMatchesPolicyPattern = | ||
r -> r.pointer().name.matches(this.pattern) && this.applyTo.matches(r) ; | ||
|
||
@Builder(toBuilder = true) | ||
public MockPolicy(@NonNull String name, @NonNull String pattern, @NonNull @Singular Map<String, Object> definitions, | ||
Integer priority, ApplyTo applyTo) { | ||
this.name = name; | ||
this.pattern = pattern; | ||
this.definitions = definitions; | ||
this.priority = priority == null ? 0 : priority; | ||
this.applyTo = applyTo == null ? ALL : applyTo; | ||
} | ||
|
||
public Optional<ReceiverPointer> getAlternateExchange() { | ||
return getParameterAsExchangePointer.apply(ALTERNATE_EXCHANGE, definitions); | ||
} | ||
|
||
public Optional<ReceiverPointer> getDeadLetterExchange() { | ||
return getParameterAsExchangePointer.apply(DEAD_LETTER_EXCHANGE, definitions); | ||
} | ||
|
||
public Optional<String> getDeadLetterRoutingKey() { | ||
return getParameterAsString.apply(DEAD_LETTER_ROUTING_KEY, definitions); | ||
} | ||
|
||
public enum ApplyTo { | ||
ALL(asList(ReceiverPointer.Type.QUEUE, ReceiverPointer.Type.EXCHANGE)), | ||
EXCHANGE(singletonList(ReceiverPointer.Type.EXCHANGE)), | ||
QUEUE(singletonList(ReceiverPointer.Type.QUEUE)); | ||
|
||
private List<ReceiverPointer.Type> supportedTypes; | ||
|
||
ApplyTo(List<ReceiverPointer.Type> supportTypes) { | ||
this.supportedTypes = supportTypes; | ||
} | ||
|
||
public boolean matches(Receiver r) { | ||
return supportedTypes.contains(r.pointer().type); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not.
I have nothing but bad experiences with Lombok.
I know that some people may find it useful to write less code, however code that is written behave as expected (vs generation of all possible constructors for ex.).
At best it messes up source jar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to take it out, it shouldn't be packaged in the source jar though.
I've got to finish ttl and then I've done all the policies so I'll probably push it all back as one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is not what I meant, rather that sources using Lombok are not valid raw Java.
When navigating sources of a third-party library, IDEs match / compile source code with no knowledge of Lombok (or other tools like it) generating stuff at compile time.
This ends up with broken navigation, (navigating to a constructor that does not exists for instance), line numbers not matching those in stacktraces and inaccurate breakpoints.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you can split into feature commits (1 commit = prod+test) to ease review I would be very grateful !