ms-tester/internal/problems/delivery/rabbitmq/sub.go

58 lines
943 B
Go
Raw Normal View History

2024-11-01 18:22:43 +00:00
package rabbitmq
import (
"fmt"
"git.sch9.ru/new_gate/ms-tester/internal/problems"
"github.com/golang/protobuf/proto"
amqp "github.com/rabbitmq/amqp091-go"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
)
func NewNotificationSubscriber(ch *amqp.Channel, queueName string, instanceName string, problemUC problems.ProblemUseCase) {
_, err := ch.QueueDeclare(
queueName,
true,
false,
false,
false,
nil,
)
if err != nil {
panic(err)
}
msgs, err := ch.Consume(
queueName,
instanceName,
false,
false,
false,
false,
nil,
)
if err != nil {
panic(err) // FIXME
}
go func() {
for d := range msgs {
err = d.Ack(false)
if err != nil {
panic(err) // FIXME
}
msg := filer_pb.EventNotification{}
err = proto.Unmarshal(d.Body, &msg)
if err != nil {
panic(err) // FIXME
}
fmt.Println(msg.String()) // TODO: instead, call appropriate problemUC handler
}
}()
return
}