nats-io / nats-server

High-Performance server for NATS.io, the cloud and edge native messaging system.
https://nats.io
Apache License 2.0
15.27k stars 1.37k forks source link

Wildcards do not work in RePublish #3977

Closed kakserpom closed 1 year ago

kakserpom commented 1 year ago

Defect

Versions of nats-server and affected client libraries used:

Version: 2.9.15 Git: [b91fa85]

Steps or code to reproduce the issue:

await jsm.streams.add({
    name: 'first-stream',
    subjects: [
        'first-stream',
    ],
});
await jsm.streams.delete('second-stream')
await jsm.streams.add({
    name: 'second-stream',
    subjects: [
        'second-stream.*',
    ],
    republish: {
        src: '>',
        dest: 'first-stream',
    },
})

Expected result:

No error

Actual result:

  api_error: {
    code: 500,
    err_code: 10052,
    description: 'stream configuration for republish not valid'
  }

I tried all variants: no src, src: 'second-stream.>', etc. Nothing works.

And yet https://docs.nats.io/nats-concepts/jetstream/streams#republish says:

Source - An optional subject pattern which is a subset of the subjects bound to the stream. It defaults to all messages in the stream, e.g. >.

Jarema commented 1 year ago

If you want to use > wildcard in any subject mapping, you cannot drop the > from dest.

await jsm.streams.add({
    name: 'first-stream',
    subjects: [
        'first-stream',
    ],
});
await jsm.streams.delete('second-stream')
await jsm.streams.add({
    name: 'second-stream',
    subjects: [
        'second-stream.*',
    ],
    republish: {
        src: '>',
-        dest: 'first-stream',
+        dest: 'first-stream.>',
    },
})

it’s much easier to work with mappings by first trying them out in NATS cli:

nats server mapping ">" "dest.>"