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