Я создаю сообщение rabbitmq messageListener и хотел бы иметь возможность получить доступ к конфигурации connectionfactory в методе onMessage, возможно ли это? Это было бы полезно для регистрации и других деталей. Возможность вести журнал, из которого было отправлено сообщение, была бы полезной, и она не была доступна в самом сообщении. Вот мой потребитель и конфигурацииAccess connectionfactory внутри messageListener onMessage
public class Consumer implements MessageListener {
@Override
public void onMessage(Message message) {
//how can I get the connection factory configuration when a message is sent?
}
здесь конфиг
{
@Configuration
@EnableAutoConfiguration
public class RabbitConfig {
private static final String SIMPLE_MESSAGE_QUEUE = "qDLX2.dlq";
@Bean
public ConnectionFactory connectionFactory() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory("server");
connectionFactory.setUsername("admin");
connectionFactory.setPassword("ad,om");
connectionFactory.setPort(5672);
connectionFactory.setVirtualHost("vhost1");
return connectionFactory;
}
@Bean
public RabbitTemplate rabbitTemplate() {
RabbitTemplate template = new RabbitTemplate(connectionFactory());
return template;
}
@Autowired
private Consumer consumer;
@Bean
public SimpleMessageListenerContainer listenerContainer() {
SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer();
listenerContainer.setConnectionFactory(connectionFactory());
listenerContainer.setQueueNames(SIMPLE_MESSAGE_QUEUE);
listenerContainer.setMessageListener(consumer);
listenerContainer.setAcknowledgeMode(AcknowledgeMode.AUTO);
return listenerContainer;
}
}
Благодаря Gregg