2024-09-10 17:26:46 +08:00
|
|
|
package rabbitmq_amqp
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"crypto/tls"
|
2024-11-15 15:37:28 +08:00
|
|
|
"fmt"
|
2024-09-10 17:26:46 +08:00
|
|
|
)
|
|
|
|
|
|
2024-09-11 20:42:05 +08:00
|
|
|
type TSaslMechanism string
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
Plain TSaslMechanism = "plain"
|
|
|
|
|
External TSaslMechanism = "external"
|
|
|
|
|
Anonymous TSaslMechanism = "anonymous"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type SaslMechanism struct {
|
|
|
|
|
Type TSaslMechanism
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-15 15:37:28 +08:00
|
|
|
type ConnectionSettings struct {
|
|
|
|
|
Host string
|
|
|
|
|
Port int
|
|
|
|
|
User string
|
|
|
|
|
Password string
|
|
|
|
|
VirtualHost string
|
|
|
|
|
Scheme string
|
|
|
|
|
ContainerId string
|
|
|
|
|
UseSsl bool
|
|
|
|
|
TlsConfig *tls.Config
|
|
|
|
|
SaslMechanism TSaslMechanism
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *ConnectionSettings) BuildAddress() string {
|
|
|
|
|
return c.Scheme + "://" + c.Host + ":" + fmt.Sprint(c.Port)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewConnectionSettings creates a new ConnectionSettings struct with default values.
|
|
|
|
|
func NewConnectionSettings() *ConnectionSettings {
|
|
|
|
|
return &ConnectionSettings{
|
|
|
|
|
Host: "localhost",
|
|
|
|
|
Port: 5672,
|
|
|
|
|
User: "guest",
|
|
|
|
|
Password: "guest",
|
|
|
|
|
VirtualHost: "/",
|
|
|
|
|
Scheme: "amqp",
|
|
|
|
|
ContainerId: "amqp-go-client",
|
|
|
|
|
UseSsl: false,
|
|
|
|
|
TlsConfig: nil,
|
|
|
|
|
}
|
2024-09-10 17:26:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type IConnection interface {
|
2024-11-15 15:37:28 +08:00
|
|
|
// Open opens a connection to the AMQP 1.0 server.
|
|
|
|
|
Open(ctx context.Context, connectionSettings *ConnectionSettings) error
|
|
|
|
|
|
|
|
|
|
// Close closes the connection to the AMQP 1.0 server.
|
2024-09-10 17:26:46 +08:00
|
|
|
Close(ctx context.Context) error
|
2024-11-15 15:37:28 +08:00
|
|
|
|
|
|
|
|
// Management returns the management interface for the connection.
|
2024-09-10 17:26:46 +08:00
|
|
|
Management() IManagement
|
2024-11-15 15:37:28 +08:00
|
|
|
|
|
|
|
|
// NotifyStatusChange registers a channel to receive status change notifications.
|
|
|
|
|
// The channel will receive a StatusChanged struct whenever the status of the connection changes.
|
2024-09-10 17:26:46 +08:00
|
|
|
NotifyStatusChange(channel chan *StatusChanged)
|
2024-11-15 15:37:28 +08:00
|
|
|
// Status returns the current status of the connection.
|
|
|
|
|
// See LifeCycle struct for more information.
|
|
|
|
|
Status() int
|
2024-09-10 17:26:46 +08:00
|
|
|
}
|