2024-06-10 18:37:04 +00:00
|
|
|
package rmq
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
|
|
|
amqp "github.com/rabbitmq/amqp091-go"
|
|
|
|
)
|
|
|
|
|
|
|
|
type RMQClient struct {
|
|
|
|
cc *amqp.Connection
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewClient creates a new RabbitMQ client. Will panic if there are an error while dealing
|
|
|
|
func NewClient(
|
|
|
|
address string,
|
|
|
|
user string,
|
|
|
|
password string,
|
|
|
|
) *RMQClient {
|
|
|
|
cc, err := amqp.Dial("amqp://" + user + ":" + password + "@localhost:5672/")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("error connect to rabbitmq server", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &RMQClient{
|
|
|
|
cc: cc,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewWithConnection(
|
|
|
|
cc *amqp.Connection,
|
|
|
|
) *RMQClient {
|
|
|
|
return &RMQClient{
|
|
|
|
cc: cc,
|
|
|
|
}
|
|
|
|
}
|
2024-06-20 19:39:31 +00:00
|
|
|
|
|
|
|
func (r *RMQClient) Channel() (*amqp.Channel, error) {
|
|
|
|
return r.cc.Channel()
|
|
|
|
}
|