-
Notifications
You must be signed in to change notification settings - Fork 239
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
[FEATURE] Nats Client Protocol idempotency id (or sid) needed for all client commands instead of only PUB/HPUB #498
Comments
(above quote is not actual, sorry me, server didn't sent all pending messages, only new ones after receiving connect, possible PHP restores connection when i WRITE something to socket, guess is not nats problem) |
Guess i dont count parallel features. To escape responses from different request it should be different opened connections... So if we open new connection for each Guess each SUB message should open new connection, allowing engineer to create connection pool, that we check in a cycle with timeout. Same thing should be for PUB message with reply-to provided... There could be PUB with Actually Also adding handlers for just 'MSG' forces to run N handlers for each incoming message. Instead it should be some filter for message fields to run only 2-3 callbacks required for certain task. Well, if handlers started only by One thing i hate in pool - highload. So many connections from single machine even with "parallel" could unexpectedly exhaust max_connection_limit or something. And what would we say if we start to talk about cluster... Connection count exponentially increased. It will be harder than i expect. |
Tried async and sync, and just unable to solve case. If confirmation/response doesn't have pointer to what exactly it covers - unable to work with these confirmations. Ping should be confirmed with pong. We use socket, so when reading we could receive few pongs (in case of long time wait) - we again dont know what pong to what ping to be sure that it works. |
fyi there is already an actively maintained NATS PHP client: https://github.com/basis-company/nats.php with JetStream, KV etc. |
Thats why i rewrite it. There's not junior code, but not senior code, OOP cries, looping too, unable to async processing, am trying to explore. Fully synchronyous blocking client with wall of code, but actually - few features is working. I tried to cooperate with - they mark task as "somewhen" and leave. |
I write PHP library to wrap nats.
I've just detected one thing that can't be resolved in that protocol (maybe i just dont know how to do that)
In short:
Explanations:
pingInterval
to 5 in /etc/nats/nats-server.confSockets is duplex. I can read from there and write there.
After sending any message i have two possible ways:
If am in (1), i usually receive answer for my command making duplex SYNC. But if we talk about (for example) VERBOSE mode - any command should send the response. Also we should remember that INCOMING message could become to socket between the answers of certain command. So even if i read SYNC the duplex - i could have unexpected remote message.
It forces me to create function like
processUntil('+OK')
. This command gets many of messages, run associated handlers until it gets for VERBOSE mode "+OK" answer. But what if there are two commands sent? I should expect TWO +OK messages and also i could get few unexpected PING, -ERR or MSG/HMSG messages between.If i ignore that situation (wont create processUntil) i could receive
-ERR
between answers, for example 'Stale Connection', and continue to handle messages after but i shouldn't handle that behavior (cus of not client but server problem)As a temporarily solution - i will wrap it into "sentCommands/expectedAnswers" stack to solve, but it should be controlled via idempotence i guess. Like your PUB/HPUB defines
sid
to make subscribtion unique.Also would be great to provide CONNECT argument "separator" to overwrite "\r\n" cus of body of message can have same separators and it would be easier to control separator letters. I solve it exploding incoming strings by "\r\n" and each step i try to resolve one of known commands. But actually it could be simplier.
Thanks.
The text was updated successfully, but these errors were encountered: