Add newlines to avrorouter JSON output

JSON does not have a concept of streams and a common way to stream JSON is
to separate each JSON object with a newline. Adding a newline makes it
easier to parse as JSON values do not natively contain newlines.
This commit is contained in:
Markus Makela
2016-11-28 22:22:09 +02:00
parent 2fe13719bc
commit 9362954e82
2 changed files with 10 additions and 6 deletions

View File

@ -80,7 +80,7 @@ avro_client_handle_request(AVRO_INSTANCE *router, AVRO_CLIENT *client, GWBUF *qu
if (avro_client_do_registration(router, client, queue) == 0)
{
client->state = AVRO_CLIENT_ERRORED;
dcb_printf(client->dcb, "ERR, code 12, msg: Registration failed");
dcb_printf(client->dcb, "ERR, code 12, msg: Registration failed\n");
/* force disconnection */
dcb_close(client->dcb);
rval = 0;
@ -88,7 +88,7 @@ avro_client_handle_request(AVRO_INSTANCE *router, AVRO_CLIENT *client, GWBUF *qu
else
{
/* Send OK ack to client */
dcb_printf(client->dcb, "OK");
dcb_printf(client->dcb, "OK\n");
client->state = AVRO_CLIENT_REGISTERED;
MXS_INFO("%s: Client [%s] has completed REGISTRATION action",
@ -558,11 +558,15 @@ const char* get_avrofile_name(const char *file_ptr, int data_len, char *dest)
static int send_row(DCB *dcb, json_t* row)
{
char *json = json_dumps(row, JSON_PRESERVE_ORDER);
GWBUF *buf;
size_t len = strlen(json);
GWBUF *buf = gwbuf_alloc(len + 1);
int rc = 0;
if (json && (buf = gwbuf_alloc_and_load(strlen(json), (void*)json)))
if (json && buf)
{
uint8_t *data = GWBUF_DATA(buf);
memcpy(data, json, len);
data[len] = '\n';
rc = dcb->func.write(dcb, buf);
}
else