gonats.ionats-streaming-server

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.


Solution

  • 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