0

I have some problem so can you help me. Is instance of AmqpTemplate class from RabbitMQ ( implementation of AMQP protocol) thread safe. Can it be accessed from multiple threads?

Thanks

4
  • What package is AmqpTemplate part of? It's not in the Java or .NET clients.
    – scvalex
    Commented Sep 15, 2011 at 15:28
  • Here is some reference about AmqpTemplate and there is nothing about thread-safe: static.springsource.org/spring-amqp/docs/1.0.x/apidocs
    – ttokic
    Commented Sep 15, 2011 at 20:33
  • Mhm. You're right about it not saying. Try posting the question on the RabbitMQ Discuss mailing list: lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
    – scvalex
    Commented Sep 16, 2011 at 9:29
  • I see the developers behind Spring AMQP answer questions posted there. Be sure to include "Spring AMQP" in the subject so that it gets their attention.
    – scvalex
    Commented Sep 16, 2011 at 9:30

1 Answer 1

4

AmqpTemplate is the interface, and RabbitTemplate is the implementation, and I assume by "thread-safe" you mean that its send/receive/sendAndReceive methods may be used concurrently. If so, then YES. The only state it maintains within instance variables are "converter" strategies for the Message and MessageProperties as well as default Exchange, Queue, and Routing Key settings (which are not even used if you invoke the methods that take those as arguments instead), and all of those are typically configured one time initially (e.g. via dependency injection). The template does not maintain any non-local state for any particular operation at runtime. With AMQP, the "Channel" is the instance that can only be used by one thread at a time, and the RabbitTemplate manages that internally such that each operation is retrieving a Channel to use within the scope of that operation. Multiple concurrent operations therefore lead to multiple instances of Channel being used, but that is not something you need to be worried about as an end-user of the template.

Hope that helps. -Mark

Not the answer you're looking for? Browse other questions tagged or ask your own question.