I have a code like that:
package main
import (
"fmt"
"github.com/nats-io/nats.go"
)
func main() {
nc, _ := nats.Connect(nats.DefaultURL)
for {
nc.Subscribe("request", func(m *nats.Msg) {
fmt.Printf("Received a message: %s\n", string(m.Data))
m.Respond([]byte("Received"))
})
}
}
What I try to do is receive a message and after receiving a message send a reply to message, forever as shown in the example.
However with the code above, there are some problems. When I added for {
to the code, it repeats the same message until a new message is received.
What is the correct implementation to receive messages continuously with NATS? (Without replying received messages)