nats: no response from stream
Asked Answered
P

4

5

have error with nats-server -js when i want publish msg with golang in nats-server -js, i have error like this: nats: no response from stream i want publish video to nats-server -js this is my pub file:

    nc, _ := nats.Connect(nats.DefaultURL)

js, _ := nc.JetStream()

webcam, _ := gocv.VideoCaptureDevice(0)
img := gocv.NewMat()
defer img.Close()
for {
    webcam.Read(&img)
    _, err := js.Publish("ORDERS", img.ToBytes())
    if err != nil {
        fmt.Println(err)
    }
}

How can I fix this problem? Thanks in advance for your replys.

Potluck answered 8/5, 2021 at 23:5 Comment(1)
What was the solution. I get the same error.Vd
D
5

The problem with your code is ,that you forgot to Add a stream .Your nats server is connectable at 4222 (default).But you have to Add a stream to publish and get the data, here is the code in go

_, err = js.AddStream(&nats.StreamConfig{
        Name:     "orders",
        Subjects: []string{"ORDERS.*"},
    })

See documentation for more

Donald answered 22/3, 2022 at 11:22 Comment(2)
Does the case matter? "order" vs. "ORDER"?Nystrom
documentation link has changed to: github.com/nats-io/nats.go#basic-usage-1Nystrom
J
2

I think you need specify child subject in publish function (ORDERS.*) Example: ORDERS.category, ORDERS.abc,.... (NOT: ORDERS)

This is my example with NATS STREAMING JS Pub/Sub Message:

enter image description here

package main

import (
    "fmt"
    "github.com/test/global"
    "github.com/nats-io/nats.go"
)

func main() {
    nc, err := nats.Connect(global.GetURL())
    if err != nil {
        fmt.Println(err)
    }
    js, err := nc.JetStream()
    if err != nil {
        fmt.Println(err)
    }
    _, err = js.Publish("ORDERS.abc", []byte("abc"))
    if err != nil {
        fmt.Println(err)
    }
}
Jacobean answered 10/5, 2021 at 3:13 Comment(2)
Hi Tu, can you fix the image link description?Sverre
Please see image link description in link: drive.google.com/file/d/1oISklRGtMrca8Uw61lVvcIPnhdjyY8v6/…Jacobean
H
0

If you have a multi-hierarchy for NATS topics like orders.a.b.c and not just orders.abc it's important that you specify the proper * wildcard pattern according to your topics hierarchy or use > for multi-token matching https://docs.nats.io/nats-concepts/subjects#matching-multiple-tokens.

For the hierarchy of orders.a.b.c the example would be something like this:

s, err := js.CreateStream(ctx, jetstream.StreamConfig{
    Name:    "ORDERS",
    Subjects: []string{"orders.>"},
})

or

s, err := js.CreateStream(ctx, jetstream.StreamConfig{
    Name:    "ORDERS",
    Subjects: []string{"orders.*.*.*"},
})
Hewlett answered 26/4 at 17:15 Comment(0)
I
0

In my case I got this message when i published messages to the strem. I found that I had a wrong pattern for the subjects:

s, err := js.CreateStream(ctx, jetstream.StreamConfig{
    Name:    "ORDERS",
    Subjects: []string{"orders.*"},
})

While publishing on a different pattern:

_, err := js.Publish("ORDERS.123.abc", img.ToBytes())

Changing the pattern to orders.*.* fixed it:

s, err := js.CreateStream(ctx, jetstream.StreamConfig{
    Name:    "ORDERS",
    Subjects: []string{"orders.*.*"},
})

The error-message is not very helpful by the way, and from I can understand, happens in different situations.

Irons answered 20/10 at 18:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.