### Description
Consuming messages without message body fails due to a JSON parsing error: ``` ERROR: kazoo [kz_json.c:287]: kz_json_parse(): Error parsing json: unexpected end of data ERROR: kazoo [kz_json.c:288]: kz_json_parse(): ERROR: kazoo [kz_amqp.c:2960]: kz_amqp_send_worker_event(): error parsing json body ``` This makes it unable to consume messages from RabbitMQ's event exchange plugin ( https://www.rabbitmq.com/event-exchange.html ), as the documentatin states: **"The message body is always blank."**
### Possible Solutions As a possible fix I tried following change in kz_amqp.c: ``` void kz_amqp_send_worker_event(kz_amqp_server_ptr server_ptr, amqp_envelope_t* envelope, kz_amqp_bind_ptr bind) { char buffer[100]; kz_amqp_cmd_ptr cmd = NULL; kz_amqp_consumer_delivery_ptr ptr = NULL; json_obj_ptr json_obj = NULL; json_object* JObj = NULL; str* message_id = NULL; int idx = envelope->channel-1; int worker = 0; int _kz_server_id = server_ptr->id; int msg_size = envelope->message.body.len;
//begin of changes int routingkey_size = envelope->routing_key.len;
if (msg_size == 0 && routingkey_size > 0 ) { char *routingkey_data = pkg_malloc(routingkey_size + 1); memset(routingkey_data, 0, routingkey_size + 1); memcpy(routingkey_data, (char*)envelope->routing_key.bytes, routingkey_size);
LM_DBG("Message size: %d\n", msg_size); LM_DBG("Routing Key: %s\n", routingkey_data);
char *pos = strchr(routingkey_data,'.'); while (pos){ *pos = '_'; pos = strchr(pos,'.'); }
LM_DBG("New Routing Key: %s\n", routingkey_data); sprintf(buffer, "kazoo:%s", routingkey_data);
if(kz_amqp_consumer_fire_event(buffer) != 0) { LM_ERR("kazoo:%s not found", routingkey_data); }
pkg_free(routingkey_data); return; }
char *json_data = pkg_malloc(msg_size + 1); if(!json_data) { LM_ERR("no more package memory available. needed %d\n", msg_size + 1); return; }
char *json_data = pkg_malloc(msg_size + 1); //end of changes
if(!json_data) { LM_ERR("no more package memory available. needed %d\n", msg_size + 1); return; } ``` The change is rather simple: If there is no message-body supplied, the event-route _kazoo:<binding_key>_ is called (after replacing any '.' with '_' in the routing_key).
@mihovilkolaric this is by design. your possible fix only allows the publishing of the routing key which in this case is useless. however, this will be taken in consideration when we update the module. thank you
Closed #1837.
Reopened #1837.
Thanks for your fast response! Do you maybe see any other solution/workaround that allows consuming messages from the event-exchange-plugin?
Closing, long time no activity. A PR can be made if someone wants to implement.
Closed #1837 as completed.