[rabbitmq-discuss] RabbitMQ erlang client documentation

Vlad Alexandru Ionescu vlad at lshift.net
Thu Dec 3 17:24:10 GMT 2009


Hi Sylvain,


I will try to answer your questions.

> it seems things have quite changed since
> September
As far as I know, apart from replacing the amqp_connection:start with 
start_direct and start_network and the new approach with #amqp_params{}, 
the API remained the same.
Yes, there has been a lot of refactoring behind the scenes, but we 
didn't touch the API.

> For instance the test suite seems to suggest one should be using
> amqp_connection:start(Params) to create a new connection but, unless I'm
> mistaken, that function doesn't exist and you must use directly either
> start_network or start_direct.
The right way of starting a connection is using either of the functions 
start_network or start_direct in amqp_connection. The start function has 
been removed quite some time ago.

> Also, it's unclear whether or not you can safely reuse Connections across
> several erlang nodes concurrently or if there are some issues in doing so.
> Can I use one connection and cretae as many channels as I want? Should
> channel be on a per erlang process basis?
As far as I am aware both the connection and the channel processes have 
been designed to be used from multiple processes. They are in fact 
gen_server's.
Not only that creating a single connection with as many channels as you 
like is possible, but it is also the recommended style. The maximum 
number of channels is 65535 I think, unless it is specified otherwise by 
the server (RabbitMQ server doesn't specify another limit). That should 
probably be more than enough.

> Another blurry point is whether or not one can use amqp_channel_util
> functions or if they are rather internals to the lib. If the former, how
> to use them the best?
amqp_channel_util is strictly for internal use. You shouldn't use 
functions in it.

The new modules amqp_network_connection and amqp_direct_connection are 
also for internal use. User apps should use amqp_connection instead.

> I have a gen_server where I direct all my AMQP calls (publish, etc.) and
> within that gen_server I create a pool of connections. Should this pool
> reside in its own gen_server so that each connection belongs to one single
> supervised erlang process? Currently I keep the pool within the
> gen_server's state. But this means I'm concurrently using the same
> connection for different channels. Is that safe?
As answered above, you don't need to worry about using the connection 
from different processes. The connection process itself is a gen_server, 
and what you get with amqp_connection:start_network() is just the pid of 
the spawned connection process, that you can use from anywhere (any 
process) in your application.
I'm not sure about your exact use case, but I think using a gen_server 
to interface with the RabbitMQ Erlang client is unnecessary.

Perhaps, at the moment, the best place to see how the client is used is 
the test_util module in the test folder. It is not very clean, but some 
of the tests should be fairly easy to understand.


HTH,
Vlad.


-- 

 [][][] Vlad Alexandru Ionescu | Developer
   [][] LShift Ltd             | Tel: +44 (0)20 7729 7060
 []  [] www.lshift.net         | Email: vlad at lshift.net






More information about the rabbitmq-discuss mailing list