reconnect timer + fixes
This commit is contained in:
parent
13ee3230e3
commit
42646a6a08
3 changed files with 71 additions and 21 deletions
20
publisher.go
20
publisher.go
|
|
@ -2,18 +2,34 @@ package rabbit
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Publisher interface {
|
||||
Push(data []byte) error
|
||||
Start(chanLen uint) <-chan []byte
|
||||
}
|
||||
|
||||
type pubHandler struct {
|
||||
client *Client
|
||||
}
|
||||
|
||||
func (p *pubHandler) Push(data []byte) error {
|
||||
func (p *pubHandler) Start(chanLen uint) <-chan []byte {
|
||||
ch := make(chan []byte, chanLen)
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case msg := <-ch:
|
||||
if err := p.push(msg); err != nil {
|
||||
log.Printf("Error publishing message: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
return ch
|
||||
}
|
||||
|
||||
func (p *pubHandler) push(data []byte) error {
|
||||
p.client.mutex.Lock()
|
||||
if !p.client.isReady {
|
||||
p.client.mutex.Unlock()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue