Closed simonhoss closed 1 year ago
Your leafnode should have a different and unique domain set then the hub, try
jetstream {
domain: leaf
}
Thanks for your response. I tried it as you suggested. Here is the startup log:
[52728] 2023/05/11 16:29:03.775260 [INF] Starting nats-server
[52728] 2023/05/11 16:29:03.775409 [INF] Version: 2.9.16
[52728] 2023/05/11 16:29:03.775411 [INF] Git: [f84ca24]
[52728] 2023/05/11 16:29:03.775414 [INF] Cluster: store_a
[52728] 2023/05/11 16:29:03.775415 [INF] Name: store_a
[52728] 2023/05/11 16:29:03.775417 [INF] Node: pbNdm6o3
[52728] 2023/05/11 16:29:03.775418 [INF] ID: NCBZWL3DIXH5JZ67OAXADF6TGXMKWCDSSUOB27L4HBVETRATIWUK2WQ7
[52728] 2023/05/11 16:29:03.775441 [INF] Using configuration file: leaf.conf
[52728] 2023/05/11 16:29:03.777592 [INF] Starting JetStream
[52728] 2023/05/11 16:29:03.778045 [INF] _ ___ _____ ___ _____ ___ ___ _ __ __
[52728] 2023/05/11 16:29:03.778050 [INF] _ | | __|_ _/ __|_ _| _ \ __| /_\ | \/ |
[52728] 2023/05/11 16:29:03.778199 [INF] | || | _| | | \__ \ | | | / _| / _ \| |\/| |
[52728] 2023/05/11 16:29:03.778203 [INF] \__/|___| |_| |___/ |_| |_|_\___/_/ \_\_| |_|
[52728] 2023/05/11 16:29:03.778205 [INF]
[52728] 2023/05/11 16:29:03.778206 [INF] https://docs.nats.io/jetstream
[52728] 2023/05/11 16:29:03.778207 [INF]
[52728] 2023/05/11 16:29:03.778212 [INF] ---------------- JETSTREAM ----------------
[52728] 2023/05/11 16:29:03.778215 [INF] Max Memory: 12.00 GB
[52728] 2023/05/11 16:29:03.778217 [INF] Max Storage: 21.24 GB
[52728] 2023/05/11 16:29:03.778219 [INF] Store Directory: "store_a_server/jetstream"
[52728] 2023/05/11 16:29:03.778220 [INF] Domain: store_a_leaf
As you see I created a domain store_a_leaf
When I push a new message with nats pub orders.store_1.foo order1_03 --context leaf
in a connected state everything works as expected, the msg appears in both nats servers.
When I push it in disconnected state the message gets completely lost.
Could you share the following?
nats stream info
for both accounts on leaf and hub for the streams in question?
Here we go
For the hub:
❯ nats stream info
? Select a Stream orders
Information for Stream orders created 2023-05-11 18:46:45
Subjects: orders.>
Replicas: 1
Storage: File
Options:
Retention: Limits
Acknowledgements: true
Discard Policy: Old
Duplicate Window: 2m0s
Allows Msg Delete: true
Allows Purge: true
Allows Rollups: false
Limits:
Maximum Messages: unlimited
Maximum Per Subject: unlimited
Maximum Bytes: unlimited
Maximum Age: unlimited
Maximum Message Size: unlimited
Maximum Consumers: unlimited
State:
Messages: 1
Bytes: 57 B
FirstSeq: 1 @ 2023-05-11T16:49:41 UTC
LastSeq: 1 @ 2023-05-11T16:49:41 UTC
Active Consumers: 0
Number of Subjects: 1
For the leaf
❯ nats stream info --context leaf
? Select a Stream orders_leaf
Information for Stream orders_leaf created 2023-05-11 18:49:35
Replicas: 1
Storage: File
Options:
Retention: Limits
Acknowledgements: true
Discard Policy: Old
Duplicate Window: 2m0s
Allows Msg Delete: true
Allows Purge: true
Allows Rollups: false
Limits:
Maximum Messages: unlimited
Maximum Per Subject: unlimited
Maximum Bytes: unlimited
Maximum Age: unlimited
Maximum Message Size: unlimited
Maximum Consumers: unlimited
Replication:
Sources: orders, Subject: orders.store_1.foo, API Prefix: $JS.hub.API
Cluster Information:
Name: store_a
Leader: store_a
Source Information:
Stream Name: orders
Lag: 0
Last Seen: 0.89s
Ext. API Prefix: $JS.hub.API
State:
Messages: 1
Bytes: 112 B
FirstSeq: 1 @ 2023-05-11T16:49:41 UTC
LastSeq: 1 @ 2023-05-11T16:49:41 UTC
Active Consumers: 0
Number of Subjects: 1
The source on the leafnode does not listen to the subject on its own and only gets messages when they are present in the hub.
You can add the subject orders.>
to the source but I don't think that is what you are trying to achieve.
Can you explain at a high level what you want accomplish? When messages are published in the hub vs on the leafnode and both situations when the leafnode connection is down?
Gotcha.
What I want to achieve is a scenario where I have a central (hub) and some leafs which are on edge devices. The hub can push infos to the edge device and the edge back to the hub. This works perfectly when the --source
is set and both systems are online. But the problem is I cannot guarantee a stable connection. So both of them should cache the not send messages and as soon as the connection is back, it should send in both directions all the not send message. In any case the messages should be persisted regardless the connection state between the leaf and the hub.
Common pattern.
On leaf have the stream listen to subjects like EVENT.LEAF-1.>
On hub have it listen on EVENT.HUB.>
Then source the leafnode stream from the hub using filter subject EVENT.HUB.>
So it only pulls hub messages.
On HUB have it source leafnode with EVENT.LEAF-1.>
so it only pulls local messages into the HUB.
If you plan to have alot of leafnodes this may start to have scaling issues on the stream hub, but we have worked with customers to architect solutions for that as well.
I also started to think in that way. Is there a possibility that I can then push the messages into a common stream on each node? Maybe with RePublish
?
See picture as example:
You could put RePublish is NATS core, so message loss can happen. Again we have designed systems for customers since these can be complex at large scale.
With the republish I meant a way of collecting the hub main stream and the source streams from the leaf. I want that all messages are again pushed into stream a where I can subscribe and get all messages on the hub including the leafs.
I solved it now by creating another stream on the hub with the sources of the other streams, which again are sourced to the dedicated leafs.
Thanks a lot for your help. I think I can now go forward with this approach!
I accounted for that when I said have the HUB source from all leafs for their filtered subjects.
See above comment.
Defect
Make sure that these boxes are checked before submitting your issue -- thank you!
nats-server -DV
outputVersions of
nats-server
and affected client libraries used:nats-server v.2.9.16 nats-cli 0.0.35
OS/Container environment:
MacOS native executable
Steps or code to reproduce the issue:
Configs:
hub.conf
leaf.conf
I connect a stream on the leaf with the following command
I push a a new message with the following command and the hub is offline
nats pub -s nats://localhost:4111 orders.store_1.foo order1_22
Expected result:
Actual result:
Log of the leaf