@@ -81,19 +81,20 @@ 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 * @param boolean $autoDecode
8586 * @return KafkaConsumerMessageInterface
8687 * @throws KafkaConsumerConsumeException
8788 * @throws KafkaConsumerEndOfPartitionException
8889 * @throws KafkaConsumerTimeoutException
8990 */
90- public function consume (bool $ autoDecode = true ): KafkaConsumerMessageInterface
91+ public function consume (int $ timeoutMs = 10000 , bool $ autoDecode = true ): KafkaConsumerMessageInterface
9192 {
9293 if (false === $ this ->isSubscribed ()) {
9394 throw new KafkaConsumerConsumeException (KafkaConsumerConsumeException::NOT_SUBSCRIBED_EXCEPTION_MESSAGE );
9495 }
9596
96- if (null === $ rdKafkaMessage = $ this ->kafkaConsume ($ this -> kafkaConfiguration -> getTimeout () )) {
97+ if (null === $ rdKafkaMessage = $ this ->kafkaConsume ($ timeoutMs )) {
9798 throw new KafkaConsumerEndOfPartitionException (
9899 rd_kafka_err2str (RD_KAFKA_RESP_ERR__PARTITION_EOF ),
99100 RD_KAFKA_RESP_ERR__PARTITION_EOF
@@ -134,17 +135,18 @@ public function decodeMessage(KafkaConsumerMessageInterface $message): KafkaCons
134135 * Queries the broker for metadata on a certain topic
135136 *
136137 * @param string $topicName
138+ * @param integer $timeoutMs
137139 * @return RdKafkaMetadataTopic
138140 * @throws RdKafkaException
139141 */
140- public function getMetadataForTopic (string $ topicName ): RdKafkaMetadataTopic
142+ public function getMetadataForTopic (string $ topicName, int $ timeoutMs = 10000 ): RdKafkaMetadataTopic
141143 {
142144 $ topic = $ this ->consumer ->newTopic ($ topicName );
143145 return $ this ->consumer
144146 ->getMetadata (
145147 false ,
146148 $ topic ,
147- $ this -> kafkaConfiguration -> getTimeout ()
149+ $ timeoutMs
148150 )
149151 ->getTopics ()
150152 ->current ();
@@ -154,28 +156,28 @@ public function getMetadataForTopic(string $topicName): RdKafkaMetadataTopic
154156 * Get the earliest offset for a certain timestamp for topic partitions
155157 *
156158 * @param array|RdKafkaTopicPartition[] $topicPartitions
157- * @param integer $timeout
159+ * @param integer $timeoutMs
158160 * @return array|RdKafkaTopicPartition[]
159161 */
160- public function offsetsForTimes (array $ topicPartitions , int $ timeout ): array
162+ public function offsetsForTimes (array $ topicPartitions , int $ timeoutMs ): array
161163 {
162- return $ this ->consumer ->offsetsForTimes ($ topicPartitions , $ timeout );
164+ return $ this ->consumer ->offsetsForTimes ($ topicPartitions , $ timeoutMs );
163165 }
164166
165167 /**
166168 * Queries the broker for the first offset of a given topic and partition
167169 *
168170 * @param string $topic
169171 * @param integer $partition
170- * @param integer $timeout
172+ * @param integer $timeoutMs
171173 * @return integer
172174 */
173- public function getFirstOffsetForTopicPartition (string $ topic , int $ partition , int $ timeout ): int
175+ public function getFirstOffsetForTopicPartition (string $ topic , int $ partition , int $ timeoutMs ): int
174176 {
175177 $ lowOffset = 0 ;
176178 $ highOffset = 0 ;
177179
178- $ this ->consumer ->queryWatermarkOffsets ($ topic , $ partition , $ lowOffset , $ highOffset , $ timeout );
180+ $ this ->consumer ->queryWatermarkOffsets ($ topic , $ partition , $ lowOffset , $ highOffset , $ timeoutMs );
179181
180182 return $ lowOffset ;
181183 }
@@ -185,15 +187,15 @@ public function getFirstOffsetForTopicPartition(string $topic, int $partition, i
185187 *
186188 * @param string $topic
187189 * @param integer $partition
188- * @param integer $timeout
190+ * @param integer $timeoutMs
189191 * @return integer
190192 */
191- public function getLastOffsetForTopicPartition (string $ topic , int $ partition , int $ timeout ): int
193+ public function getLastOffsetForTopicPartition (string $ topic , int $ partition , int $ timeoutMs ): int
192194 {
193195 $ lowOffset = 0 ;
194196 $ highOffset = 0 ;
195197
196- $ this ->consumer ->queryWatermarkOffsets ($ topic , $ partition , $ lowOffset , $ highOffset , $ timeout );
198+ $ this ->consumer ->queryWatermarkOffsets ($ topic , $ partition , $ lowOffset , $ highOffset , $ timeoutMs );
197199
198200 return $ highOffset ;
199201 }
@@ -216,8 +218,8 @@ protected function getConsumerMessage(RdKafkaMessage $message): KafkaConsumerMes
216218 }
217219
218220 /**
219- * @param integer $timeout
221+ * @param integer $timeoutMs
220222 * @return null|RdKafkaMessage
221223 */
222- abstract protected function kafkaConsume (int $ timeout ): ?RdKafkaMessage ;
224+ abstract protected function kafkaConsume (int $ timeoutMs ): ?RdKafkaMessage ;
223225}
0 commit comments