0
나는 sprin 클라우드 설정과 RabbitMQ를 연결합니다사용 봄 클라우드 봄 서비스 RabbitMQ와 커넥터 및 시작 게시자 설정 기능
@Bean
public ConnectionFactory rabbitConnectionFactory() {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("publisherConfirms", true);
RabbitConnectionFactoryConfig rabbitConfig = new RabbitConnectionFactoryConfig(properties);
return connectionFactory().rabbitConnectionFactory(rabbitConfig);
}
삭제 2. rabbitTemplate.setMandatory (사실)와 setConfirmCallback을() :
@Bean
public RabbitTemplate rabbitTemplate() {
RabbitTemplate template = new RabbitTemplate(connectionFactory);
template.setMandatory(true);
template.setMessageConverter(new Jackson2JsonMessageConverter());
template.setConfirmCallback((correlationData, ack, cause) -> {
if (!ack) {
System.out.println("send message failed: " + cause + correlationData.toString());
} else {
System.out.println("Publisher Confirm" + correlationData.toString());
}
});
return template;
}
3. publisherConfirm 및 인쇄 로그를 호출하기 위해 대기열에 메시지를 보냅니다.
@Component
public class TestSender {
@Autowired
private RabbitTemplate rabbitTemplate;
@Scheduled(cron = "0/5 * * * * ? ")
public void send() {
this.rabbitTemplate.convertAndSend(EXCHANGE, "routingkey", "hello world",
(Message m) -> {
m.getMessageProperties().setHeader("tenant", "aaaaa");
return m;
}, new CorrelationData(UUID.randomUUID().toString()));
Date date = new Date();
System.out.println("Sender Msg Successfully - " + date);
}
}
게시자 확인이 작동하지 않았습니다. 로그가 인쇄되지 않았습니다. true 또는 false로 설정하면 로그가 없어지지 않습니다.
로컬에서이 스 니펫을 실행하므로이 문제를 발견했다고 생각합니다. 클라우드 구성의 ConnectionFactory는 사용되지 않습니다. 따라서 publisherConfrims는 활성화되어 있지 않습니다. 고맙습니다. – Maxwell