Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nats module subscriber issue when connected to more "nats_urls" #2916

Closed
smititelu opened this issue Nov 4, 2021 · 2 comments
Closed

nats module subscriber issue when connected to more "nats_urls" #2916

smititelu opened this issue Nov 4, 2021 · 2 comments

Comments

@smititelu
Copy link
Contributor

Description, Troubleshooting, Reproduction

I have 3 go nats servers running and the following kamailio config for nats:

modparam("nats", "nats_url", "nats://127.0.0.1:4222")
modparam("nats", "nats_url", "nats://127.0.0.2:4222")
modparam("nats", "nats_url", "nats://127.0.0.3:4222")

modparam("nats", "subject_queue_group", "foo:2020")
...

event_route[nats:foo]
{
                xlog("L_ERR", "==============> received $natsData");
}

I try to publish using some nats publisher (e.g. nats.c example/libuv-pub.c), and nothing gets printed in event route:

./pub -s nats://127.0.0.1:4222 -txt "aaaaaaaaaaaa" -count 1 // event route log NOT printed
./pub -s nats://127.0.0.2:4222 -txt "aaaaaaaaaaaa" -count 1 // event route log NOT printed

However, if I try to publish on the last server "127.0.0.3", log is printed:

./pub -s nats://127.0.0.3:4222 -txt "aaaaaaaaaaaa" -count 1 // event route log IS printed

I expected to see 1 log message for each of the above publish(es). Found this while implementing and testing #2915

Thanks,
Stefan

@smititelu
Copy link
Contributor Author

smititelu commented Nov 5, 2021

Found in nats.h file, from nats.c git repo:

 * By default, #natsConnection_Connect() attempts to connect to a server
 * specified in provided list of servers. If it cannot connect and the list has been
 * fully tried, the function returns an error.

So the lib behavior is to connect to a single server from the list, not to all servers in the list. Right now, the subscriber part of kamailio nats module creates a single connection with the list of servers from "nats_url" modparams.

To be decided later if a single connection per "nats_url" is needed for subscriber part of kamailio nats module.

Closing this, as it is expected lib behavior. Will document this in "nats_url" modparam.

Thanks,
Stefan

@eschmidbauer
Copy link
Contributor

This sounds like a nice improvement, I submitted a PR to move the connection handling into a new struct. We can extend it into a linked-list by doing something like this:
image

I think we should leave the default behavior of relying on libnats to do connection failover based on the server list it is given, and define a "name" on the connection to create simultaneous connections.
perhaps using something similar to htable like

modparam("nats", "nats_url", "nats://127.0.0.1:4222;name=connection1")
modparam("nats", "nats_url", "nats://127.0.0.1:5222;name=connection1")
modparam("nats", "nats_url", "nats://127.0.0.1:6222;name=connection2")

This would create two sets of connections.
"connection1" would contain server list of nats://127.0.0.1:4222 and nats://127.0.0.1:5222
"connection2" would contain server list of nats://127.0.0.1:6222
We could then reference the connections by name in other modparams or functions.

smititelu added a commit to smititelu/kamailio that referenced this issue Dec 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants