File tree 7 files changed +105
-3
lines changed
7 files changed +105
-3
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ test: pcov-disable
22
22
23
23
static-analysis : pcov-disable
24
24
mkdir -p build/logs/phpstan
25
- ${PHPSTAN} analyse --no-progress --memory-limit=64
25
+ ${PHPSTAN} analyse --no-progress --memory-limit=128M
26
26
27
27
update-dependencies :
28
28
composer update
Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ final class KafkaConsumerBuilder implements KafkaConsumerBuilderInterface
51
51
/**
52
52
* @var callable
53
53
*/
54
- private $ consumeCallback ;
54
+ private $ oauthBearerCallback ;
55
55
56
56
/**
57
57
* @var callable
@@ -228,6 +228,20 @@ public function withOffsetCommitCallback(callable $offsetCommitCallback): KafkaC
228
228
return $ that ;
229
229
}
230
230
231
+ /**
232
+ * Set callback that is being called on offset commits
233
+ *
234
+ * @param callable $oauthBearerCallback
235
+ * @return KafkaConsumerBuilderInterface
236
+ */
237
+ public function withOAuthBearerTokenRefreshCallback (callable $ oauthBearerCallback ): KafkaConsumerBuilderInterface
238
+ {
239
+ $ that = clone $ this ;
240
+ $ that ->oauthBearerCallback = $ oauthBearerCallback ;
241
+
242
+ return $ that ;
243
+ }
244
+
231
245
/**
232
246
* Lets you set a custom decoder for the consumed message
233
247
*
@@ -292,5 +306,9 @@ private function registerCallbacks(KafkaConfiguration $conf): void
292
306
if (null !== $ this ->offsetCommitCallback ) {
293
307
$ conf ->setOffsetCommitCb ($ this ->offsetCommitCallback );
294
308
}
309
+
310
+ if (null !== $ this ->oauthBearerCallback ) {
311
+ $ conf ->setOAuthBearerTokenRefreshCb ($ this ->oauthBearerCallback );
312
+ }
295
313
}
296
314
}
Original file line number Diff line number Diff line change @@ -105,7 +105,15 @@ public function withDecoder(DecoderInterface $decoder): self;
105
105
* @param callable $logCallback
106
106
* @return KafkaConsumerBuilderInterface
107
107
*/
108
- public function withLogCallback (callable $ logCallback ): KafkaConsumerBuilderInterface ;
108
+ public function withLogCallback (callable $ logCallback ): self ;
109
+
110
+ /**
111
+ * Set callback that is being called on offset commits
112
+ *
113
+ * @param callable $oauthBearerCallback
114
+ * @return KafkaConsumerBuilderInterface
115
+ */
116
+ public function withOAuthBearerTokenRefreshCallback (callable $ oauthBearerCallback ): self ;
109
117
110
118
/**
111
119
* Returns your consumer instance
Original file line number Diff line number Diff line change @@ -39,6 +39,11 @@ final class KafkaProducerBuilder implements KafkaProducerBuilderInterface
39
39
*/
40
40
private $ logCallback ;
41
41
42
+ /**
43
+ * @var callable
44
+ */
45
+ private $ oauthBearerCallback ;
46
+
42
47
/**
43
48
* @var EncoderInterface
44
49
*/
@@ -131,6 +136,19 @@ public function withLogCallback(callable $logCallback): KafkaProducerBuilderInte
131
136
return $ this ;
132
137
}
133
138
139
+ /**
140
+ * Callback for OAuth Bearer Token refresh
141
+ *
142
+ * @param callable $oauthBearerCallback
143
+ * @return KafkaProducerBuilderInterface
144
+ */
145
+ public function withOAuthBearerTokenRefreshCallback (callable $ oauthBearerCallback ): KafkaProducerBuilderInterface
146
+ {
147
+ $ this ->oauthBearerCallback = $ oauthBearerCallback ;
148
+
149
+ return $ this ;
150
+ }
151
+
134
152
/**
135
153
* Lets you set a custom encoder for produce message
136
154
*
@@ -188,5 +206,9 @@ private function registerCallbacks(KafkaConfiguration $conf): void
188
206
if (null !== $ this ->logCallback ) {
189
207
$ conf ->setLogCb ($ this ->logCallback );
190
208
}
209
+
210
+ if (null !== $ this ->oauthBearerCallback ) {
211
+ $ conf ->setOAuthBearerTokenRefreshCb ($ this ->oauthBearerCallback );
212
+ }
191
213
}
192
214
}
Original file line number Diff line number Diff line change @@ -50,6 +50,14 @@ public function withErrorCallback(callable $errorCallback): self;
50
50
*/
51
51
public function withLogCallback (callable $ logCallback ): self ;
52
52
53
+ /**
54
+ * Callback for OAuth Bearer Token refresh
55
+ *
56
+ * @param callable $oauthBearerCallback
57
+ * @return KafkaProducerBuilderInterface
58
+ */
59
+ public function withOAuthBearerTokenRefreshCallback (callable $ oauthBearerCallback ): self ;
60
+
53
61
/**
54
62
* Lets you set a custom encoder for produce message
55
63
*
Original file line number Diff line number Diff line change @@ -203,6 +203,33 @@ public function testSetRebalanceCallback(): void
203
203
self ::assertArrayHasKey ('rebalance_cb ' , $ conf );
204
204
}
205
205
206
+ /**
207
+ * @return void
208
+ * @throws \ReflectionException
209
+ */
210
+ public function testSetOAuthBearerTokenRefreshCallback (): void
211
+ {
212
+ $ callback = function () {
213
+ // Anonymous test method, no logic required
214
+ };
215
+
216
+ $ clone = $ this ->kafkaConsumerBuilder ->withOAuthBearerTokenRefreshCallback ($ callback );
217
+
218
+ $ reflectionProperty = new \ReflectionProperty ($ clone , 'oauthBearerCallback ' );
219
+ $ reflectionProperty ->setAccessible (true );
220
+
221
+ self ::assertSame ($ callback , $ reflectionProperty ->getValue ($ clone ));
222
+ self ::assertNotSame ($ clone , $ this ->kafkaConsumerBuilder );
223
+
224
+ $ consumer = $ clone
225
+ ->withAdditionalBroker ('localhost ' )
226
+ ->withSubscription ('test ' )
227
+ ->withOAuthBearerTokenRefreshCallback ($ callback )
228
+ ->build ();
229
+ $ conf = $ consumer ->getConfiguration ();
230
+ self ::assertArrayHasKey ('oauthbearer_token_refresh_cb ' , $ conf );
231
+ }
232
+
206
233
/**
207
234
* @return void
208
235
* @throws \ReflectionException
Original file line number Diff line number Diff line change @@ -108,6 +108,24 @@ public function testSetErrorCallback(): void
108
108
self ::assertSame ($ callback , $ reflectionProperty ->getValue ($ clone ));
109
109
}
110
110
111
+ /**
112
+ * @return void
113
+ * @throws \ReflectionException
114
+ */
115
+ public function testSetOAuthBearerTokenRefreshCallback (): void
116
+ {
117
+ $ callback = function () {
118
+ // Anonymous test method, no logic required
119
+ };
120
+
121
+ $ clone = $ this ->kafkaProducerBuilder ->withOAuthBearerTokenRefreshCallback ($ callback );
122
+
123
+ $ reflectionProperty = new \ReflectionProperty ($ clone , 'oauthBearerCallback ' );
124
+ $ reflectionProperty ->setAccessible (true );
125
+
126
+ self ::assertSame ($ callback , $ reflectionProperty ->getValue ($ clone ));
127
+ }
128
+
111
129
/**
112
130
* @throws KafkaProducerException
113
131
*/
@@ -132,6 +150,7 @@ public function testBuild(): void
132
150
->withDeliveryReportCallback ($ callback )
133
151
->withErrorCallback ($ callback )
134
152
->withLogCallback ($ callback )
153
+ ->withOAuthBearerTokenRefreshCallback ($ callback )
135
154
->build ();
136
155
137
156
self ::assertInstanceOf (KafkaProducerInterface::class, $ producer );
You can’t perform that action at this time.
0 commit comments