[rabbitmq-discuss] Issue in sending binary data using amqp_basic_publish API.
Kiran Kumar
kirankumar.pnm at gmail.com
Mon Nov 18 21:50:17 GMT 2013
I have a rabbitmq server running on my debian linux machine. I have a BGP
process running and it prepared a Route Message using google protocol
buffers. The protocol buffer returns a binary data buffer.
Then I have below code to send this data to rabbitmq server. When I execute
this, the process crashes on amqp_basic_publish call.
Any thoughts on this ? Am I missing some thing here ?
int bgp_mq_send(char const* rt_msg, int size)
{
static int init_done = 0;
int status;
amqp_socket_t *socket = NULL;
amqp_connection_state_t conn = NULL;
amqp_rpc_reply_t reply;
if (init_done == 0) {
conn = amqp_new_connection();
socket = amqp_tcp_socket_new(conn);
if (!socket) {
printf("\n socket creation failed\n");
return 1;
}
status = amqp_socket_open(socket, "localhost", 5672);
if (status) {
printf("\n socket open failed\n");
return 1;
}
reply = amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN,
"guest", "guest");
if (reply.reply_type) {
printf("\n Login is failed\n");
}
amqp_channel_open(conn, 1);
reply = amqp_get_rpc_reply(conn);
if (reply.reply_type) {
printf("\n get_reply failed\n");
}
init_done = 1;
}
{
amqp_basic_properties_t props;
props._flags = AMQP_BASIC_CONTENT_TYPE_FLAG |
AMQP_BASIC_DELIVERY_MODE_FLAG;
props.content_type = amqp_cstring_bytes("gpb");
props.content_encoding = amqp_cstring_bytes("binary");
props.delivery_mode = 2; /* persistent delivery mode */
amqp_bytes_t str2;
str2.len = size;
str2.bytes = rt_msg;
status = amqp_basic_publish(conn, 1,
amqp_cstring_bytes("amq.fanout"),
amqp_cstring_bytes("#"), 0, 0,
&props, str2); *<<<----------- It crashes right
here.*
if (status < 0) {
printf("\n publish failed\n");
}
printf("\n Publish success\n");
}
reply = amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS);
if (reply.reply_type) {
printf("\n chan close failed\n");
}
reply = amqp_connection_close(conn, AMQP_REPLY_SUCCESS);
if (reply.reply_type) {
printf("\n conn close failed\n");
}
status = amqp_destroy_connection(conn);
if (status < 0) {
printf("\n Destroy failed\n");
}
printf("\n All Done\n");
return 0;
}
any help in moving forward would be great.
Thanks,
Kiran.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20131118/c571a539/attachment.htm>
More information about the rabbitmq-discuss
mailing list