我有以下程序寫在Spring Boot
這工作正常。但問題是,我不確定我是否應該使用RabbitTemplate
或AmqpTemplate
。一些在線示例/教程使用RabbitTemplate
,而另一些則使用AmqpTemplate
。哪一個使用RabbitTemplate或AmqpTemplate?
請指導什麼是最佳實踐和應該使用哪一個。
@SpringBootApplication
public class BasicApplication {
private static RabbitTemplate rabbitTemplate;
private static final String QUEUE_NAME = "helloworld.q";
//this definition of Queue is required in RabbitMQ. Not required in ActiveMQ
@Bean
public Queue queue() {
return new Queue(QUEUE_NAME, false);
}
public static void main(String[] args) {
try (ConfigurableApplicationContext ctx = SpringApplication.run(BasicApplication.class, args)) {
rabbitTemplate = ctx.getBean(RabbitTemplate.class);
rabbitTemplate.convertAndSend(QUEUE_NAME, "Hello World !");
}
}
}