2 Commits

Author SHA1 Message Date
matst80
5223fef2fa Update amqp-order-handler.go
All checks were successful
Build and Publish / Metadata (push) Successful in 10s
Build and Publish / BuildAndDeployAmd64 (push) Successful in 53s
Build and Publish / BuildAndDeployArm64 (push) Successful in 5m0s
2025-11-11 16:44:41 +01:00
matst80
7161c2a8b6 Update amqp-order-handler.go 2025-11-11 16:00:59 +01:00

View File

@@ -9,7 +9,8 @@ import (
)
type AmqpOrderHandler struct {
conn *amqp.Connection
conn *amqp.Connection
queue *amqp.Queue
}
func NewAmqpOrderHandler(conn *amqp.Connection) *AmqpOrderHandler {
@@ -25,19 +26,18 @@ func (h *AmqpOrderHandler) DefineTopics() error {
}
defer ch.Close()
err = ch.ExchangeDeclare(
queue, err := ch.QueueDeclare(
"orders", // name
"direct", // type
true, // durable
false, // auto-deleted
false, // internal
false, // no-wait
nil, // arguments
false,
false,
false,
false,
nil,
)
if err != nil {
return fmt.Errorf("failed to declare an exchange: %w", err)
}
h.queue = &queue
return nil
}
@@ -51,13 +51,14 @@ func (h *AmqpOrderHandler) OrderCompleted(body []byte) error {
defer cancel()
return ch.PublishWithContext(ctx,
"orders", // exchange
"new", // routing key
"", // exchange
"orders", // routing key
false, // mandatory
false, // immediate
amqp.Publishing{
ContentType: "application/json",
Body: body,
DeliveryMode: amqp.Persistent,
ContentType: "application/json",
Body: body,
})
}