
com.github.fridujo.rabbitmq.mock.exchange.MockTopicExchange Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rabbitmq-mock Show documentation
Show all versions of rabbitmq-mock Show documentation
Mock for RabbitMQ Java amqp-client
package com.github.fridujo.rabbitmq.mock.exchange;
import java.util.Map;
import com.github.fridujo.rabbitmq.mock.AmqArguments;
import com.github.fridujo.rabbitmq.mock.ReceiverRegistry;
public class MockTopicExchange extends MultipleReceiverExchange {
public static final String TYPE = "topic";
public MockTopicExchange(String name, AmqArguments arguments, ReceiverRegistry receiverRegistry) {
super(name, TYPE, arguments, receiverRegistry);
}
/**
*
* https://www.rabbitmq.com/tutorials/tutorial-five-python.html
*
* sharp / hash character substitutes to zero or more words
* An easy thought representation of routing keys is a list of words, words being separated by dots,
* and topic exchange binding keys an description of this kind of list.
* Considering the key some.#.key.*, all these keys can match:
*
* - some.key.redeyes where # matches for no words and * for 1 word (redeyes)
* - some.pink.key.blueeyes where # matches for 1 words (pink) and * for 1 word (blueeyes)
* - some.pink.rabbit.key.random where # matches for 2 words (pink, rabbit) and * for 1 word (random)
*
*/
protected boolean match(BindConfiguration bindConfiguration, String routingKey, Map headers) {
String bindingRegex = bindConfiguration.bindingKey
.replace("*", "([^\\.]+)")
.replace(".#", "(\\.(.*))?")
.replace("#", "(.+)");
return routingKey.matches(bindingRegex);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy