sarama.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. Package sarama provides client libraries for the Kafka protocol (versions 0.8 and later). The AsyncProducer object
  3. is the high-level API for producing messages asynchronously; the SyncProducer provides a blocking API for the same purpose.
  4. The Consumer object is the high-level API for consuming messages. The Client object provides metadata
  5. management functionality that is shared between the higher-level objects.
  6. Note that Sarama's Consumer type does not currently support automatic consumer-group rebalancing and offset tracking.
  7. For Zookeeper-based tracking (Kafka 0.8.2 and earlier), the https://github.com/wvanbergen/kafka library
  8. builds on Sarama to add this support. For Kafka-based tracking (Kafka 0.9 and later), the
  9. https://github.com/bsm/sarama-cluster library builds on Sarama to add this support.
  10. For lower-level needs, the Broker and Request/Response objects permit precise control over each connection
  11. and message sent on the wire.
  12. The Request/Response objects and properties are mostly undocumented, as they line up exactly with the
  13. protocol fields documented by Kafka at https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol
  14. */
  15. package sarama
  16. import (
  17. "io/ioutil"
  18. "log"
  19. )
  20. // Logger is the instance of a StdLogger interface that Sarama writes connection
  21. // management events to. By default it is set to discard all log messages via ioutil.Discard,
  22. // but you can set it to redirect wherever you want.
  23. var Logger StdLogger = log.New(ioutil.Discard, "[Sarama] ", log.LstdFlags)
  24. // StdLogger is used to log error messages.
  25. type StdLogger interface {
  26. Print(v ...interface{})
  27. Printf(format string, v ...interface{})
  28. Println(v ...interface{})
  29. }
  30. // PanicHandler is called for recovering from panics spawned internally to the library (and thus
  31. // not recoverable by the caller's goroutine). Defaults to nil, which means panics are not recovered.
  32. var PanicHandler func(interface{})
  33. // MaxRequestSize is the maximum size (in bytes) of any request that Sarama will attempt to send. Trying
  34. // to send a request larger than this will result in an PacketEncodingError. The default of 100 MiB is aligned
  35. // with Kafka's default `socket.request.max.bytes`, which is the largest request the broker will attempt
  36. // to process.
  37. var MaxRequestSize int32 = 100 * 1024 * 1024
  38. // MaxResponseSize is the maximum size (in bytes) of any response that Sarama will attempt to parse. If
  39. // a broker returns a response message larger than this value, Sarama will return a PacketDecodingError to
  40. // protect the client from running out of memory. Please note that brokers do not have any natural limit on
  41. // the size of responses they send. In particular, they can send arbitrarily large fetch responses to consumers
  42. // (see https://issues.apache.org/jira/browse/KAFKA-2063).
  43. var MaxResponseSize int32 = 100 * 1024 * 1024