summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Gough <agough@transtech.net.au>2016-09-09 11:43:09 +1000
committerAlan Antonuk <alan.antonuk@gmail.com>2016-09-11 21:51:13 -0700
commitb1acb373661a9a799428b50fa402be231013e374 (patch)
tree09420d2810ac027b4a23b16eb9fea5ec396c1b75
parent547c37ff1cc3c221d1b00c30f68eb1d6c1076d2c (diff)
downloadrabbitmq-c-b1acb373661a9a799428b50fa402be231013e374.tar.gz
Add ability to specify headers on the command line for amqp-publish
-rw-r--r--tools/doc/amqp-publish.xml9
-rw-r--r--tools/publish.c39
2 files changed, 48 insertions, 0 deletions
diff --git a/tools/doc/amqp-publish.xml b/tools/doc/amqp-publish.xml
index e609972..aae07f4 100644
--- a/tools/doc/amqp-publish.xml
+++ b/tools/doc/amqp-publish.xml
@@ -118,6 +118,15 @@
</para>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-H</option></term>
+ <term><option>--header</option>=<replaceable class="parameter">header</replaceable></term>
+ <listitem>
+ <para>
+ Specifies an optional header in the form "key: value".
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
</refsect1>
diff --git a/tools/publish.c b/tools/publish.c
index c65bdf6..acb63bc 100644
--- a/tools/publish.c
+++ b/tools/publish.c
@@ -64,12 +64,14 @@ int main(int argc, const char **argv)
static char *routing_key = NULL;
static char *content_type = NULL;
static char *content_encoding = NULL;
+ static char **headers = NULL;
static char *reply_to = NULL;
static char *body = NULL;
amqp_basic_properties_t props;
amqp_bytes_t body_bytes;
static int delivery = 1; /* non-persistent by default */
static int line_buffered = 0;
+ static char **pos;
struct poptOption options[] = {
INCLUDE_OPTIONS(connect_options),
@@ -103,6 +105,10 @@ int main(int argc, const char **argv)
"the content-encoding for the message", "content encoding"
},
{
+ "header", 'H', POPT_ARG_ARGV, &headers, 0,
+ "set a message header (may be specified multiple times)", "\"key: value\""
+ },
+ {
"body", 'b', POPT_ARG_STRING, &body, 0,
"specify the message body", "body"
},
@@ -137,6 +143,35 @@ int main(int argc, const char **argv)
props.reply_to = amqp_cstring_bytes(reply_to);
}
+ if (headers) {
+ int num = 0;
+ for (pos = headers; *pos; pos++) {
+ num++;
+ }
+
+ if (num > 0) {
+ amqp_table_t *table = &props.headers;
+ table->num_entries = num;
+ table->entries = calloc(num, sizeof(amqp_table_entry_t));
+ int i = 0;
+ for (pos = headers; *pos; pos++) {
+ char *colon = strchr(*pos, ':');
+ if (colon) {
+ *colon++ = '\0';
+ while (*colon == ' ') colon++;
+ table->entries[i].key = amqp_cstring_bytes(*pos);
+ table->entries[i].value.kind = AMQP_FIELD_KIND_UTF8;
+ table->entries[i].value.value.bytes = amqp_cstring_bytes(colon);
+ i++;
+ }
+ else {
+ fprintf(stderr, "Ignored header definition missing ':' delimiter in \"%s\"\n", *pos);
+ }
+ }
+ props._flags |= AMQP_BASIC_HEADERS_FLAG;
+ }
+ }
+
conn = make_connection();
if (body) {
@@ -157,6 +192,10 @@ int main(int argc, const char **argv)
do_publish(conn, exchange, routing_key, &props, body_bytes);
}
+ if (props.headers.num_entries > 0) {
+ free(props.headers.entries);
+ }
+
if (!body) {
free(body_bytes.bytes);
}