java - Why is my Spring Boot application creating durable queue in one program and non-durable in another in RabbitMQ -
i have 2 spring based programs. both of them publishes simple "hello world" message onto queues (gets created automatically) successfully. 1 program creates non-durable queue whereas other 1 creates durable. program not specifying parameters creating either of these. not sure how queue creation in spring framework works.
basicapplication1.java
@springbootapplication public class basicapplication1 { private static rabbittemplate rabbittemplate; private static final string queue_name = "helloworld.q"; @bean public queue queue() { return new queue(queue_name, false); } //creates "non-durable" queue in rabbitmq public static void main(string[] args) { try (configurableapplicationcontext ctx = springapplication.run(basicapplication1.class, args)) { rabbittemplate = ctx.getbean(rabbittemplate.class); rabbittemplate.convertandsend(queue_name, "hello world !"); } } }
basicapplication2.java
@springbootapplication public class basicapplication2{ @bean public queue queue() { return new queue("helloworld2.q"); } public static void main(string[] args) { springapplication.run(basicapplication2.class, args); } }
producer.java
@component public class producer implements commandlinerunner { @autowired private rabbittemplate rabbittemplate; @autowired private queue queue; //creates "durable" queue in rabbitmq @override public void run(string... args) throws exception { this.rabbittemplate.convertandsend(this.queue.getname(), "hello world !"); } }
Comments
Post a Comment