private methods + push move

This commit is contained in:
nquidox 2026-02-20 16:04:48 +03:00
parent 3f0401de1d
commit 6addcca08d
2 changed files with 4 additions and 31 deletions

View file

@ -2,7 +2,6 @@ package rabbit
import (
"context"
"errors"
amqp "github.com/rabbitmq/amqp091-go"
"time"
)
@ -115,33 +114,7 @@ func (c *Client) changeChannel(channel *amqp.Channel) {
c.Channel.NotifyPublish(c.notifyConfirm)
}
func (c *Client) Push(data []byte) error {
c.mutex.Lock()
if !c.isReady {
c.mutex.Unlock()
return errors.New("failed to push: not connected")
}
c.mutex.Unlock()
for {
err := c.UnsafePush(data)
if err != nil {
c.logger.Println("Push failed. Retrying...")
select {
case <-c.done:
return errShutdown
case <-time.After(c.opts.resendDelay):
}
continue
}
confirm := <-c.notifyConfirm
if confirm.Ack {
c.logger.Printf("Push confirmed [%d]!", confirm.DeliveryTag)
return nil
}
}
}
func (c *Client) UnsafePush(data []byte) error {
func (c *Client) unsafePush(data []byte) error {
c.mutex.Lock()
if !c.isReady {
c.mutex.Unlock()
@ -165,7 +138,7 @@ func (c *Client) UnsafePush(data []byte) error {
)
}
func (c *Client) Consume() (<-chan amqp.Delivery, error) {
func (c *Client) consume() (<-chan amqp.Delivery, error) {
c.mutex.Lock()
if !c.isReady {
c.mutex.Unlock()