EasyCVR is a high stability and high access video platform developed by TSINGSEE Qingxi Video, which has rich access protocols and can be cascaded through national standard protocols. When the modules of EasyCVR communicate messages, a message middleware is needed to transmit and send messages. After investigating various MQ middleware, it was decided to use NSQ for compilation.

When EasyCVR uses NSQ, it is expected to delay 60 seconds before the consumer can receive the corresponding message. Therefore, we mainly investigate the process of this function in this paper. We mainly use the DeferredPublish method to implement this function, and the method code is as follows:

package main import ( "fmt" "github.com/nsqio/go-nsq" "log" "time" "zhangqiadams.com/gotools/model/consts" ) func main()  { config := nsq.NewConfig() // 1. Producer, err := nsq.NewProducer("127.0.0.1:4154", config) if err! = nil { log.Fatal(err) } messageBody := []byte("hello world delay") topicName := "topic2" // 2. Synchronously push stream to NSPD. Synchronously push stream means wait for response from NSPD and return error if sending fails. // PublishAsync represents asynchronous push messages to NSPD, Err = producer.deferredPublish (topicName, 60*time.Second, messageBody) FMT.Println( time.Now().Format(consts.TimeFormat)) if err ! = nil { log.Fatal(err) } /*sigChan := make(chan os.Signal, 1) signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) <-sigChan*/ // 3. Stop producer.stop ()} Stop producer.stop ()}Copy the code

A message was sent at 14:06:45.

The consumer received the message 60 seconds later and received the corresponding message at 14:07:46.

After code confirmation, delayed message sending is realized in NSQD, and delayed stream pushing function has been realized.