我正在學習RabbitMq,只是想發送規定次數的訊息。 我有發送器類,它將訊息發送到交換機,并且我想重復它的某些次數。 我正在使用預定注釋,但它有不同的目的,而且與我不匹配,因為它沒有停止。
@Scheduled(initialDelay = 1000,fixedDelay = 1500)
public void sendNumbers(){
int index = atomicInteger.getAndIncrement()。
UID uuid = uuids.get(index);
Pair<Integer,Integer> pair = sumPair.get(uuid)。
MessagePostProcessor messagePostProcessor = message -> {
MessageProperties messageProperties = message.getMessageProperties()。
messageProperties.setCorrelationId(uuid.toString())。
messageProperties.setReplyTo(response.getName())。
return訊息。
};
rabbitTemplate.convertAndSend(directExchange.getName(),routingKey,pair,messagePostProcessor)。
}
我怎么做?
我怎么做?
uj5u.com熱心網友回復:
只需使用一個for回圈來重復你想要的次數。
你可以在一個ApplicationRunner中進行。
@Bean
ApplicationRunner runner(RabbitTemplate模板) {
return()-> {
for (int i = 0。i < 10; i ) {
...
template.convertAndSend(...)
}
};
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/308786.html
標籤:
上一篇:如何用firebaseadmin捕捉firebaseauth的錯誤?
下一篇:<p>我建立了這個BST,并試圖遵循java代碼慣例,我決定圍繞一些訪問修飾符進行修復,并添加了一些getters和setters,但現在我的整個代碼在執行中出現了很多問題,我無法弄清楚原
