rabbitmq - how to set queue/message durability to false in Spring AMQP using annotations? -
i wrote sample spring amqp producer running on rabbitmq server sends messages , consuming messages uisng messagelistener using spring amqp. here, want set queue , message durability false. please 1 me on how set "durable" flag false using annotations.
here sample code
@configuration
public class producerconfiguration {
protected final string queuename = "hello.queue"; @bean public rabbittemplate rabbittemplate() { rabbittemplate template = new rabbittemplate(connectionfactory()); template.setroutingkey(this.queuename); template.setqueue(this.queuename); return template; } @bean public connectionfactory connectionfactory() { cachingconnectionfactory connectionfactory = new cachingconnectionfactory("localhost"); connectionfactory.setusername("guest"); connectionfactory.setpassword("guest"); return connectionfactory; }
}
public class producer { public static void main(string[] args) throws exception { new producer().send(); } public void send() { applicationcontext context = new annotationconfigapplicationcontext( producerconfiguration.class); rabbittemplate rabbittemplate = context.getbean(rabbittemplate.class); (int = 1; <= 10; i++) { rabbittemplate.convertandsend(i); } }
}
thanks in advance.
@configuration public class config { @bean public connectionfactory connectionfactory() { return new cachingconnectionfactory(); } @bean public queue foo() { return new queue("foo", false); } @bean public rabbitadmin rabbitadmin() { return new rabbitadmin(connectionfactory()); } }
the rabbit admin declare queue first time connection opened. note can't change queue durable not; delete first.
Comments
Post a Comment