onMsg(natsConnection *conn, natsSubscription *sub, natsMsg *msg, void *closure)
printf("Received msg: %s - %.*s\n",
natsMsg_GetDataLength(msg),
// Need to destroy the message!
natsConnection *conn = NULL;
natsSubscription *sub = NULL;
s = natsConnection_ConnectTo(&conn, NATS_DEFAULT_URL);
// Creates an asynchronous subscription on subject "foo".
// When a message is sent on subject "foo", the callback
// onMsg() will be invoked by the client library.
// You can pass a closure as the last argument.
s = natsConnection_Subscribe(&sub, conn, "foo", onMsg, NULL);
// Destroy objects that were created
natsSubscription_Destroy(sub);
natsConnection_Destroy(conn);