[rabbitmq-discuss] Librabbitmq-c API
David Wragg
david at rabbitmq.com
Fri Sep 2 12:31:22 BST 2011
Alex P <oleksandr.petrov at gmail.com> writes:
> So far we went with a toolset that's defined in ./examples and ./
> tools, but, for instance in example for listenqueue framing is done
> manually. Is there a high-level API for receiving a whole message in
> case it's there and getting AMQP_BASIC_GET_EMPTY_METHOD or anything
> else if body is empty / nothing received?
You're right, the support for consuming messages is quite low-level.
There's no particularly good reason for that, although designing an
efficient general purpose high-level API is non-trivial. You can write
easily write one that meets the needs of your application though, and I
would recommend you do so.
For example, the code in tools/ is able to directly output message
contents from the memory buffers managed by librabbitmq. The copy_body
function in tools/common.c encapsulates this.
But other applications might want to malloc a single block of memory for
each incoming message body, and copy the body data from the frames into
that. Etc.
> amqp_basic_get(conn, 1, queue, 1); seemed to be a good candidate for
> that, but still in codegen.py it's marked as one of those methods that
> should not be exposed as an API.
amqp_basic_get is exposed as an API. It's defined in amq_api.c, and is
definitely intended for use by applications.
It is marked for special handling in codegen.py simply because the
autogenerated definition would not be correct (the comment there is
misleading; the real issue is that basic.get has two possible responses:
AMQP_BASIC_GET_OK_METHOD and AMQP_BASIC_GET_EMPTY_METHOD).
> So, my question would be - what is the best way to receive messages?
> Should we handle framing manually, as it's done in examples? If not,
> what are the api methods that we should stick to?
Do it manually, but by writing your own code to encapsulate the
low-level frame handling. librabbitmq might get a higher-level API one
day, and by encapsulating the code that uses the current API, you'll
find it easier to transition.
David
--
David Wragg
Staff Engineer, RabbitMQ
VMware, Inc.
More information about the rabbitmq-discuss
mailing list