Closed injaelee closed 8 years ago
@injaelee Thanks for your interest in NATS Streaming!
I believe the issue is that you are not using the file based store (default is memory only), so no state is persisted when you restart the server. When the server restarts, it gets new subject prefixes and this is why your publisher is able to reconnect to NATS Server, but sent messages go nowhere so to speak, and so the publisher times-out. To run with a file based store:
nats-streaming-server -store file -dir datastore
Here, datastore
is any directory where the server is going to persist the state.
Hope this helps!
@kozlovic I have a question regarding this behavior as I was thinking of a possible workaround without using the file mode.
The approach that I experimented with was to create a nats.Conn in advance with a custom ReconnectHandler and pass it to stan.Connect to create a stan.Conn. In this way, the reconnect handler can recreate a stan.Conn (i.e., closing the old one and creating a new one using stan.Connect) when it is invoked.
This approach works fine but I see a few issues.
I would appreciate if you could comment on this approach.
regards, aki
@elakito Unfortunately, several things make this approach not ideal:
More importantly, if you run the streaming server in memory-only mode, as I said, no state is preserved. From an application perspective, this may not mean much to stay running anyway. The memory-only mode value is essentially for client or network failures.
@kozlovic Thanks. I think point 1 is probably not complicated to handle but point 2 seems to be a real problem.
In that case, one last question, what is the reason for prefixing those subjects? The reason for asking is whether dropping the prefixes might be an option when using the memory mode.
regards, aki
Make them unique so that if you had multiple Streaming servers on the same network, communication between a client and its server would be "private".
@kozlovic I experimented with several approaches. For the pure in-memory approach using a static prefix, I needed to add a heuristic workaround to automatically re-register the old publisher client when it publishes first time after a broker restart. With that change, the publishing part worked fine but the subscription part didn't work because I can't automatically reactivate the old subscriptions.
So, to solve this problem, I tried another approach that persists the server, client, and subscription information. With this approach, the publishing part worked fine but the subscription part worked partially because the old subscriber may be waiting for a sequence n, but the newly restarted broker may be at sequence 1. In other words, the old subscribers will miss n messages after a restart. In order to avoid this situation, I needed to persist the last sequence number so this information can be recovered after a restart.
I will investigate a little more about this approach and write to the mailing list.
Thank you for your help.
I posted a message to https://groups.google.com/forum/#!topic/natsio/V4tvf8FVJ54
When the stream server is restarted, the client calls the reconnect callback but times out in publishing the message.
I've briefly gone through the open/closed issues with the keyword "reconnect". But I haven't seen anything related to the issue at hand. I am wondering whether I am missing something. I would appreciate your help.
Here is how to reproduce the problem.
Here is my client code. [ Link: https://gist.github.com/injaelee/694bef09413f4e8829b63f589a64548d ]
Here is how I run the server.
Here are the log messages from the server including the event of CTRL-C and the re-start.
Here is the output from the client code.