1414
1515namespace Kafka \Consumer ;
1616
17+ use Kafka \ConsumerConfig ;
18+
1719/**
1820+------------------------------------------------------------------------------
1921* Kafka protocol since Kafka v0.8
@@ -660,8 +662,31 @@ public function succFetch($result, $fd)
660662 // }}}
661663 // {{{ protected function commit()
662664
665+ protected function consume_msg ()
666+ {
667+ foreach ($ this ->messages as $ topic => $ value ) {
668+ foreach ($ value as $ part => $ messages ) {
669+ foreach ($ messages as $ message ) {
670+ if ($ this ->consumer != null ) {
671+ call_user_func ($ this ->consumer , $ topic , $ part , $ message );
672+ }
673+ }
674+ }
675+ }
676+
677+ $ this ->messages = array ();
678+ }
679+
680+
663681 protected function commit ()
664682 {
683+ $ config = ConsumerConfig::getInstance ();
684+ if ($ config ->getConsumeMode () == ConsumerConfig::CONSUME_BEFORE_COMMIT_OFFSET )
685+ {
686+ $ this ->consume_msg ();
687+ }
688+
689+
665690 $ broker = \Kafka \Broker::getInstance ();
666691 $ groupBrokerId = $ broker ->getGroupBrokerId ();
667692 $ connect = $ broker ->getMetaConnect ($ groupBrokerId );
@@ -704,6 +729,10 @@ protected function commit()
704729 // }}}
705730 // {{{ public function succCommit()
706731
732+ /**
733+ * @var State
734+ */
735+ public $ state ;
707736 public function succCommit ($ result )
708737 {
709738 $ this ->debug ('Commit success, result: ' . json_encode ($ result ));
@@ -716,17 +745,10 @@ public function succCommit($result)
716745 }
717746 }
718747 }
719-
720- foreach ($ this ->messages as $ topic => $ value ) {
721- foreach ($ value as $ part => $ messages ) {
722- foreach ($ messages as $ message ) {
723- if ($ this ->consumer != null ) {
724- call_user_func ($ this ->consumer , $ topic , $ part , $ message );
725- }
726- }
727- }
748+ if (ConsumerConfig::getInstance ()->getConsumeMode () == ConsumerConfig::CONSUME_AFTER_COMMIT_OFFSET )
749+ {
750+ $ this ->consume_msg ();
728751 }
729- $ this ->messages = array ();
730752 }
731753
732754 // }}}
0 commit comments