Closed StarpTech closed 7 years ago
The issue is not related to having the nats library (with the exception that any code you add may contribute to exposing it).
What we know: the on message is getting processed before the subscription is ready. There's a 'ready' notification for the subscription, which you can use to trigger the subscription registration.
If you process.nextTick() the handling of the connect and ready, the issue will be hard to reproduce, but it will still happen.
We need to figure out why this is happening. As the response to the subscription should be getting back before a message is sent.
Hi @aricart so there exist no workaround right? Will you investigate in the near future? Thanks.
Yes there's a small workaround - let me re-write your example real quick so that it is clear to you.
@StarpTech you can try https://github.com/nats-io/node-nats-streaming/tree/defer-subs-until-protocol. This solves the issue as far as I can tell. I will pow-wow with Ivan to further dig into why I get a message before the protocol subscription response is sent. You can use the branch until we push it to unblock you.
@aricart thanks!
The PR will get you going until we determine how/if the server needs to be fixed.
@StarpTech - the issue with the server was fixed (you need to get the build referencing the fix from @kozlovic). So the existing library you got from npm
should work. Let me know if you spot anything else!
I will try it asap thanks!
When I remove the first line it works.
Error: