package rabbit import ( "context" rmq "github.com/rabbitmq/rabbitmq-amqp-go-client/pkg/rabbitmqamqp" ) type rabbitClient struct { env *rmq.Environment conn *rmq.AmqpConnection } func NewClient(ctx context.Context, tag string) (*rabbitClient, error) { endpoints, err := genEndpoints(tag) if err != nil { return nil, err } cli := new(rabbitClient) cli.env = rmq.NewClusterEnvironment(endpoints) conn, err := cli.env.NewConnection(context.Background()) if err != nil { return nil, err } client.conn = conn return cli, nil } func (c *rabbitClient) Management() *rmq.AmqpManagement { return c.conn.Management() } func (c *rabbitClient) NewPublisher(ctx context.Context, destination rmq.ITargetAddress, options rmq.IConsumerOptions) (*rmq.Publisher, error) { return c.conn.NewPublisher(ctx, destination, options) } func (c *rabbitClient) NewConsumer(ctx context.Context, queueName string, options rmq.IConsumerOptions) (*rmq.Consumer, error) { return c.conn.NewConsumer(ctx, queueName, options) } func (c *rabbitClient) Close(ctx context.Context) error { return c.env.CloseConnections(ctx) }