// Copyright 2020-2021 The NATS Authors // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include int main(int argc, char **argv) { natsConnection *conn = NULL; natsSubscription *sub = NULL; natsMsg *msg = NULL; natsMsg *rmsg = NULL; natsStatus s; // Creates a connection to the default NATS URL s = natsConnection_ConnectTo(&conn, NATS_DEFAULT_URL); // Create a message if (s == NATS_OK) s = natsMsg_Create(&msg, "foo", NULL, "body", 4); // Create a header by setting a key/value if (s == NATS_OK) s = natsMsgHeader_Set(msg, "My-Key1", "value1"); // Let's set a new key if (s == NATS_OK) s = natsMsgHeader_Set(msg, "My-Key2", "value2"); // Here we add a value to the first key if (s == NATS_OK) s = natsMsgHeader_Add(msg, "My-Key1", "value3"); // Adding yet another key if (s == NATS_OK) s = natsMsgHeader_Set(msg, "My-Key3", "value4"); // Remove a key if (s == NATS_OK) s = natsMsgHeader_Delete(msg, "My-Key3"); // Let's print all the keys that are currently set if (s == NATS_OK) { const char* *keys = NULL; int nkeys = 0; int i; s = natsMsgHeader_Keys(msg, &keys, &nkeys); for (i=0; (s == NATS_OK) && (i