0
私はrabbitmq messageListenerを作成していますが、onMessageメソッドで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;
}
}
おかげ グレッグ