func (q *PriorityQueue) publisher(pri int) (broker.Publisher, error) {
	if pri > q.Max() || pri < q.Min() {
		return nil, fmt.Errorf("Priority out of range: %d", pri)
	}
	if q.publishers[pri] == nil {
		pub, err := q.source.Publisher(queueName(q.prefix, pri))
		if err != nil {
			return nil, err
		}
		q.publishers[pri] = pub
	}
	return q.publishers[pri], nil
}
publisher returns a new publisher from the priority indicated by pri.
package pq
import (
	"fmt"
	"reflect"
	"sync"
	"time"
	"github.com/armon/relay/broker"
)
var (
	MinQuietPeriod = 10 * time.Millisecond
)
type PriorityQueue struct {
	max          int
	source       broker.Broker
	prefix       string
	quietPeriod  time.Duration
	publishers   []broker.Publisher
	shutdownLock sync.Mutex
	shutdown     bool
}
type priorityResp struct {
	value    interface{}
	priority int
	consumer broker.Consumer
}
func NewPriorityQueue(
	b broker.Broker,
	pri int,
	prefix string,
	quietPeriod time.Duration) (*PriorityQueue, error) {
	if b == nil {
		return nil, fmt.Errorf("Broker must not be nil")
	}
	if pri < 1 {
		return nil, fmt.Errorf("Must be 1 or more priorities")
	}
	if quietPeriod < MinQuietPeriod {
		quietPeriod = MinQuietPeriod
	}
	q := PriorityQueue{
		source:      b,
		prefix:      prefix,
		max:         pri - 1,
		quietPeriod: quietPeriod,
	}
	q.publishers = make([]broker.Publisher, pri)
	return &q, nil
}
func queueName(prefix string, pri int) string {
	return fmt.Sprintf("%s-%d", prefix, pri)
}
func (q *PriorityQueue) Max() int {
	return q.max
}
func (q *PriorityQueue) Min() int {
	return 0
}