Package org.springframework.pulsar.core
Class DefaultTopicResolver
java.lang.Object
org.springframework.pulsar.core.DefaultTopicResolver
- All Implemented Interfaces:
Aware,BeanFactoryAware,TopicResolver
Topic resolver that accepts custom type to topic mappings and uses the mappings during
topic resolution.
Message type to topic mappings can be configured with
addCustomTopicMapping(Class, String).
- Author:
- Chris Bono, Aleksei Arsenev, Jonas Geiregat
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new DefaultTopicResolver.DefaultTopicResolver(ExpressionResolver expressionResolver) Constructs a new DefaultTopicResolver with the given expression resolver. -
Method Summary
Modifier and TypeMethodDescriptionaddCustomTopicMapping(Class<?> messageType, String topic) Adds a custom mapping from message type to topic.doResolveTopic(String userSpecifiedTopic, Class<?> messageType, Supplier<String> defaultTopicSupplier) Gets the currently registered custom mappings from message type to topic.removeCustomMapping(Class<?> messageType) Removes the custom mapping from message type to topic.resolveTopic(String userSpecifiedTopic, Class<?> messageType, Supplier<String> defaultTopicSupplier) Resolve the topic name to use for the given message type.resolveTopic(String userSpecifiedTopic, Supplier<String> defaultTopicSupplier) Resolve the topic name to use.resolveTopic(String userSpecifiedTopic, T message, Supplier<String> defaultTopicSupplier) Resolve the topic name to use for the given message.voidsetBeanFactory(BeanFactory beanFactory) voidusePulsarMessageAnnotations(boolean usePulsarMessageAnnotations) Sets whether to inspect message classes for the@PulsarMessageannotation during topic resolution.
-
Constructor Details
-
DefaultTopicResolver
Constructs a new DefaultTopicResolver with the given expression resolver.- Parameters:
expressionResolver- the expression resolver to use for resolving topic
-
DefaultTopicResolver
public DefaultTopicResolver()Constructs a new DefaultTopicResolver.
-
-
Method Details
-
usePulsarMessageAnnotations
public void usePulsarMessageAnnotations(boolean usePulsarMessageAnnotations) Sets whether to inspect message classes for the@PulsarMessageannotation during topic resolution.- Parameters:
usePulsarMessageAnnotations- whether to inspect messages for the annotation
-
addCustomTopicMapping
Adds a custom mapping from message type to topic.- Parameters:
messageType- the message typetopic- the topic to use for messages of typemessageType- Returns:
- the previously mapped topic or
nullif there was no mapping formessageType.
-
removeCustomMapping
Removes the custom mapping from message type to topic.- Parameters:
messageType- the message type- Returns:
- the previously mapped topic or
nullif there was no mapping formessageType.
-
getCustomTopicMappings
Gets the currently registered custom mappings from message type to topic.- Returns:
- unmodifiable map of custom mappings
-
resolveTopic
public Resolved<String> resolveTopic(@Nullable String userSpecifiedTopic, Supplier<String> defaultTopicSupplier) Description copied from interface:TopicResolverResolve the topic name to use.- Specified by:
resolveTopicin interfaceTopicResolver- Parameters:
userSpecifiedTopic- the topic specified by the userdefaultTopicSupplier- supplies the default topic to use (use a supplier that returnsnullto signal no default)- Returns:
- the topic to use or
emptyif no topic could be resolved
-
resolveTopic
public <T> Resolved<String> resolveTopic(@Nullable String userSpecifiedTopic, @Nullable T message, Supplier<String> defaultTopicSupplier) Description copied from interface:TopicResolverResolve the topic name to use for the given message.- Specified by:
resolveTopicin interfaceTopicResolver- Type Parameters:
T- the message type- Parameters:
userSpecifiedTopic- the topic specified by the usermessage- the message instance being produced or consumeddefaultTopicSupplier- supplies the default topic to use (use a supplier that returnsnullto signal no default)- Returns:
- the topic to use or
emptyif no topic could be resolved
-
resolveTopic
public Resolved<String> resolveTopic(@Nullable String userSpecifiedTopic, @Nullable Class<?> messageType, Supplier<String> defaultTopicSupplier) Description copied from interface:TopicResolverResolve the topic name to use for the given message type.- Specified by:
resolveTopicin interfaceTopicResolver- Parameters:
userSpecifiedTopic- the topic specified by the usermessageType- the message type being produced or consumeddefaultTopicSupplier- supplies the default topic to use (use a supplier that returnsnullto signal no default)- Returns:
- the topic to use or
emptyif no topic could be resolved
-
doResolveTopic
-
setBeanFactory
- Specified by:
setBeanFactoryin interfaceBeanFactoryAware- Throws:
BeansException
-