mahdi gadget
mahdi gadget

Reputation: 113

nats: no response from stream

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.

Upvotes: 5

Views: 10087

Answers (4)

nilsmagnus
nilsmagnus

Reputation: 2322

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.

Upvotes: 0

joni jones
joni jones

Reputation: 2995

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.*.*.*"},
})

Upvotes: 0

Tu Phung
Tu Phung

Reputation: 31

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)
    }
}

Upvotes: 2

Shubham Dixit
Shubham Dixit

Reputation: 1

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

Upvotes: 5

Related Questions