// NewPublisher is a Publisher constructor
439072
func NewPublisher(exchange string, key string, opts ...PublisherOpt) *Publisher {
	p := &Publisher{
		exchange: exchange,
		key:      key,
		pubChan:  make(chan publishMaybeErr),
		stop:     make(chan struct{}),
	}
	for _, o := range opts {
		o(p)
	}
	return p
}
90236
func NewPublisher(
	publisher *nats.Conn,
	subject string,
	enc EncodeRequestFunc,
	dec DecodeResponseFunc,
	options ...PublisherOption,
) *Publisher {
	p := &Publisher{
		publisher: publisher,
		subject:   subject,
		enc:       enc,
		dec:       dec,
		timeout:   10 * time.Second,
	}
	for _, option := range options {
		option(p)
	}
	return p
}
905374
func New(primary bool, local, remote string) (bstar *Bstar, err error) {

	bstar = &Bstar{}

	//  Initialize the Binary Star
	bstar.Reactor = zmq.NewReactor()
	if primary {
		bstar.state = state_PRIMARY
	} else {
		bstar.state = state_BACKUP
	}

	//  Create publisher for state going to peer
	bstar.statepub, err = zmq.NewSocket(zmq.PUB)
	bstar.statepub.Bind(local)

	//  Create subscriber for state coming from peer
	bstar.statesub, err = zmq.NewSocket(zmq.SUB)
	bstar.statesub.SetSubscribe("")
	bstar.statesub.Connect(remote)

	//  Set-up basic reactor events
	bstar.Reactor.AddChannelTime(time.Tick(bstar_HEARTBEAT), 1,
		func(i interface{}) error { return bstar.send_state() })
	bstar.Reactor.AddSocket(bstar.statesub, zmq.POLLIN,
		func(e zmq.State) error { return bstar.recv_state() })

	return
}
14953
func (a *Agent) Publisher(ctx context.Context, subscriptionID string) (exec.LogPublisher, func(), error) {
	// TODO(stevvooe): The level of coordination here is WAY too much for logs.
	// These should only be best effort and really just buffer until a session is
	// ready. Ideally, they would use a separate connection completely.

	var (
		err       error
		publisher api.LogBroker_PublishLogsClient
	)

	err = a.withSession(ctx, func(session *session) error {
		publisher, err = api.NewLogBrokerClient(session.conn.ClientConn).PublishLogs(ctx)
		return err
	})
	if err != nil {
		return nil, nil, err
	}

	// make little closure for ending the log stream
	sendCloseMsg := func() {
		// send a close message, to tell the manager our logs are done
		publisher.Send(&api.PublishLogsMessage{
			SubscriptionID: subscriptionID,
			Close:          true,
		})
		// close the stream forreal
		publisher.CloseSend()
	}

	return exec.LogPublisherFunc(func(ctx context.Context, message api.LogMessage) error {
			select {
			case <-ctx.Done():
				sendCloseMsg()
				return ctx.Err()
			default:
			}

			return publisher.Send(&api.PublishLogsMessage{
				SubscriptionID: subscriptionID,
				Messages:       []api.LogMessage{message},
			})
		}), func() {
			sendCloseMsg()
		}, nil
}
1004763
func newPublicationTracker(pub publicationDescriptor, profile *StatsProfile) *tracker {
	return &tracker{
		profile:     profile,
		reqService:  "micro.pubsub",
		reqEndpoint: pub.Topic(),
	}
}
1109330
func newPeer(host *Whisper, remote *p2p.Peer, rw p2p.MsgReadWriter) *Peer {
	return &Peer{
		host:           host,
		peer:           remote,
		ws:             rw,
		trusted:        false,
		powRequirement: 0.0,
		known:          mapset.NewSet(),
		quit:           make(chan struct{}),
		bloomFilter:    MakeFullNodeBloom(),
		fullNode:       true,
	}
}
444651
func NewRepublisher(ns namesys.Publisher, ds ds.Datastore, self ic.PrivKey, ks keystore.Keystore) *Republisher {
	return &Republisher{
		ns:             ns,
		ds:             ds,
		self:           self,
		ks:             ks,
		Interval:       DefaultRebroadcastInterval,
		RecordLifetime: DefaultRecordLifetime,
	}
}
996032
func (e *engineImpl) PullPubSubOnDevServer(c context.Context, taskManagerName, publisher string) error {
	_, sub := e.genTopicAndSubNames(c, taskManagerName, publisher)
	msg, ack, err := pullSubcription(c, sub, "")
	if err != nil {
		return err
	}
	if msg == nil {
		logging.Infof(c, "No new PubSub messages")
		return nil
	}
	switch err = e.handlePubSubMessage(c, msg); {
	case err == nil:
		ack() // success
	case transient.Tag.In(err) || tq.Retry.In(err):
		// don't ack, ask for redelivery
	default:
		ack() // fatal error
	}
	return err
}
372660
func NewDestinationPublisher(fs afero.Fs, outputFormats output.Formats, mediaTypes media.Types, minify bool) DestinationPublisher {
	pub := DestinationPublisher{fs: fs}
	if minify {
		pub.min = minifiers.New(mediaTypes, outputFormats)
		pub.minify = true
	}
	return pub
}
531075
func (a *MandrillAPI) TemplatePublish(name string) (Template, error) {
	if name == "" {
		return Template{}, errors.New("name cannot be blank")
	}
	var params map[string]interface{} = make(map[string]interface{})
	params["name"] = name
	return execute(a, params, templates_publish_endpoint)
}
372009
func IsPublishableModel(model interface{}) (ok bool) {
	if model != nil {
		_, ok = reflect.New(utils.ModelType(model)).Interface().(publishInterface)
	}
	return
}
922345
func setPublishOption(k, v interface{}) broker.PublishOption {
	return func(o *broker.PublishOptions) {
		if o.Context == nil {
			o.Context = context.Background()
		}
		o.Context = context.WithValue(o.Context, k, v)
	}
}
434138
func (s *CreateFunctionInput) SetPublish(v bool) *CreateFunctionInput {
	s.Publish = &v
	return s
}
1221004
func NewPubsub(pool *redis.Pool) *Pubsub {
	ps := &Pubsub{
		pool:   pool,
		errs:   make(chan error),
		closer: make(chan struct{}),
		send:   make(chan command),
		subs: []*RecordList{
			PlainEvent:   NewRecordList(),
			PatternEvent: NewRecordList(),
		},
	}

	go ps.work()

	return ps
}
171483
func readAndPublish(r *bufio.Reader, delim byte, producers map[string]*nsq.Producer) error {
	line, readErr := r.ReadBytes(delim)

	if len(line) > 0 {
		// trim the delimiter
		line = line[:len(line)-1]
	}

	if len(line) == 0 {
		return readErr
	}

	for _, producer := range producers {
		err := producer.Publish(*topic, line)
		if err != nil {
			return err
		}
	}

	return readErr
}
181649
func PublisherAfter(after ...PublisherResponseFunc) PublisherOption {
	return func(p *Publisher) { p.after = append(p.after, after...) }
}
534455
func NewPUBCOMP(opts *PUBCOMPOptions) (Packet, error) {
	// Initialize the options.
	if opts == nil {
		opts = &PUBCOMPOptions{}
	}

	// Validate the options.
	if err := opts.validate(); err != nil {
		return nil, err
	}

	// Create a PUBCOMP Packet.
	p := &PUBCOMP{
		PacketID: opts.PacketID,
	}

	// Set the variable header to the Packet.
	p.setVariableHeader()

	// Set the Fixed header to the Packet.
	p.setFixedHeader()

	// Return the Packet.
	return p, nil
}