[rabbitmq-discuss] RE : test of a existing queue
Cyril LECLERC
Cyril.LECLERC at pragmaconsult.lu
Fri Feb 22 17:00:09 GMT 2013
thank you for your reactivity
channel.queueDeclarePassive(queueName) will throw an exception if the queue doesn't exist.
Yes but the solution needs to use a Channel object, use @Inject of the factory, and it is not a boolean method so utilisation of spring amqp has no avantage and more it closes the channel connection!!!!we have to declare az new channel because spring create one by default plus all my consumers...for the moment my code is like this (in a wicket appplication) :
@Inject
AmqpTemplate amqpTemplate;
amqpTemplate.convertAndSend("queue", messageField.getValue().toString());
my spring configuration :
<!-- now we can use -->
<context:property-placeholder location="${ext.properties.dir}" />
<rabbit:connection-factory id="rabbitConnectionFactory"
host="${config.amqp.server}" username="${config.amqp.username}" password="${config.amqp.password}" />
<!-- Creates a org.springframework.amqp.rabbit.core.RabbitTemplate for access
to the broker -->
<rabbit:template id="amqpTemplate" connection-factory="rabbitConnectionFactory" />
<!-- Creates a queue for consumers to retrieve messages -->
<rabbit:queue id="queue" name="${config.amqp.queuename}" />
<bean id="messageListener" class="lu.pragmaconsult.geocamp.receiver.MessageHandler" />
<rabbit:listener-container
connection-factory="rabbitConnectionFactory" concurrency="${config.amqp.nbconsumer}"
auto-startup="true">
<rabbit:listener queues="queue" ref="messageListener" />
</rabbit:listener-container>
If i use your advice :
@Inject
AmqpTemplate amqpTemplate;
Channel channel;
@Inject
ConnectionFactory rabbitConnectionFactory;
amqpTemplate.convertAndSend("queue", messageField.getValue().toString());
channel =(Channel) rabbitConnectionFactory.createConnection().createChannel(true);
try {
channel.queueDeclarePassive("queue/GeoCampQueue3");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//maybe add the code for verify the queue
amqpTemplate.convertAndSend("queue/GeoCampQueue3", messageField.getValue().toString());
it is not what i want moreover i want the name of queue come from spring and not in code.
No, you can't specify the queue name in the send methods - you don't send to a queue, you send to an exchange, and it routes it to the queue.
if the queue is binding to the exchange by default, it is in direct so the queue name is my "routing key", if i put the name of the exchange ("") nothing happening
i try this :
<rabbit:template id="amqpTemplate" connection-factory="rabbitConnectionFactory" queue="queue" exchange="" routing-key=""/>
but the exchange and routing key is like this by default, so my template don't send automatiqueliy to my queue directly by spring configuration.....
have you got any idéas????
________________________________________
De : rabbitmq-discuss-bounces at lists.rabbitmq.com [rabbitmq-discuss-bounces at lists.rabbitmq.com] de la part de Gary Russell [grussell at vmware.com]
Date d'envoi : vendredi 22 février 2013 17:22
À : Discussions about RabbitMQ
Objet : Re: [rabbitmq-discuss] test of a existing queue
channel.queueDeclarePassive(queueName) will throw an exception if the queue doesn't exist.
You can get a channel by
Channel channel = factory.createConnection().createChannel(false);
where factory is a reference to the CachingConnectionFactory.
No, you can't specify the queue name in the send methods - you don't send to a queue, you send to an exchange, and it routes it to the queue.
----- Original Message -----
From: "Cyril LECLERC" <Cyril.LECLERC at pragmaconsult.lu>
To: "Discussions about RabbitMQ" <rabbitmq-discuss at lists.rabbitmq.com>
Sent: Friday, February 22, 2013 10:54:53 AM
Subject: [rabbitmq-discuss] test of a existing queue
Hello,
How we can test if a queue exits in application? Without the queueDeclare because it is not what i want, indeed, if i use amqpTemplate.convertAndSend(), and the queue does'nt existing, nothing will happen, but i have to know if the queue configured is existing, but not create it...because we use spring amqp.
Moreover how we can configure the name of the queue in this method (amqpTemplate.convertAndSend()) because it takes one string argument but when it is configured in spring i don't have to configure in the code i want to use spring configuration ...
thanks....
Cyril
_______________________________________________
rabbitmq-discuss mailing list
rabbitmq-discuss at lists.rabbitmq.com
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
_______________________________________________
rabbitmq-discuss mailing list
rabbitmq-discuss at lists.rabbitmq.com
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
--
This email was Virus checked by Pragma Consult Security Gateway.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20130222/375dc992/attachment.htm>
More information about the rabbitmq-discuss
mailing list