Question Regarding Changing Headers

43 views
Skip to first unread message

wil...@gmail.com

unread,
Dec 3, 2016, 4:00:27 PM12/3/16
to simpleamqpclient-users


I keep getting a munmap exception when I try to execute this method. The issue has to do with the BasicMessages created below. When I use a normal message with only std::string as the input, then it works. When I try to set the headers I get the munmap exception. I am trying to send plain text.

Here is the method:

void send_message(AmqpClient::Channel::ptr_t conn, std::string message, std::string header, std::string exchange, std::string key, bool json) {
    amqp_basic_properties_t props;
    props._flags = AMQP_BASIC_CONTENT_TYPE_FLAG | AMQP_BASIC_DELIVERY_MODE_FLAG | AMQP_BASIC_HEADERS_FLAG;

    if (json) {
        props.content_type = amqp_cstring_bytes("application/json");
    } else {
        props.content_type = amqp_cstring_bytes("text/plain");
    }

    props.delivery_mode = 1;

    amqp_table_entry_t entries[1];
    amqp_table_t table;

    entries[0].key = amqp_cstring_bytes(key.c_str());
    entries[0].value.kind = AMQP_FIELD_KIND_UTF8;
    amqp_bytes_t name = amqp_cstring_bytes(header.c_str());
    entries[0].value.value.bytes = name;

    table.num_entries = 1;
    table.entries = entries;

    props.headers = table;

    amqp_bytes_t bytes = amqp_cstring_bytes(message.c_str());

    // Option 1 with headers that I want
    AmqpClient::BasicMessage::ptr_t c_message = AmqpClient::BasicMessage::Create(bytes, &props);

    // Option 2 without headers I want
    AmqpClient::BasicMessage::ptr_t b_message = AmqpClient::BasicMessage::Create(message);

    conn->BasicPublish(exchange, key, c_message, false, false);

}

Alan Antonuk

unread,
Dec 3, 2016, 4:19:30 PM12/3/16
to wil...@gmail.com, simpleamqpclient-users
That version of BasicMessage::Create should probably not have been exposed as a public API.

Instead of constructing the props using rabbitmq-c interfaces yourself and passing it in, create the BasicMessage object, then use BasicMessage::ContentType(), BasicMessage::DeliveryMode and BasicMessage::Headers to set these message properties.

-Alan

--
You received this message because you are subscribed to the Google Groups "simpleamqpclient-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simpleamqpclient-...@googlegroups.com.
To post to this group, send email to simpleamqpc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/simpleamqpclient-users/46b178ad-2489-4dd5-b021-c372b3c424da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

wil...@gmail.com

unread,
Dec 3, 2016, 4:30:41 PM12/3/16
to simpleamqpclient-users
On the repo I don't see that method in BasicMessage.h. Is there a corresponding method elsewhere? The closest method I see is HeaderTable(const Table &header_table)
To unsubscribe from this group and stop receiving emails from it, send an email to simpleamqpclient-users+unsub...@googlegroups.com.

Alan Antonuk

unread,
Dec 3, 2016, 4:31:51 PM12/3/16
to wil...@gmail.com, simpleamqpclient-users
Oop, I meant HeaderTable(), yes thats correct.

To unsubscribe from this group and stop receiving emails from it, send an email to simpleamqpclient-...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "simpleamqpclient-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simpleamqpclient-...@googlegroups.com.

To post to this group, send email to simpleamqpc...@googlegroups.com.

wil...@gmail.com

unread,
Dec 3, 2016, 4:50:18 PM12/3/16
to simpleamqpclient-users
Could I bother you for an example? Right now this is really confusing me.

Can you set more than one header and can you set an "id" to each header?
To unsubscribe from this group and stop receiving emails from it, send an email to simpleamqpclient-users+unsub...@googlegroups.com.
To post to this group, send email to simpleamqpc...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "simpleamqpclient-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simpleamqpclient-users+unsub...@googlegroups.com.

Alan Antonuk

unread,
Dec 5, 2016, 1:52:20 AM12/5/16
to wil...@gmail.com, simpleamqpclient-users
Table is a typedef for std::map<std::string, TableValue>.  Adding a bunch of headers might look like (I haven't run this through a compiler, so there may be errors):

BasicMessage::ptr_t message = BasicMessage::Create("message body");
Table headers;

headers.insert(std::make_pair("header1", TableValue("value1"));
headers.insert(std::make_pair("header2", TableValue(123));

message->HeaderTable(headers);

-Alan



To unsubscribe from this group and stop receiving emails from it, send an email to simpleamqpclient-...@googlegroups.com.
To post to this group, send email to simpleamqpc...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "simpleamqpclient-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simpleamqpclient-...@googlegroups.com.

To post to this group, send email to simpleamqpc...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "simpleamqpclient-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simpleamqpclient-...@googlegroups.com.

To post to this group, send email to simpleamqpc...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages