consumer.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. package sarama
  2. import (
  3. "errors"
  4. "fmt"
  5. "sync"
  6. "sync/atomic"
  7. "time"
  8. )
  9. // ConsumerMessage encapsulates a Kafka message returned by the consumer.
  10. type ConsumerMessage struct {
  11. Key, Value []byte
  12. Topic string
  13. Partition int32
  14. Offset int64
  15. }
  16. // ConsumerError is what is provided to the user when an error occurs.
  17. // It wraps an error and includes the topic and partition.
  18. type ConsumerError struct {
  19. Topic string
  20. Partition int32
  21. Err error
  22. }
  23. func (ce ConsumerError) Error() string {
  24. return fmt.Sprintf("kafka: error while consuming %s/%d: %s", ce.Topic, ce.Partition, ce.Err)
  25. }
  26. // ConsumerErrors is a type that wraps a batch of errors and implements the Error interface.
  27. // It can be returned from the PartitionConsumer's Close methods to avoid the need to manually drain errors
  28. // when stopping.
  29. type ConsumerErrors []*ConsumerError
  30. func (ce ConsumerErrors) Error() string {
  31. return fmt.Sprintf("kafka: %d errors while consuming", len(ce))
  32. }
  33. // Consumer manages PartitionConsumers which process Kafka messages from brokers. You MUST call Close()
  34. // on a consumer to avoid leaks, it will not be garbage-collected automatically when it passes out of
  35. // scope.
  36. //
  37. // Sarama's Consumer type does not currently support automatic consumer-group rebalancing and offset tracking.
  38. // For Zookeeper-based tracking (Kafka 0.8.2 and earlier), the https://github.com/wvanbergen/kafka library
  39. // builds on Sarama to add this support. For Kafka-based tracking (Kafka 0.9 and later), the
  40. // https://github.com/bsm/sarama-cluster library builds on Sarama to add this support.
  41. type Consumer interface {
  42. // Topics returns the set of available topics as retrieved from the cluster
  43. // metadata. This method is the same as Client.Topics(), and is provided for
  44. // convenience.
  45. Topics() ([]string, error)
  46. // Partitions returns the sorted list of all partition IDs for the given topic.
  47. // This method is the same as Client.Partitions(), and is provided for convenience.
  48. Partitions(topic string) ([]int32, error)
  49. // ConsumePartition creates a PartitionConsumer on the given topic/partition with
  50. // the given offset. It will return an error if this Consumer is already consuming
  51. // on the given topic/partition. Offset can be a literal offset, or OffsetNewest
  52. // or OffsetOldest
  53. ConsumePartition(topic string, partition int32, offset int64) (PartitionConsumer, error)
  54. // Close shuts down the consumer. It must be called after all child
  55. // PartitionConsumers have already been closed.
  56. Close() error
  57. }
  58. type consumer struct {
  59. client Client
  60. conf *Config
  61. ownClient bool
  62. lock sync.Mutex
  63. children map[string]map[int32]*partitionConsumer
  64. brokerConsumers map[*Broker]*brokerConsumer
  65. }
  66. // NewConsumer creates a new consumer using the given broker addresses and configuration.
  67. func NewConsumer(addrs []string, config *Config) (Consumer, error) {
  68. client, err := NewClient(addrs, config)
  69. if err != nil {
  70. return nil, err
  71. }
  72. c, err := NewConsumerFromClient(client)
  73. if err != nil {
  74. return nil, err
  75. }
  76. c.(*consumer).ownClient = true
  77. return c, nil
  78. }
  79. // NewConsumerFromClient creates a new consumer using the given client. It is still
  80. // necessary to call Close() on the underlying client when shutting down this consumer.
  81. func NewConsumerFromClient(client Client) (Consumer, error) {
  82. // Check that we are not dealing with a closed Client before processing any other arguments
  83. if client.Closed() {
  84. return nil, ErrClosedClient
  85. }
  86. c := &consumer{
  87. client: client,
  88. conf: client.Config(),
  89. children: make(map[string]map[int32]*partitionConsumer),
  90. brokerConsumers: make(map[*Broker]*brokerConsumer),
  91. }
  92. return c, nil
  93. }
  94. func (c *consumer) Close() error {
  95. if c.ownClient {
  96. return c.client.Close()
  97. }
  98. return nil
  99. }
  100. func (c *consumer) Topics() ([]string, error) {
  101. return c.client.Topics()
  102. }
  103. func (c *consumer) Partitions(topic string) ([]int32, error) {
  104. return c.client.Partitions(topic)
  105. }
  106. func (c *consumer) ConsumePartition(topic string, partition int32, offset int64) (PartitionConsumer, error) {
  107. child := &partitionConsumer{
  108. consumer: c,
  109. conf: c.conf,
  110. topic: topic,
  111. partition: partition,
  112. messages: make(chan *ConsumerMessage, c.conf.ChannelBufferSize),
  113. errors: make(chan *ConsumerError, c.conf.ChannelBufferSize),
  114. feeder: make(chan *FetchResponse, 1),
  115. trigger: make(chan none, 1),
  116. dying: make(chan none),
  117. fetchSize: c.conf.Consumer.Fetch.Default,
  118. }
  119. if err := child.chooseStartingOffset(offset); err != nil {
  120. return nil, err
  121. }
  122. var leader *Broker
  123. var err error
  124. if leader, err = c.client.Leader(child.topic, child.partition); err != nil {
  125. return nil, err
  126. }
  127. if err := c.addChild(child); err != nil {
  128. return nil, err
  129. }
  130. go withRecover(child.dispatcher)
  131. go withRecover(child.responseFeeder)
  132. child.broker = c.refBrokerConsumer(leader)
  133. child.broker.input <- child
  134. return child, nil
  135. }
  136. func (c *consumer) addChild(child *partitionConsumer) error {
  137. c.lock.Lock()
  138. defer c.lock.Unlock()
  139. topicChildren := c.children[child.topic]
  140. if topicChildren == nil {
  141. topicChildren = make(map[int32]*partitionConsumer)
  142. c.children[child.topic] = topicChildren
  143. }
  144. if topicChildren[child.partition] != nil {
  145. return ConfigurationError("That topic/partition is already being consumed")
  146. }
  147. topicChildren[child.partition] = child
  148. return nil
  149. }
  150. func (c *consumer) removeChild(child *partitionConsumer) {
  151. c.lock.Lock()
  152. defer c.lock.Unlock()
  153. delete(c.children[child.topic], child.partition)
  154. }
  155. func (c *consumer) refBrokerConsumer(broker *Broker) *brokerConsumer {
  156. c.lock.Lock()
  157. defer c.lock.Unlock()
  158. bc := c.brokerConsumers[broker]
  159. if bc == nil {
  160. bc = c.newBrokerConsumer(broker)
  161. c.brokerConsumers[broker] = bc
  162. }
  163. bc.refs++
  164. return bc
  165. }
  166. func (c *consumer) unrefBrokerConsumer(brokerWorker *brokerConsumer) {
  167. c.lock.Lock()
  168. defer c.lock.Unlock()
  169. brokerWorker.refs--
  170. if brokerWorker.refs == 0 {
  171. close(brokerWorker.input)
  172. if c.brokerConsumers[brokerWorker.broker] == brokerWorker {
  173. delete(c.brokerConsumers, brokerWorker.broker)
  174. }
  175. }
  176. }
  177. func (c *consumer) abandonBrokerConsumer(brokerWorker *brokerConsumer) {
  178. c.lock.Lock()
  179. defer c.lock.Unlock()
  180. delete(c.brokerConsumers, brokerWorker.broker)
  181. }
  182. // PartitionConsumer
  183. // PartitionConsumer processes Kafka messages from a given topic and partition. You MUST call Close()
  184. // or AsyncClose() on a PartitionConsumer to avoid leaks, it will not be garbage-collected automatically
  185. // when it passes out of scope.
  186. //
  187. // The simplest way of using a PartitionConsumer is to loop over its Messages channel using a for/range
  188. // loop. The PartitionConsumer will only stop itself in one case: when the offset being consumed is reported
  189. // as out of range by the brokers. In this case you should decide what you want to do (try a different offset,
  190. // notify a human, etc) and handle it appropriately. For all other error cases, it will just keep retrying.
  191. // By default, it logs these errors to sarama.Logger; if you want to be notified directly of all errors, set
  192. // your config's Consumer.Return.Errors to true and read from the Errors channel, using a select statement
  193. // or a separate goroutine. Check out the Consumer examples to see implementations of these different approaches.
  194. type PartitionConsumer interface {
  195. // AsyncClose initiates a shutdown of the PartitionConsumer. This method will
  196. // return immediately, after which you should wait until the 'messages' and
  197. // 'errors' channel are drained. It is required to call this function, or
  198. // Close before a consumer object passes out of scope, as it will otherwise
  199. // leak memory. You must call this before calling Close on the underlying client.
  200. AsyncClose()
  201. // Close stops the PartitionConsumer from fetching messages. It is required to
  202. // call this function (or AsyncClose) before a consumer object passes out of
  203. // scope, as it will otherwise leak memory. You must call this before calling
  204. // Close on the underlying client.
  205. Close() error
  206. // Messages returns the read channel for the messages that are returned by
  207. // the broker.
  208. Messages() <-chan *ConsumerMessage
  209. // Errors returns a read channel of errors that occurred during consuming, if
  210. // enabled. By default, errors are logged and not returned over this channel.
  211. // If you want to implement any custom error handling, set your config's
  212. // Consumer.Return.Errors setting to true, and read from this channel.
  213. Errors() <-chan *ConsumerError
  214. // HighWaterMarkOffset returns the high water mark offset of the partition,
  215. // i.e. the offset that will be used for the next message that will be produced.
  216. // You can use this to determine how far behind the processing is.
  217. HighWaterMarkOffset() int64
  218. }
  219. type partitionConsumer struct {
  220. consumer *consumer
  221. conf *Config
  222. topic string
  223. partition int32
  224. broker *brokerConsumer
  225. messages chan *ConsumerMessage
  226. errors chan *ConsumerError
  227. feeder chan *FetchResponse
  228. trigger, dying chan none
  229. responseResult error
  230. fetchSize int32
  231. offset int64
  232. highWaterMarkOffset int64
  233. }
  234. var errTimedOut = errors.New("timed out feeding messages to the user") // not user-facing
  235. func (child *partitionConsumer) sendError(err error) {
  236. cErr := &ConsumerError{
  237. Topic: child.topic,
  238. Partition: child.partition,
  239. Err: err,
  240. }
  241. if child.conf.Consumer.Return.Errors {
  242. child.errors <- cErr
  243. } else {
  244. Logger.Println(cErr)
  245. }
  246. }
  247. func (child *partitionConsumer) dispatcher() {
  248. for _ = range child.trigger {
  249. select {
  250. case <-child.dying:
  251. close(child.trigger)
  252. case <-time.After(child.conf.Consumer.Retry.Backoff):
  253. if child.broker != nil {
  254. child.consumer.unrefBrokerConsumer(child.broker)
  255. child.broker = nil
  256. }
  257. Logger.Printf("consumer/%s/%d finding new broker\n", child.topic, child.partition)
  258. if err := child.dispatch(); err != nil {
  259. child.sendError(err)
  260. child.trigger <- none{}
  261. }
  262. }
  263. }
  264. if child.broker != nil {
  265. child.consumer.unrefBrokerConsumer(child.broker)
  266. }
  267. child.consumer.removeChild(child)
  268. close(child.feeder)
  269. }
  270. func (child *partitionConsumer) dispatch() error {
  271. if err := child.consumer.client.RefreshMetadata(child.topic); err != nil {
  272. return err
  273. }
  274. var leader *Broker
  275. var err error
  276. if leader, err = child.consumer.client.Leader(child.topic, child.partition); err != nil {
  277. return err
  278. }
  279. child.broker = child.consumer.refBrokerConsumer(leader)
  280. child.broker.input <- child
  281. return nil
  282. }
  283. func (child *partitionConsumer) chooseStartingOffset(offset int64) error {
  284. newestOffset, err := child.consumer.client.GetOffset(child.topic, child.partition, OffsetNewest)
  285. if err != nil {
  286. return err
  287. }
  288. oldestOffset, err := child.consumer.client.GetOffset(child.topic, child.partition, OffsetOldest)
  289. if err != nil {
  290. return err
  291. }
  292. switch {
  293. case offset == OffsetNewest:
  294. child.offset = newestOffset
  295. case offset == OffsetOldest:
  296. child.offset = oldestOffset
  297. case offset >= oldestOffset && offset <= newestOffset:
  298. child.offset = offset
  299. default:
  300. return ErrOffsetOutOfRange
  301. }
  302. return nil
  303. }
  304. func (child *partitionConsumer) Messages() <-chan *ConsumerMessage {
  305. return child.messages
  306. }
  307. func (child *partitionConsumer) Errors() <-chan *ConsumerError {
  308. return child.errors
  309. }
  310. func (child *partitionConsumer) AsyncClose() {
  311. // this triggers whatever broker owns this child to abandon it and close its trigger channel, which causes
  312. // the dispatcher to exit its loop, which removes it from the consumer then closes its 'messages' and
  313. // 'errors' channel (alternatively, if the child is already at the dispatcher for some reason, that will
  314. // also just close itself)
  315. close(child.dying)
  316. }
  317. func (child *partitionConsumer) Close() error {
  318. child.AsyncClose()
  319. go withRecover(func() {
  320. for _ = range child.messages {
  321. // drain
  322. }
  323. })
  324. var errors ConsumerErrors
  325. for err := range child.errors {
  326. errors = append(errors, err)
  327. }
  328. if len(errors) > 0 {
  329. return errors
  330. }
  331. return nil
  332. }
  333. func (child *partitionConsumer) HighWaterMarkOffset() int64 {
  334. return atomic.LoadInt64(&child.highWaterMarkOffset)
  335. }
  336. func (child *partitionConsumer) responseFeeder() {
  337. var msgs []*ConsumerMessage
  338. feederLoop:
  339. for response := range child.feeder {
  340. msgs, child.responseResult = child.parseResponse(response)
  341. for i, msg := range msgs {
  342. select {
  343. case child.messages <- msg:
  344. case <-time.After(child.conf.Consumer.MaxProcessingTime):
  345. child.responseResult = errTimedOut
  346. child.broker.acks.Done()
  347. for _, msg = range msgs[i:] {
  348. child.messages <- msg
  349. }
  350. child.broker.input <- child
  351. continue feederLoop
  352. }
  353. }
  354. child.broker.acks.Done()
  355. }
  356. close(child.messages)
  357. close(child.errors)
  358. }
  359. func (child *partitionConsumer) parseResponse(response *FetchResponse) ([]*ConsumerMessage, error) {
  360. block := response.GetBlock(child.topic, child.partition)
  361. if block == nil {
  362. return nil, ErrIncompleteResponse
  363. }
  364. if block.Err != ErrNoError {
  365. return nil, block.Err
  366. }
  367. if len(block.MsgSet.Messages) == 0 {
  368. // We got no messages. If we got a trailing one then we need to ask for more data.
  369. // Otherwise we just poll again and wait for one to be produced...
  370. if block.MsgSet.PartialTrailingMessage {
  371. if child.conf.Consumer.Fetch.Max > 0 && child.fetchSize == child.conf.Consumer.Fetch.Max {
  372. // we can't ask for more data, we've hit the configured limit
  373. child.sendError(ErrMessageTooLarge)
  374. child.offset++ // skip this one so we can keep processing future messages
  375. } else {
  376. child.fetchSize *= 2
  377. if child.conf.Consumer.Fetch.Max > 0 && child.fetchSize > child.conf.Consumer.Fetch.Max {
  378. child.fetchSize = child.conf.Consumer.Fetch.Max
  379. }
  380. }
  381. }
  382. return nil, nil
  383. }
  384. // we got messages, reset our fetch size in case it was increased for a previous request
  385. child.fetchSize = child.conf.Consumer.Fetch.Default
  386. atomic.StoreInt64(&child.highWaterMarkOffset, block.HighWaterMarkOffset)
  387. incomplete := false
  388. prelude := true
  389. var messages []*ConsumerMessage
  390. for _, msgBlock := range block.MsgSet.Messages {
  391. for _, msg := range msgBlock.Messages() {
  392. if prelude && msg.Offset < child.offset {
  393. continue
  394. }
  395. prelude = false
  396. if msg.Offset >= child.offset {
  397. messages = append(messages, &ConsumerMessage{
  398. Topic: child.topic,
  399. Partition: child.partition,
  400. Key: msg.Msg.Key,
  401. Value: msg.Msg.Value,
  402. Offset: msg.Offset,
  403. })
  404. child.offset = msg.Offset + 1
  405. } else {
  406. incomplete = true
  407. }
  408. }
  409. }
  410. if incomplete || len(messages) == 0 {
  411. return nil, ErrIncompleteResponse
  412. }
  413. return messages, nil
  414. }
  415. // brokerConsumer
  416. type brokerConsumer struct {
  417. consumer *consumer
  418. broker *Broker
  419. input chan *partitionConsumer
  420. newSubscriptions chan []*partitionConsumer
  421. wait chan none
  422. subscriptions map[*partitionConsumer]none
  423. acks sync.WaitGroup
  424. refs int
  425. }
  426. func (c *consumer) newBrokerConsumer(broker *Broker) *brokerConsumer {
  427. bc := &brokerConsumer{
  428. consumer: c,
  429. broker: broker,
  430. input: make(chan *partitionConsumer),
  431. newSubscriptions: make(chan []*partitionConsumer),
  432. wait: make(chan none),
  433. subscriptions: make(map[*partitionConsumer]none),
  434. refs: 0,
  435. }
  436. go withRecover(bc.subscriptionManager)
  437. go withRecover(bc.subscriptionConsumer)
  438. return bc
  439. }
  440. func (bc *brokerConsumer) subscriptionManager() {
  441. var buffer []*partitionConsumer
  442. // The subscriptionManager constantly accepts new subscriptions on `input` (even when the main subscriptionConsumer
  443. // goroutine is in the middle of a network request) and batches it up. The main worker goroutine picks
  444. // up a batch of new subscriptions between every network request by reading from `newSubscriptions`, so we give
  445. // it nil if no new subscriptions are available. We also write to `wait` only when new subscriptions is available,
  446. // so the main goroutine can block waiting for work if it has none.
  447. for {
  448. if len(buffer) > 0 {
  449. select {
  450. case event, ok := <-bc.input:
  451. if !ok {
  452. goto done
  453. }
  454. buffer = append(buffer, event)
  455. case bc.newSubscriptions <- buffer:
  456. buffer = nil
  457. case bc.wait <- none{}:
  458. }
  459. } else {
  460. select {
  461. case event, ok := <-bc.input:
  462. if !ok {
  463. goto done
  464. }
  465. buffer = append(buffer, event)
  466. case bc.newSubscriptions <- nil:
  467. }
  468. }
  469. }
  470. done:
  471. close(bc.wait)
  472. if len(buffer) > 0 {
  473. bc.newSubscriptions <- buffer
  474. }
  475. close(bc.newSubscriptions)
  476. }
  477. func (bc *brokerConsumer) subscriptionConsumer() {
  478. <-bc.wait // wait for our first piece of work
  479. // the subscriptionConsumer ensures we will get nil right away if no new subscriptions is available
  480. for newSubscriptions := range bc.newSubscriptions {
  481. bc.updateSubscriptions(newSubscriptions)
  482. if len(bc.subscriptions) == 0 {
  483. // We're about to be shut down or we're about to receive more subscriptions.
  484. // Either way, the signal just hasn't propagated to our goroutine yet.
  485. <-bc.wait
  486. continue
  487. }
  488. response, err := bc.fetchNewMessages()
  489. if err != nil {
  490. Logger.Printf("consumer/broker/%d disconnecting due to error processing FetchRequest: %s\n", bc.broker.ID(), err)
  491. bc.abort(err)
  492. return
  493. }
  494. bc.acks.Add(len(bc.subscriptions))
  495. for child := range bc.subscriptions {
  496. child.feeder <- response
  497. }
  498. bc.acks.Wait()
  499. bc.handleResponses()
  500. }
  501. }
  502. func (bc *brokerConsumer) updateSubscriptions(newSubscriptions []*partitionConsumer) {
  503. for _, child := range newSubscriptions {
  504. bc.subscriptions[child] = none{}
  505. Logger.Printf("consumer/broker/%d added subscription to %s/%d\n", bc.broker.ID(), child.topic, child.partition)
  506. }
  507. for child := range bc.subscriptions {
  508. select {
  509. case <-child.dying:
  510. Logger.Printf("consumer/broker/%d closed dead subscription to %s/%d\n", bc.broker.ID(), child.topic, child.partition)
  511. close(child.trigger)
  512. delete(bc.subscriptions, child)
  513. default:
  514. break
  515. }
  516. }
  517. }
  518. func (bc *brokerConsumer) handleResponses() {
  519. // handles the response codes left for us by our subscriptions, and abandons ones that have been closed
  520. for child := range bc.subscriptions {
  521. result := child.responseResult
  522. child.responseResult = nil
  523. switch result {
  524. case nil:
  525. break
  526. case errTimedOut:
  527. Logger.Printf("consumer/broker/%d abandoned subscription to %s/%d because consuming was taking too long\n",
  528. bc.broker.ID(), child.topic, child.partition)
  529. delete(bc.subscriptions, child)
  530. case ErrOffsetOutOfRange:
  531. // there's no point in retrying this it will just fail the same way again
  532. // shut it down and force the user to choose what to do
  533. child.sendError(result)
  534. Logger.Printf("consumer/%s/%d shutting down because %s\n", child.topic, child.partition, result)
  535. close(child.trigger)
  536. delete(bc.subscriptions, child)
  537. case ErrUnknownTopicOrPartition, ErrNotLeaderForPartition, ErrLeaderNotAvailable, ErrReplicaNotAvailable:
  538. // not an error, but does need redispatching
  539. Logger.Printf("consumer/broker/%d abandoned subscription to %s/%d because %s\n",
  540. bc.broker.ID(), child.topic, child.partition, result)
  541. child.trigger <- none{}
  542. delete(bc.subscriptions, child)
  543. default:
  544. // dunno, tell the user and try redispatching
  545. child.sendError(result)
  546. Logger.Printf("consumer/broker/%d abandoned subscription to %s/%d because %s\n",
  547. bc.broker.ID(), child.topic, child.partition, result)
  548. child.trigger <- none{}
  549. delete(bc.subscriptions, child)
  550. }
  551. }
  552. }
  553. func (bc *brokerConsumer) abort(err error) {
  554. bc.consumer.abandonBrokerConsumer(bc)
  555. _ = bc.broker.Close() // we don't care about the error this might return, we already have one
  556. for child := range bc.subscriptions {
  557. child.sendError(err)
  558. child.trigger <- none{}
  559. }
  560. for newSubscription := range bc.newSubscriptions {
  561. for _, child := range newSubscription {
  562. child.sendError(err)
  563. child.trigger <- none{}
  564. }
  565. }
  566. }
  567. func (bc *brokerConsumer) fetchNewMessages() (*FetchResponse, error) {
  568. request := &FetchRequest{
  569. MinBytes: bc.consumer.conf.Consumer.Fetch.Min,
  570. MaxWaitTime: int32(bc.consumer.conf.Consumer.MaxWaitTime / time.Millisecond),
  571. }
  572. for child := range bc.subscriptions {
  573. request.AddBlock(child.topic, child.partition, child.offset, child.fetchSize)
  574. }
  575. return bc.broker.Fetch(request)
  576. }