I have created two streams on my nats-server, using nats cli. Then using nats-io/nats.c library, I created two consumers for each of the streams. now I am trying to subscribe to the topics in each of the stream, I am able to successfully subscribe to only first topic but unable to subscribe to second one, as its providing me the error: consumer is already bound to a subscription. for first topic subscription option I am using consumer1 and for second topic I am using consumer2.
Things I did
natsStatus status;
jsSubOptions jsSuOpts;
status = jsSubOptions_Init(&jsSuOpts);
if (streamName == "stream1")
{
status = CreateandUpdateConsumer("Consumer1", streamName, topicname);
jsSuOpts.Stream = streamName.c_str();
jsSuOpts.Consumer = "filemodule";
if (status == NATS_OK)
{
// this calls the js_Subscribe()
subscribe_internal(topicname, &jsSuOpts, subcloud);
/*can put consumer configuration if required*/
}
}
else if (streamName == "stream2")
{
status = CreateandUpdateConsumer("Consumer2", streamName, topicname);
jsSuOpts.Stream = streamName.c_str();
jsSuOpts.Consumer = "filemodule_apps";
// temp = subslbapps;
if (status == NATS_OK)
{
subscribe_internal(topicname, &jsSuOpts, subslbapps);
/*can put consumer configuration if required*/
}
}
Parameters that i kept global/common are :
natsConnection *conn;
natsStatistics *stats;
natsOptions *opts;
natsSubscription *subcloud;
natsSubscription *subslbapps;
natsMsg *msg;
jsCtx *js;
jsOptions jsOpts;
jsPubOptions jsPubOpts;
So wanted to know what i am missing here ?. i am new to nats so need help.
and one strange thing if i am sending data to my topic on which, i am getting error , it receives the data (call back is invoked).