Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(video): VideoSummary consumer 添加延迟重试和失败重传次数 #118

Merged
merged 2 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions src/services/publish/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,17 @@ func (a PublishServiceImpl) New() {
channel, err = conn.Channel()
exitOnError(err)

exchangeArgs := amqp.Table{
"x-delayed-type": "topic",
}
err = channel.ExchangeDeclare(
strings.VideoExchange,
"fanout",
"x-delayed-message", //"topic",
true,
false,
false,
false,
nil,
exchangeArgs,
)
exitOnError(err)

Expand All @@ -83,7 +86,7 @@ func (a PublishServiceImpl) New() {

err = channel.QueueBind(
strings.VideoPicker,
"",
strings.VideoPicker,
strings.VideoExchange,
false,
nil,
Expand All @@ -92,7 +95,7 @@ func (a PublishServiceImpl) New() {

err = channel.QueueBind(
strings.VideoSummary,
"",
strings.VideoSummary,
strings.VideoExchange,
false,
nil,
Expand Down Expand Up @@ -265,20 +268,24 @@ func (a PublishServiceImpl) CreateVideo(ctx context.Context, request *publish.Cr
// Context 注入到 RabbitMQ 中
headers := rabbitmq.InjectAMQPHeaders(ctx)

err = channel.Publish(strings.VideoExchange, "", false, false,
amqp.Publishing{
DeliveryMode: amqp.Persistent,
ContentType: "text/plain",
Body: marshal,
Headers: headers,
})

if err != nil {
resp = &publish.CreateVideoResponse{
StatusCode: strings.VideoServiceInnerErrorCode,
StatusMsg: strings.VideoServiceInnerError,
routingKeys := []string{strings.VideoPicker, strings.VideoSummary}
for _, key := range routingKeys {
// Send raw video to all queues bound the exchange
err = channel.Publish(strings.VideoExchange, key, false, false,
amqp.Publishing{
DeliveryMode: amqp.Persistent,
ContentType: "text/plain",
Body: marshal,
Headers: headers,
})

if err != nil {
resp = &publish.CreateVideoResponse{
StatusCode: strings.VideoServiceInnerErrorCode,
StatusMsg: strings.VideoServiceInnerError,
}
return
}
return
}

resp = &publish.CreateVideoResponse{
Expand Down
19 changes: 14 additions & 5 deletions src/services/videoprocessor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,17 @@ func main() {
exitOnError(err)
}(ch)

exchangeArgs := amqp.Table{
"x-delayed-type": "topic",
}
err = ch.ExchangeDeclare(
strings.VideoExchange,
"fanout",
"x-delayed-message", //"topic",
true,
false,
false,
false,
nil,
exchangeArgs,
)
exitOnError(err)

Expand All @@ -90,7 +93,7 @@ func main() {

err = ch.QueueBind(
strings.VideoPicker,
"",
strings.VideoPicker,
strings.VideoExchange,
false,
nil,
Expand All @@ -99,7 +102,7 @@ func main() {

err = ch.QueueBind(
strings.VideoSummary,
"",
strings.VideoSummary,
strings.VideoExchange,
false,
nil,
Expand Down Expand Up @@ -178,7 +181,13 @@ func Consume(channel *amqp.Channel) {
"err": err,
}).Errorf("Error when updating file information to database")
logging.SetSpanError(span, result.Error)
errorHandler(d, true, logger, &span)
err = d.Nack(false, true)
if err != nil {
logger.WithFields(logrus.Fields{
"err": err,
}).Errorf("Error when resending the video to queue...")
logging.SetSpanError(span, err)
}
span.End()
continue
}
Expand Down
Loading
Loading