-
-
Notifications
You must be signed in to change notification settings - Fork 62
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
I'm trying to load in a custom ObjectMapper using the instructions provided in #164 . This was not working. I did some troubleshooting, and it seems like the problem is that the message converter never actually gets used.
I think the issue is here:
// RqueueListenerAutoConfig
public RqueueMessageHandler rqueueMessageHandler() {
return this.simpleRqueueListenerContainerFactory.getRqueueMessageHandler(this.getMessageConverterProvider());
}
// RqueueListenerBaseConfig
protected MessageConverterProvider getMessageConverterProvider() {
try {
Class<?> c = Thread.currentThread().getContextClassLoader().loadClass(this.messageConverterProviderClass);
Object messageProvider = c.newInstance();
if (messageProvider instanceof MessageConverterProvider) {
return (MessageConverterProvider)messageProvider;
} else {
throw new IllegalStateException("configured message converter is not of type MessageConverterProvider, type: '" + this.messageConverterProviderClass + "'", new Exception());
}
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new IllegalStateException("MessageConverterProvider class '" + this.messageConverterProviderClass + "' loading failed ", e);
}
}
RqueueListenerBaseConfig
forces reading the messageConverterProviderClass
configuration instead of what was configured in the factory.
This is how I worked around the problem, but I am not sure if it is the correct way. It requires extra boilerplate that I couldn't find referenced in any other issue or discussion.
@Configuration
public class RedisConfig {
@Bean
public SimpleRqueueListenerContainerFactory simpleRqueueListenerContainerFactory(MessageConverterProvider mapperProvider) {
SimpleRqueueListenerContainerFactory factory = new SimpleRqueueListenerContainerFactory();
factory.setMessageConverterProvider(mapperProvider);
return factory;
}
@Bean
public RqueueMessageHandler rqueueMessageHandler(SimpleRqueueListenerContainerFactory factory, MessageConverterProvider mcp) {
return factory.getRqueueMessageHandler(mcp);
}
@Bean
public MessageConverterProvider messageConverterProvider(final ObjectMapper objectMapper) {
var gm = new GenericMessageConverter(objectMapper);
var converter = new DefaultRqueueMessageConverter(Collections.singletonList(gm));
return new FixedObjectMapperMessageConverterProvider(converter);
}
}
@RequiredArgsConstructor
class FixedObjectMapperMessageConverterProvider extends DefaultMessageConverterProvider {
private final DefaultRqueueMessageConverter converter;
public MessageConverter getConverter() {
return converter;
}
}
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working