Skip to content

Commit

Permalink
autopaho now provides Router()
Browse files Browse the repository at this point in the history
Previously if you wanted to subscribe and register a handler, then both a ConnectionManager and Router would be needed; this complicates passing the client around (or dependency injection).

ref eclipse-paho#168
  • Loading branch information
MattBrittan authored Nov 19, 2023
2 parents 5f4de1d + 25e8bfd commit c13be08
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions autopaho/auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ type ConnectionManager struct {
connDown chan struct{} // Channel is closed when the connection is down (only valid if cli != nil; must lock Mu to read)
mu sync.Mutex // protects all of the above

cfg ClientConfig // The config passed to NewConnection (stored to enable getters)
cancelCtx context.CancelFunc // Calling this will shut things down cleanly

queue queue.Queue // In not nil, this will be used to queue publish requests
Expand Down Expand Up @@ -241,6 +242,7 @@ func NewConnection(ctx context.Context, cfg ClientConfig) (*ConnectionManager, e
c := ConnectionManager{
cli: nil,
connUp: make(chan struct{}),
cfg: cfg,
cancelCtx: cancel,
queue: cfg.Queue,
done: make(chan struct{}),
Expand Down Expand Up @@ -444,6 +446,11 @@ func (c *ConnectionManager) TerminateConnectionForTest() {
c.mu.Unlock()
}

// Router returns the paho router in use
func (c *ConnectionManager) Router() paho.Router {
return c.cfg.Router
}

// managePublishQueue sends messages from the publish queue.
// blocks until the context is cancelled.
func (c *ConnectionManager) managePublishQueue(ctx context.Context) error {
Expand Down

0 comments on commit c13be08

Please sign in to comment.