nats: no response from stream

7.2k Views Asked by At

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.

2

There are 2 best solutions below

2
On BEST ANSWER

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

2
On

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