[openamq-dev] amq_content_basic... destroy vs unlink

Dmitri Tsyganov dmitri.tsyganov at dowjones.com
Thu Oct 25 17:55:55 CEST 2007


Hello,

I have an application that publishes content_basic Open AMQ messages in
a very rapid order. (who does not :))

The external level of my application is responsible for creating actual
content (data). 

I have noticed some discrepancies with my data and need some
clarification from the experts. I looked at the code and I have some
ideas, but I want to make sure that my assumptions are correct.

According to the documentation I should be using
amq_content_basic_destroy on the content created with
amq_content_basic_new.

Sample code with my comments is attached.

Here are my questions:

1. amq_content_basic_set_body does not copy content, only content
pointer (although it duplicates exchange and routing key strings).
amq_client_session_basic_publish is an asynchronous call. So it is not
safe to destroy message body right after the call, right? Is is safe to
call amq_content_basic_destroy? 

2. Should I be calling unlink instead? Will it free the content memory?

3. When I pass "mem free" callback to ..._set_body and then, after
calling publish, I call amq_content_basic_destroy - I get following
assertion:

ipr_bucket_list.c:1203: ipr_bucket_list_first_: Assertion `self' failed.

It does not assert if I call unlink instead. But... see question #2

Thank you very much in advance!

Dmitri


-------------- next part --------------


// External layer provides message content
const MessageContent* message = pOutbox->newMessage();

if( message && message->nSize )
{
    //  Create new content and publish it
    amq_content_basic_t *content = amq_content_basic_new ();

    // allocate temp content buffer (from my cache) 
    char* cache = content_new(); 

    if( content && cache )
    {
        // copy message content into temp buffer
	if(message->nSize <= MC_MAX_CONTENT)
	{
	    memcpy(cache, message->pContent, message->nSize);
	}

	// *** was using this,... but I need to know when it is safe to clear content 		
	// amq_content_basic_set_body(content, cache, message->nSize, NULL);

	// content_destroy is a pointer to an icl_mem_free compatible function
	amq_content_basic_set_body(content, cache, message->nSize, content_destroy);

	amq_content_basic_set_message_id(content, message->szID);

	// publish content 
	nError = amq_client_session_basic_publish(m_pSession, // session
						  content, // content reference
						  0, // access ticket (unused - use 0)
						  message->szExchange, // exchange name
						  message->szKey, // routing key
						  0, // if 1, must be routable
						  0); // if 1, must be deliverable

	// when use destroy - receive asserts in 
	//
	// ipr_bucket_list.c:1203: ipr_bucket_list_first_: Assertion `self' failed.
	//
	// it asserts ONLY when I provide callback in ..._set_body 
	// amq_content_basic_destroy (&content);
	
	// OK when using unlink... but will it free the content memory
	amq_content_basic_unlink (&content);
    }
	
    // notify external layer that I am done with message content and it can be safely
    // destroyed/reused
    pOutbox->freeMessage(message);
}


More information about the openamq-dev mailing list