ack messages
This commit is contained in:
@@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@@ -75,11 +74,12 @@ func startMutationConsumer(ctx context.Context, conn *amqp.Connection, hub *Hub)
|
|||||||
return
|
return
|
||||||
case m, ok := <-msgs:
|
case m, ok := <-msgs:
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Print("no message, would have closed")
|
log.Fatalf("connection closed")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Log and broadcast to all websocket clients
|
// Log and broadcast to all websocket clients
|
||||||
log.Printf("mutation event: %s", string(m.Body))
|
log.Printf("mutation event: %s", string(m.Body))
|
||||||
|
|
||||||
if hub != nil {
|
if hub != nil {
|
||||||
select {
|
select {
|
||||||
case hub.broadcast <- m.Body:
|
case hub.broadcast <- m.Body:
|
||||||
@@ -87,6 +87,9 @@ func startMutationConsumer(ctx context.Context, conn *amqp.Connection, hub *Hub)
|
|||||||
// if hub queue is full, drop to avoid blocking
|
// if hub queue is full, drop to avoid blocking
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err := m.Ack(false); err != nil {
|
||||||
|
log.Printf("error acknowledging message: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@@ -152,7 +155,7 @@ func main() {
|
|||||||
if amqpURL != "" {
|
if amqpURL != "" {
|
||||||
conn, err := amqp.Dial(amqpURL)
|
conn, err := amqp.Dial(amqpURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Errorf("failed to connect to RabbitMQ: %w", err)
|
log.Fatalf("failed to connect to RabbitMQ: %w", err)
|
||||||
}
|
}
|
||||||
if err := startMutationConsumer(ctx, conn, hub); err != nil {
|
if err := startMutationConsumer(ctx, conn, hub); err != nil {
|
||||||
log.Printf("AMQP listener disabled: %v", err)
|
log.Printf("AMQP listener disabled: %v", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user