У меня проблема с Spring Boot Rabbit Mq. У меня есть 2 слушателя, которые слушают одну и ту же очередь, но обрабатывают разные объекты:
@Service
@RabbitListener(queues = "#{changeDataQueue.name}")
public class CreateDayAheadTradeListener implements DayAheadTradeEventListener<CreateDayAheadTradeRequest> {
@Autowired
private DayAheadTradeRepository repository;
@Override
@RabbitHandler
public void process(final CreateDayAheadTradeRequest event) {
// Do something
}
}
И следующий:
@Service
@RabbitListener(queues = "#{changeDataQueue.name}")
public class UpdateDayAheadTradeListener implements DayAheadTradeEventListener<ModifyDayAheadTradeStatusRequest> {
@Autowired
private DayAheadTradeRepository repository;
@Override
@RabbitHandler
public void process(final ModifyDayAheadTradeStatusRequest event) {
// Do something
}
}
Конфиг Кролика:
@EnableRabbit
@Configuration
public class RabbitMqConfig {
private final String createDayAheadTradesRouting = CreateDayAheadTradeRequest.class
.getAnnotation(Routing.class)
.routingKey();
private final String updateDayAheadTradesRouting = ModifyDayAheadTradeStatusRequest.class
.getAnnotation(Routing.class)
.routingKey();
private final String requestDayAheadTradesRouting = DayAheadTradeRequest.class
.getAnnotation(Routing.class)
.routingKey();
@Bean
public TopicExchange topicExchange() {
return new TopicExchange("schedule"); // exchange name
}
@Bean
public Queue changeDataQueue() {
return QueueBuilder
.durable("dayahead.trades.data") // queue template name
.build();
}
@Bean
public Queue requestQueue() {
return QueueBuilder
.nonDurable("dayahead.trades.request") // queue template name
.exclusive()
.build();
}
@Bean
public Binding createDataBinding(final Queue changeDataQueue, final TopicExchange topicExchange) {
return BindingBuilder
.bind(changeDataQueue)
.to(topicExchange)
.with(createDayAheadTradesRouting);
}
@Bean
public Binding updateDataBinding(final Queue changeDataQueue, final TopicExchange topicExchange) {
return BindingBuilder
.bind(changeDataQueue)
.to(topicExchange)
.with(updateDayAheadTradesRouting);
}
@Bean
public Binding requestBinding(final Queue requestQueue, final TopicExchange topicExchange) {
return BindingBuilder
.bind(requestQueue)
.to(topicExchange)
.with(requestDayAheadTradesRouting);
}
@Bean
public Jackson2JsonMessageConverter producerJackson2MessageConverter() {
final ObjectMapper mapper = EventUtils.createMapper();
mapper.registerModule(new MarketdataModule());
return new Jackson2JsonMessageConverter(mapper);
}
}
Проблема в том, что если я создаю 2 отдельные очереди для разных типов объектов - все работает нормально, но идея состоит в том, чтобы использовать одну очередь для нескольких типов объектов. Но у меня есть следующее исключение:
org.springframework.amqp.rabbit.support.ListenerExecutionFailedException: Listener method 'no match' threw exception
at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:219)
at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandlerAndProcessResult(MessagingMessageListenerAdapter.java:143)
at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.onMessage(MessagingMessageListenerAdapter.java:132)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1569)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.actualInvokeListener(AbstractMessageListenerContainer.java:1488)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:1476)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:1467)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1411)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:958)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:908)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$1600(SimpleMessageListenerContainer.java:81)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.mainLoop(SimpleMessageListenerContainer.java:1279)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1185)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.springframework.amqp.AmqpException: No method found for class java.util.LinkedHashMap
at org.springframework.amqp.rabbit.listener.adapter.DelegatingInvocableHandler.getHandlerForPayload(DelegatingInvocableHandler.java:149)
at org.springframework.amqp.rabbit.listener.adapter.DelegatingInvocableHandler.invoke(DelegatingInvocableHandler.java:129)
at org.springframework.amqp.rabbit.listener.adapter.HandlerAdapter.invoke(HandlerAdapter.java:61)
at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:211)
... 13 more
Я не могу найти информацию об этом, я надеюсь, что кто-то знает об этом. Спасибо