これはRabbitTemplate
@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;
}
である。これは、春・クラウドの設定:
@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);
}
この送信者を使ってメッセージを送信します。その結果は期待できません。
@Component
public class TestSender {
@Autowired
private RabbitTemplate rabbitTemplate;
@Scheduled(cron = "0/5 * * * * ? ")
public void send() {
System.out.println("===============================================================");
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);
}
}
クール - 私はそれを知らなかった。メモ[typoはドキュメント](https://github.com/spring-cloud/spring-cloud-connectors/issues/220)です。実際の戻り値の型は 'org.springframework.amqp.rabbit.connection.ConnectionFactory'です。 –
問題のおかげでゲーリー、私はそれを見てみましょう。 –
ありがとうございました。 – Maxwell