produce_request.go 974 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package kafka
  2. const (
  3. NO_RESPONSE int16 = 0
  4. WAIT_FOR_LOCAL int16 = 1
  5. WAIT_FOR_ALL int16 = -1
  6. )
  7. type ProduceRequest struct {
  8. ResponseCondition int16
  9. Timeout int32
  10. MsgSets map[*string]map[int32]*messageSet
  11. }
  12. func (p *ProduceRequest) encode(pe packetEncoder) {
  13. pe.putInt16(p.ResponseCondition)
  14. pe.putInt32(p.Timeout)
  15. pe.putArrayCount(len(p.MsgSets))
  16. for topic, partitions := range p.MsgSets {
  17. pe.putString(topic)
  18. pe.putArrayCount(len(partitions))
  19. for id, msgSet := range partitions {
  20. pe.putInt32(id)
  21. msgSet.encode(pe)
  22. }
  23. }
  24. }
  25. func (p *ProduceRequest) key() int16 {
  26. return 0
  27. }
  28. func (p *ProduceRequest) version() int16 {
  29. return 0
  30. }
  31. func (p *ProduceRequest) AddMessageSet(topic *string, partition int32, set *messageSet) {
  32. if p.MsgSets == nil {
  33. p.MsgSets = make(map[*string]map[int32]*messageSet)
  34. }
  35. if p.MsgSets[topic] == nil {
  36. p.MsgSets[topic] = make(map[int32]*messageSet)
  37. }
  38. p.MsgSets[topic][partition] = set
  39. }