lujiajing1126 opened a new pull request #5879: URL: https://github.com/apache/skywalking/pull/5879
### Add an agent plugin to support Spring-Kafka 1.3.x - [x] Add a test case for the new plugin - [x] Add a component id in the [component-libraries.yml](https://github.com/apache/skywalking/blob/master/oap-server/server-bootstrap/src/main/resources/component-libraries.yml). Shared with `kafka`. - [x] Add a logo in [the UI repo](https://github.com/apache/skywalking-rocketbot-ui/tree/master/src/views/components/topology/assets). Shared with `kafka`. - [x] As a continuation of #5244 - [ ] Update the [`CHANGES` log](https://github.com/apache/skywalking/blob/master/CHANGES.md). Not yet be done. ### The current design of Spring-Kafka plugin The current `Spring-Kafka` plugin in skywalking is aimed at `Spring-Kafka 2.x+` in the sense that there is a `pollAndInvoke` method which is responsible for `poll` messages from Kafka and `invoke` the listeners defined by developers. And this method is provided from version 2.2.1 in order to improve the smell of the codes https://github.com/spring-projects/spring-kafka/pull/873 So the current plugin takes advantage of this refactor and enhances directly this `pollAndInvoke` method. But we still have to maintain many services which depend on Spring-Boot 1.5.x and thus `Spring-Kafka` 1.3.x according to [the official compatibility matrix](https://spring.io/projects/spring-kafka). ### The approach to versions below 2.2.x Below that specific version, we do not have `pollAndInvoke` method and this whole function is **inlined** into the `while`-loop of the main `run` method, thus seems not possible to make this enhancement. My approach is to enhance the `processSeeks` in the same inner class `ListenerConsumer`. The reason why we choose this aspect is, - this method is called at the very beginning of the loop (or equivalently the end of the loop), then we can inject(remove) our `Context` after(before) the method is executed. - this method is called and **only** called there, it is not used in other places, which represents precisely the beginning of the run loop. For completeness and safe reasons, we also enhance the whole `run()` method in order to remove the context after the loop finishes. The last thing is to distinguish the versions of `Spring-Kafka`. I use `org.springframework.kafka.listener.config.ContainerProperties` as the witness class for versions below `2.2.x`. This class is renamed as `org.springframework.kafka.listener.ContainerProperties` after `2.2.x`. So this plugin will not be applied for Spring-Kafka 2.2.x+. I have checked all versions up to `2.6.x`. So with this plugin, we can enhance the following `Spring-Kafka` versions, which are missing so far, - 1.3.x - 2.0.x - 2.1.x Theoretically, it can also work with 1.2.x, but that version is not recommended by the official Spring-Kafka team. Also with `Spring-Kafka` 1.2.x, you have to manually set Kafka version to those higher than `0.10`. Otherwise, the header API is missing. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
