github.com/kaituanwang/hyperledger@v2.0.1+incompatible/orderer/consensus/kafka/partitioner.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package kafka
     8  
     9  import "github.com/Shopify/sarama"
    10  
    11  type staticPartitioner struct {
    12  	partitionID int32
    13  }
    14  
    15  // newStaticPartitioner returns a PartitionerConstructor that
    16  // returns a Partitioner that always chooses the specified partition.
    17  func newStaticPartitioner(partition int32) sarama.PartitionerConstructor {
    18  	return func(topic string) sarama.Partitioner {
    19  		return &staticPartitioner{partition}
    20  	}
    21  }
    22  
    23  // Partition takes a message and partition count and chooses a partition.
    24  func (prt *staticPartitioner) Partition(message *sarama.ProducerMessage, numPartitions int32) (int32, error) {
    25  	return prt.partitionID, nil
    26  }
    27  
    28  // RequiresConsistency indicates to the user of the partitioner whether the
    29  // mapping of key->partition is consistent or not.
    30  func (prt *staticPartitioner) RequiresConsistency() bool {
    31  	return true
    32  }