update
Some checks failed
Build and Publish / BuildAndDeploy (push) Failing after 3m41s
Build and Publish / BuildAndDeployAmd64 (push) Has been cancelled

This commit is contained in:
matst80
2025-04-18 18:00:40 +02:00
parent b63415bc2c
commit 4cc1851626
5 changed files with 108 additions and 4 deletions

83
amqp-order-handler.go Normal file
View File

@@ -0,0 +1,83 @@
package main
import (
"log"
amqp "github.com/rabbitmq/amqp091-go"
)
type RabbitTransportMaster struct {
Url string
connection *amqp.Connection
//channel *amqp.Channel
}
const (
topic = "order-placed"
)
func (t *RabbitTransportMaster) Connect() error {
conn, err := amqp.DialConfig(t.Url, amqp.Config{
//Vhost: "/",
Properties: amqp.NewConnectionProperties(),
})
if err != nil {
return err
}
t.connection = conn
ch, err := conn.Channel()
if err != nil {
return err
}
defer ch.Close()
if err := ch.ExchangeDeclare(
topic, // name
"topic", // type
true, // durable
false, // auto-delete
false, // internal
false, // noWait
nil, // arguments
); err != nil {
return err
}
if _, err = ch.QueueDeclare(
topic, // name of the queue
true, // durable
false, // delete when unused
false, // exclusive
false, // noWait
nil, // arguments
); err != nil {
return err
}
return nil
}
func (t *RabbitTransportMaster) Close() error {
log.Println("Closing master channel")
return t.connection.Close()
//return t.channel.Close()
}
func (t *RabbitTransportMaster) OrderCompleted(data []byte) error {
ch, err := t.connection.Channel()
if err != nil {
return err
}
defer ch.Close()
return ch.Publish(
topic,
topic,
true,
false,
amqp.Publishing{
ContentType: "application/json",
Body: data,
},
)
}