Compare commits
2 Commits
cc6d48c879
...
5223fef2fa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5223fef2fa | ||
|
|
7161c2a8b6 |
@@ -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,
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user