Reputation: 1679
I use librabbitmq C library to deal with AMQP-complaint brokers (RabbitMQ in my case) and i try to add headers onto the c client, for rabbitmq.
I modified amqp_sendstring.c
amqp_basic_properties_t props; props._flags = AMQP_BASIC_CONTENT_TYPE_FLAG | AMQP_BASIC_DELIVERY_MODE_FLAG | AMQP_BASIC_HEADERS_FLAG; props.content_type = amqp_cstring_bytes("text/plain"); props.delivery_mode = 2; /* persistent delivery mode */ amqp_table_t *table=&props.headers; props.headers.num_entries=2; props.headers.entries=calloc(props.headers.num_entries, sizeof(amqp_table_entry_t)); strcpy(&(table->entries[0]).key,"id1"); ((table->entries[0]).value).kind=AMQP_FIELD_KIND_I32; ((table->entries[0]).value).value.i32=1234; strcpy(&(table->entries[1]).key,"id2"); (table->entries[1]).value.kind=AMQP_FIELD_KIND_I32; (table->entries[1]).value.value.i32=5678; die_on_error(amqp_basic_publish(conn, 1, amqp_cstring_bytes(exchange), amqp_cstring_bytes(routingkey), 0, 0, &props,
and in amqp_listen.c:
132 printf("Num headers received %d \n", envelope.message.properties.headers.num_entries);
However the listener doesn't seem to receive any headers. Any body have any suggestions? Other sample code?
Upvotes: 0
Views: 2064
Reputation: 2026
The .key
member of amqp_table_entry_t
is an amqp_bytes_t
not a char*
, so you should use amqp_cstring_bytes()
to set it instead of strcpy()
.
Upvotes: 3