@@ -81,18 +81,19 @@ public function getConfiguration(): array
8181 * Consumes a message and returns it
8282 * In cases of errors / timeouts an exception is thrown
8383 *
84+ * @param integer $timeoutMs
8485 * @return KafkaConsumerMessageInterface
8586 * @throws KafkaConsumerConsumeException
8687 * @throws KafkaConsumerEndOfPartitionException
8788 * @throws KafkaConsumerTimeoutException
8889 */
89- public function consume (): KafkaConsumerMessageInterface
90+ public function consume (int $ timeoutMs = 10000 ): KafkaConsumerMessageInterface
9091 {
9192 if (false === $ this ->isSubscribed ()) {
9293 throw new KafkaConsumerConsumeException (KafkaConsumerConsumeException::NOT_SUBSCRIBED_EXCEPTION_MESSAGE );
9394 }
9495
95- if (null === $ rdKafkaMessage = $ this ->kafkaConsume ($ this -> kafkaConfiguration -> getTimeout () )) {
96+ if (null === $ rdKafkaMessage = $ this ->kafkaConsume ($ timeoutMs )) {
9697 throw new KafkaConsumerEndOfPartitionException (
9798 rd_kafka_err2str (RD_KAFKA_RESP_ERR__PARTITION_EOF ),
9899 RD_KAFKA_RESP_ERR__PARTITION_EOF
@@ -118,17 +119,18 @@ public function consume(): KafkaConsumerMessageInterface
118119 * Queries the broker for metadata on a certain topic
119120 *
120121 * @param string $topicName
122+ * @param integer $timeoutMs
121123 * @return RdKafkaMetadataTopic
122124 * @throws RdKafkaException
123125 */
124- public function getMetadataForTopic (string $ topicName ): RdKafkaMetadataTopic
126+ public function getMetadataForTopic (string $ topicName, int $ timeoutMs = 10000 ): RdKafkaMetadataTopic
125127 {
126128 $ topic = $ this ->consumer ->newTopic ($ topicName );
127129 return $ this ->consumer
128130 ->getMetadata (
129131 false ,
130132 $ topic ,
131- $ this -> kafkaConfiguration -> getTimeout ()
133+ $ timeoutMs
132134 )
133135 ->getTopics ()
134136 ->current ();
@@ -138,28 +140,28 @@ public function getMetadataForTopic(string $topicName): RdKafkaMetadataTopic
138140 * Get the earliest offset for a certain timestamp for topic partitions
139141 *
140142 * @param array|RdKafkaTopicPartition[] $topicPartitions
141- * @param integer $timeout
143+ * @param integer $timeoutMs
142144 * @return array|RdKafkaTopicPartition[]
143145 */
144- public function offsetsForTimes (array $ topicPartitions , int $ timeout ): array
146+ public function offsetsForTimes (array $ topicPartitions , int $ timeoutMs ): array
145147 {
146- return $ this ->consumer ->offsetsForTimes ($ topicPartitions , $ timeout );
148+ return $ this ->consumer ->offsetsForTimes ($ topicPartitions , $ timeoutMs );
147149 }
148150
149151 /**
150152 * Queries the broker for the first offset of a given topic and partition
151153 *
152154 * @param string $topic
153155 * @param integer $partition
154- * @param integer $timeout
156+ * @param integer $timeoutMs
155157 * @return integer
156158 */
157- public function getFirstOffsetForTopicPartition (string $ topic , int $ partition , int $ timeout ): int
159+ public function getFirstOffsetForTopicPartition (string $ topic , int $ partition , int $ timeoutMs ): int
158160 {
159161 $ lowOffset = 0 ;
160162 $ highOffset = 0 ;
161163
162- $ this ->consumer ->queryWatermarkOffsets ($ topic , $ partition , $ lowOffset , $ highOffset , $ timeout );
164+ $ this ->consumer ->queryWatermarkOffsets ($ topic , $ partition , $ lowOffset , $ highOffset , $ timeoutMs );
163165
164166 return $ lowOffset ;
165167 }
@@ -169,15 +171,15 @@ public function getFirstOffsetForTopicPartition(string $topic, int $partition, i
169171 *
170172 * @param string $topic
171173 * @param integer $partition
172- * @param integer $timeout
174+ * @param integer $timeoutMs
173175 * @return integer
174176 */
175- public function getLastOffsetForTopicPartition (string $ topic , int $ partition , int $ timeout ): int
177+ public function getLastOffsetForTopicPartition (string $ topic , int $ partition , int $ timeoutMs ): int
176178 {
177179 $ lowOffset = 0 ;
178180 $ highOffset = 0 ;
179181
180- $ this ->consumer ->queryWatermarkOffsets ($ topic , $ partition , $ lowOffset , $ highOffset , $ timeout );
182+ $ this ->consumer ->queryWatermarkOffsets ($ topic , $ partition , $ lowOffset , $ highOffset , $ timeoutMs );
181183
182184 return $ highOffset ;
183185 }
@@ -200,8 +202,8 @@ protected function getConsumerMessage(RdKafkaMessage $message): KafkaConsumerMes
200202 }
201203
202204 /**
203- * @param integer $timeout
205+ * @param integer $timeoutMs
204206 * @return null|RdKafkaMessage
205207 */
206- abstract protected function kafkaConsume (int $ timeout ): ?RdKafkaMessage ;
208+ abstract protected function kafkaConsume (int $ timeoutMs ): ?RdKafkaMessage ;
207209}
0 commit comments