NATS msg publish failing while using js_PublishMsgAsync function of nats c lib

53 views
Skip to first unread message

Aashish

unread,
Nov 13, 2024, 11:52:34 AM11/13/24
to nats
Hello,

I am using the NATS C library to publish and receive messages over NATS. I have a callback function attached to a DDS Reader, and whenever it receives any message over DDS, it forwards the same message over NATS using the js_PublishMsgAsync function. However, it returns error code 26, which is NATS_TIMEOUT.

Another function, which is registered as a callback for NATS messages, is able to publish messages using the same API. But at the same time, the same API (js_PublishMsgAsync) is failing when called from the callback function attached to the DDS Reader.

Does anyone know what might be the issue here?

Thanks in advance for the answers.

If you need any more help or further clarification, feel free to ask!

Lev Brouk

unread,
Nov 13, 2024, 2:02:59 PM11/13/24
to nats
Would you be able to provide a code snippet that fails?

Lev Brouk

unread,
Nov 13, 2024, 2:03:03 PM11/13/24
to nats
Would it be possible to post a code snippet, please?

On Wednesday, November 13, 2024 at 8:52:34 AM UTC-8 Aashish wrote:

Aashish

unread,
Nov 14, 2024, 10:35:43 AM11/14/24
to nats
Hello,

Can not share actual code. But below is kind of similar code description. 

NATSHelper::NATSHelper()
{
//NATS connection and initialization code
//NATSHelper::DDSReaderHandler function is registered as callback for DDS topic

}

void NATSHelper::nats_msg_handler(...)
{
//This is function which is subscribed to NATS subject XYZ_request
//Messages are properly received here

//Then acknowledgement is published to NATS subject XYZ_response using
js_PublishMsgAsync(...)
//This succeeds without any error
}

void NATSHelper::DDSReaderHandler(..)
{
//DDS message(protobuf msg) received here over DDS
//same message is serialized to byteArray using SerializeToString function
//Then published to NATS subject XYZ_response using
js_PublishMsgAsync(...)
//Here,This function returns error code 26 which is NATS_TIMEOUT
//meanwhile in function NATSHelper::nats_msg_handler, its stll properly receiving messages and successfully publishing over NATS

//One observation, if retry logic is applied here then js_PublishMsgAsync succeeds after 12 to 15 retry attempt.
}

Aashish

unread,
Nov 14, 2024, 10:35:48 AM11/14/24
to nats
Hello,

I can't share actual code but below is almost similar code description-

NATSHelper::NATSHelper()
{
//NATS connection and initialization code
//NATSHelper::DDSreaderHandler function is registered as callback for some DDS topic


}

void NATSHelper::nats_msg_handler(...)
{
//This is function which is subscribed to NATS subject XYZ_request
//Messages are properly received here

//Then acknowledgement is published to NATS subject XYZ_response using
js_PublishMsgAsync(...)
//This succeeds without any error
}

void NATSHelper::DDSreaderHandler(..)

{
//DDS message(protobuf msg) received here over DDS
//same message is serialized to byteArray using SerializeToString function
//Then published to NATS subject XYZ_response using
js_PublishMsgAsync(...)
//here, This function returns error code 26 which is NATS_TIMEOUT
//meanwhile in function NATSHelper::nats_msg_handler, its still properly receiving messages and successfully publishing over NATS

//One observation, if retry logic is applied here then it succeeds after 12 to 15 retry attempt.
}



On Thursday 14 November 2024 at 00:33:03 UTC+5:30 l...@synadia.com wrote:

Aashish

unread,
Nov 18, 2024, 10:24:20 AM11/18/24
to nats
Does anyone know what might be the issue here?

Reply all
Reply to author
Forward
0 new messages