Answer the question
In order to leave comments, you need to log in
Go why (it closes by itself) ampq channel closes?
1) There is a queue with one message (for the test)
2) Again, for the test, the message is always returned to the queue
Code examplemsg.Nack(false, true)
func addSmsSender(ampq <-chan amqp.Delivery, status *string) {
var me MyStruct
for true {
if *status != "Connected" {
fmt.Printf("Alarm connect\r\n")
fmt.Print(*status)
time.Sleep(Constants.VirginTimeout * time.Millisecond)
continue
}
msg, ok := <-ampq
//если канал закрыт, то ложимся спать
if !ok {
fmt.Print("Я сплю\r\n")
json.Unmarshal([]byte(msg.Body), &me)
fmt.Printf("%+v\n",&me)
time.Sleep(Constants.VirginTimeout * time.Millisecond)
continue
}
fmt.Print("Read\r\n")
err := json.Unmarshal([]byte(msg.Body), &me )
if err != nil {
//здесь обработка ошибок распаковки джсона
fmt.Printf("JSON UNMARSHAL ERR")
//ок говорим что ошибка в JSON и выкидываем обратно в очередь, мб повезет в след раз заработает
msg.Nack(false, true)
continue
}
.......
msg.Nack(false, true)
go func() {
fmt.Printf("closing: %s", <-w.conn.NotifyClose(make(chan *amqp.Error)))
}()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question