Validate method validates ReaderConfig properties.
()
| 526 | |
| 527 | // Validate method validates ReaderConfig properties. |
| 528 | func (config *ReaderConfig) Validate() error { |
| 529 | if len(config.Brokers) == 0 { |
| 530 | return errors.New("cannot create a new kafka reader with an empty list of broker addresses") |
| 531 | } |
| 532 | |
| 533 | if config.Partition < 0 || config.Partition >= math.MaxInt32 { |
| 534 | return fmt.Errorf("partition number out of bounds: %d", config.Partition) |
| 535 | } |
| 536 | |
| 537 | if config.MinBytes < 0 { |
| 538 | return fmt.Errorf("invalid negative minimum batch size (min = %d)", config.MinBytes) |
| 539 | } |
| 540 | |
| 541 | if config.MaxBytes < 0 { |
| 542 | return fmt.Errorf("invalid negative maximum batch size (max = %d)", config.MaxBytes) |
| 543 | } |
| 544 | |
| 545 | if config.GroupID != "" { |
| 546 | if config.Partition != 0 { |
| 547 | return errors.New("either Partition or GroupID may be specified, but not both") |
| 548 | } |
| 549 | |
| 550 | if len(config.Topic) == 0 && len(config.GroupTopics) == 0 { |
| 551 | return errors.New("either Topic or GroupTopics must be specified with GroupID") |
| 552 | } |
| 553 | } else if len(config.Topic) == 0 { |
| 554 | return errors.New("cannot create a new kafka reader with an empty topic") |
| 555 | } |
| 556 | |
| 557 | if config.MinBytes > config.MaxBytes { |
| 558 | return fmt.Errorf("minimum batch size greater than the maximum (min = %d, max = %d)", config.MinBytes, config.MaxBytes) |
| 559 | } |
| 560 | |
| 561 | if config.ReadBackoffMax < 0 { |
| 562 | return fmt.Errorf("ReadBackoffMax out of bounds: %d", config.ReadBackoffMax) |
| 563 | } |
| 564 | |
| 565 | if config.ReadBackoffMin < 0 { |
| 566 | return fmt.Errorf("ReadBackoffMin out of bounds: %d", config.ReadBackoffMin) |
| 567 | } |
| 568 | |
| 569 | return nil |
| 570 | } |
| 571 | |
| 572 | // ReaderStats is a data structure returned by a call to Reader.Stats that exposes |
| 573 | // details about the behavior of the reader. |
no outgoing calls