Source and Mirror configuration example

Streams with source and mirror configurations are best managed through a client API. If you intend to create such a configuration from command line with NATS CLI you should use a JSON configuration.

  1. nats stream add --config stream_with_sources.json

Example stream configuration with two sources

Minimal example

  1. {
  2. "name": "SOURCE_TARGET",
  3. "subjects": [
  4. "foo1.ext.*",
  5. "foo2.ext.*"
  6. ],
  7. "discard": "old",
  8. "duplicate_window": 120000000000,
  9. "sources": [
  10. {
  11. "name": "SOURCE1_ORIGIN",
  12. },
  13. ],
  14. "deny_delete": false,
  15. "sealed": false,
  16. "max_msg_size": -1,
  17. "allow_rollup_hdrs": false,
  18. "max_bytes": -1,
  19. "storage": "file",
  20. "allow_direct": false,
  21. "max_age": 0,
  22. "max_consumers": -1,
  23. "max_msgs_per_subject": -1,
  24. "num_replicas": 1,
  25. "name": "SOURCE_TARGET",
  26. "deny_purge": false,
  27. "compression": "none",
  28. "max_msgs": -1,
  29. "retention": "limits",
  30. "mirror_direct": false
  31. }

With additional options

  1. {
  2. "name": "SOURCE_TARGET",
  3. "subjects": [
  4. "foo1.ext.*",
  5. "foo2.ext.*"
  6. ],
  7. "discard": "old",
  8. "duplicate_window": 120000000000,
  9. "sources": [
  10. {
  11. "name": "SOURCE1_ORIGIN",
  12. "filter_subject": "foo1.bar",
  13. "opt_start_seq": 42,
  14. "external": {
  15. "deliver": "",
  16. "api": "$JS.domainA.API"
  17. },
  18. },
  19. {
  20. "name": "SOURCE2_ORIGIN",
  21. "filter_subject": "foo2.bar"
  22. }
  23. ],
  24. "consumer_limits": {
  25. },
  26. "deny_delete": false,
  27. "sealed": false,
  28. "max_msg_size": -1,
  29. "allow_rollup_hdrs": false,
  30. "max_bytes": -1,
  31. "storage": "file",
  32. "allow_direct": false,
  33. "max_age": 0,
  34. "max_consumers": -1,
  35. "max_msgs_per_subject": -1,
  36. "num_replicas": 1,
  37. "name": "SOURCE_TARGET",
  38. "deny_purge": false,
  39. "compression": "none",
  40. "max_msgs": -1,
  41. "retention": "limits",
  42. "mirror_direct": false
  43. }

Example stream configuration with mirror

Minimal example

  1. {
  2. "name": "MIRROR_TARGET"
  3. "discard": "old",
  4. "mirror": {
  5. "name": "MIRROR_ORIGIN"
  6. },
  7. "deny_delete": false,
  8. "sealed": false,
  9. "max_msg_size": -1,
  10. "allow_rollup_hdrs": false,
  11. "max_bytes": -1,
  12. "storage": "file",
  13. "allow_direct": false,
  14. "max_age": 0,
  15. "max_consumers": -1,
  16. "max_msgs_per_subject": -1,
  17. "num_replicas": 1,
  18. "name": "MIRROR_TARGET",
  19. "deny_purge": false,
  20. "compression": "none",
  21. "max_msgs": -1,
  22. "retention": "limits",
  23. "mirror_direct": false
  24. }

With additional options

  1. {
  2. "name": "MIRROR_TARGET"
  3. "discard": "old",
  4. "mirror": {
  5. "opt_start_time": "2024-07-11T08:57:20.4441646Z",
  6. "external": {
  7. "deliver": "",
  8. "api": "$JS.domainB.API"
  9. },
  10. "name": "MIRROR_ORIGIN"
  11. },
  12. "consumer_limits": {
  13. },
  14. "deny_delete": false,
  15. "sealed": false,
  16. "max_msg_size": -1,
  17. "allow_rollup_hdrs": false,
  18. "max_bytes": -1,
  19. "storage": "file",
  20. "allow_direct": false,
  21. "max_age": 0,
  22. "max_consumers": -1,
  23. "max_msgs_per_subject": -1,
  24. "num_replicas": 1,
  25. "name": "MIRROR_TARGET",
  26. "deny_purge": false,
  27. "compression": "none",
  28. "max_msgs": -1,
  29. "retention": "limits",
  30. "mirror_direct": false
  31. }