Commit 772c00a
authored
Allow setting a custom EventListener in ApiClientBuilder (#1621)
Hi Team,
Thank you for your great work on developing the SDK for LINE Bot in
Java.
I noticed that you have already implemented `HttpInterceptor` interface,
which allows the SDK users to add a custom `Interceptor` to the
underlying OKHttpClient.
(https://square.github.io/okhttp/features/interceptors/) With this
support, we can easily add our own custom `HttpInterceptor` or reuse
existing `OKHttpClient's Interceptor` by wrapping it accordingly.
I was wondering if it would be possible to also allow setting a custom
`EventListener` on the underlying
`OkHttpClient`.(https://square.github.io/okhttp/features/events/)
Based on our discussion, rather than introducing a new interface like
HttpInterceptor, it seems preferable to expose the EventListener
directly, as it is easier for users to use and also leads to a simpler
implementation.
This pull request introduces a proof of concept for adding such support.
The implementation closely mirrors that of the custom interceptor
mechanism , although `EventListener` is a bit more involved than
`Interceptor`.
With this feature, SDK users will be able to set a custom EventListener
to suit their needs when creating the API client. For Example:
```java
MessagingApiClient.builder("your access token")
.apiEndPoint(URI.create(lineApiUrl))
.addInterceptor(new MyHttpInterceptor)
.setEventListener(new MyEventListener())
.build();
```
My use case for `OKHttpClient's EventListener`.
In our system, we also use `OkHttpClient` along with `Retrofit`. To
enhance the observability of API calls in our system, we leverage the
`OkHttpMetricsEventListener` provided by `Micrometer` to record HTTP
request metrics.
(https://docs.micrometer.io/micrometer/reference/reference/okhttpclient.html).
We would like to attach this metrics to LINE Bot SDK's client by
adapting a `Micrometer`'s `OkHttpMetricsEventListener`, like this:
```java
MessagingApiClient.builder("your access token")
.apiEndPoint(URI.create(lineApiUrl))
.addInterceptor(new MyHttpInterceptor)
.setEventListener(new OkHttpMetricsEventListener())
.build();
```
Thank you for considering this suggestion. I look forward to your
feedback!1 parent 03e345f commit 772c00a
1 file changed
Lines changed: 18 additions & 0 deletions
File tree
- clients/line-bot-client-base/src/main/java/com/linecorp/bot/client/base
Lines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| |||
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
92 | 100 | | |
93 | 101 | | |
94 | 102 | | |
| |||
141 | 149 | | |
142 | 150 | | |
143 | 151 | | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
144 | 157 | | |
145 | 158 | | |
146 | 159 | | |
| |||
230 | 243 | | |
231 | 244 | | |
232 | 245 | | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
233 | 250 | | |
234 | 251 | | |
235 | 252 | | |
| |||
262 | 279 | | |
263 | 280 | | |
264 | 281 | | |
| 282 | + | |
265 | 283 | | |
266 | 284 | | |
267 | 285 | | |
| |||
0 commit comments