12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- package sarama
- type RequiredAcks int16
- const (
-
- NoResponse RequiredAcks = 0
-
- WaitForLocal RequiredAcks = 1
-
- WaitForAll RequiredAcks = -1
- )
- type ProduceRequest struct {
- RequiredAcks RequiredAcks
- Timeout int32
- msgSets map[string]map[int32]*MessageSet
- }
- func (p *ProduceRequest) encode(pe packetEncoder) error {
- pe.putInt16(int16(p.RequiredAcks))
- pe.putInt32(p.Timeout)
- err := pe.putArrayLength(len(p.msgSets))
- if err != nil {
- return err
- }
- for topic, partitions := range p.msgSets {
- err = pe.putString(topic)
- if err != nil {
- return err
- }
- err = pe.putArrayLength(len(partitions))
- if err != nil {
- return err
- }
- for id, msgSet := range partitions {
- pe.putInt32(id)
- pe.push(&lengthField{})
- err = msgSet.encode(pe)
- if err != nil {
- return err
- }
- err = pe.pop()
- if err != nil {
- return err
- }
- }
- }
- return nil
- }
- func (p *ProduceRequest) key() int16 {
- return 0
- }
- func (p *ProduceRequest) version() int16 {
- return 0
- }
- func (p *ProduceRequest) AddMessage(topic string, partition int32, msg *Message) {
- if p.msgSets == nil {
- p.msgSets = make(map[string]map[int32]*MessageSet)
- }
- if p.msgSets[topic] == nil {
- p.msgSets[topic] = make(map[int32]*MessageSet)
- }
- set := p.msgSets[topic][partition]
- if set == nil {
- set = new(MessageSet)
- p.msgSets[topic][partition] = set
- }
- set.addMessage(msg)
- }
- func (p *ProduceRequest) AddSet(topic string, partition int32, set *MessageSet) {
- if p.msgSets == nil {
- p.msgSets = make(map[string]map[int32]*MessageSet)
- }
- if p.msgSets[topic] == nil {
- p.msgSets[topic] = make(map[int32]*MessageSet)
- }
- p.msgSets[topic][partition] = set
- }
|