[rabbitmq-discuss] Erlang strings and binstrings (newbie question)

Alexandru Scvorţov alexandru at rabbitmq.com
Fri Oct 28 11:52:28 BST 2011


> I know the differences between strings and bitstrings but, why don't we
> allways use one of them? why sometimes strings and others bitstrings?

Because some of the fields are part of the actual AMQP methods and some
are just used by the client.  The fields in the AMQP methods are going
to be sent over the network, and the client will not inspect them, so
they're binaries.

So, host is a string because the client uses that to open the
connection, but routing_key is a binary because it's a parameter in the
methods and is blindly sent over the network.

You have to use the right one (string or binary), of course, otherwise,
you get errors from deep inside the client.

Hope this helps.

Cheers,
Alex

On Fri, Oct 28, 2011 at 12:29:28PM +0200, Farruco Sanjurjo wrote:
> Hi,
> 
> I'm using this (
> https://github.com/rabbitmq/rabbitmq-tutorials/tree/master/erlang)  erlang
> examples as an entry point to RabbitMQ and due to the fact that I'm also a
> newbie to erlang there's something I don't get.
> 
> In the send.erl example, when you connect to the RabbitMQ server you specify
> the host with a string ("localhost") but ,for example, when you specify the
> routing_key you use a bitstring (<<"hello">>).
> 
> I know the differences between strings and bitstrings but, why don't we
> allways use one of them? why sometimes strings and others bitstrings?
> 
> Thanks,
> Farruco Sanjurjo

> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss



More information about the rabbitmq-discuss mailing list