code: func (s *StanServer) replicate(iopms []*ioPendingMsg) (map[*channel]raft.Future, error) {
  	var (
  		futures = make(map[*channel]raft.Future)
  		batches = make(map[*channel]*spb.Batch)
  	)
  	for _, iopm := range iopms {
  		pm := &iopm.pm
  		c, err := s.lookupOrCreateChannel(pm.Subject)
  		if err != nil {
  			return nil, err
  		}
  		msg := c.pubMsgToMsgProto(pm, c.nextSequence)
  		batch := batches[c]
  		if batch == nil {
  			batch = &spb.Batch{}
  			batches[c] = batch
  		}
  		batch.Messages = append(batch.Messages, msg)
  		iopm.c = c
  		c.nextSequence++
  	}
  	for c, batch := range batches {
  		op := &spb.RaftOperation{
  			OpType:       spb.RaftOperation_Publish,
  			PublishBatch: batch,
  		}
  		data, err := op.Marshal()
  		if err != nil {
  			panic(err)
  		}
  		futures[c] = s.raft.Apply(data, 0)
  	}
  	return futures, nil
  }
docs: // replicate will replicate the batch of messages to followers and return
  // futures (one for each channel messages were replicated for) which, when
  // waited upon, will indicate if the replication was successful or not. This
  // should only be called if running in clustered mode.