Нужна помощь в разработке решения для поддержки приведенного ниже сценария
Я пытаюсь реализовать приложение весенней загрузки, которое может поддерживать RabbitMQ Azure Service BUS и Amazon MQ в одном приложении. Но одновременно будет действовать только одна очередь (одна из трех) на основе свойства, которое мы собираемся установить из файла свойств
Код: Выделить всё
messaging.queue.type: rabbitmq #azure or rabbitmq or aws
Код: Выделить всё
@Configuration
@ConditionalOnProperty(name = "messaging.queue.type", havingValue = "rabbitmq")
public class RabbitMQConfig {
@Autowired
QueueProperties properties;
@Bean
CachingConnectionFactory connectionFactory() {
return CommonRabbitMQConfig.connectionFactory(
properties.getHost(),
properties.getPort(),
properties.getUsername(),
properties.getPassword(),
Boolean.valueOf(properties.getIsSsl()));
}
Код: Выделить всё
@Service
@Slf4j
public class RabbitMQHandler {
@Autowired RabbitMQConsumer consumer;
@RabbitListener(
queues = "${spring.rabbitmq.producers[0].queues[0].name}",
containerFactory = "publicRabbitListenerContainerFactory")
public void handle(Message message, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) {
try {
channel.basicAck(tag, true);
validateInbound(message);
} catch (BadInboundRequestException | IOException e) {
log. Warn("Inbound message has bad header :: {}", e.getMessage());
return;
}
if (Arrays.asList(properties.getQueue().getInbound().getEvents())
.contains(message.getHeaders().get(EVENT_HEADER_KEY))) consumer. Consume(message);
else log. Warn("Inbound message ignored :: {}", IGNORE_MESSAGE);
}
How can I manage this all and also support other 2 services and add flag that can ON or OFF certain messaging queue?
or do we need to add @conditional annotation on Handeler class also ?
I can use the factory method but I am more looking from configuration perspection and how to isolate complete queue code of aws /rabbitmq and azure bus so that I should not have bean dependency exception in app.
regards
Dnyaneshwar Muley
Источник: https://stackoverflow.com/questions/781 ... ue-pattern