-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #9 - Dead Letter Exchange, Dead Letter Routing and Alternative …
…Exchange Policies
- Loading branch information
Showing
11 changed files
with
820 additions
and
43 deletions.
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.