Hello Gojek Courier team,
I hope this message finds you well. I'm reaching out to suggest a feature enhancement that could streamline the handling of multi-topic subscriptions within the service interface of Gojek Courier.
Current Situation:
Currently, in order to subscribe to multiple topics using the @SubscribeMultiple
annotation, we are required to create separate @Receive
annotations for each topic. While this approach works, it can lead to redundant code and reduced maintainability, especially when the response models for these topics are identical.
Proposal:
I'd like to propose the introduction of a "Global Listener" concept that would allow us to handle multiple topic subscriptions with consistent response models in a more concise and elegant manner.
Suggested Implementation:
-
Introduction of Global Listener Annotation: Add a new annotation, say @GlobalListener
, that can be placed at the service interface level to denote a method that will act as a global listener.
-
Reduced Redundancy with Shared Response Model: With this new annotation, the service interface method could be designed to listen to multiple topics using wildcard expressions or dynamic parameters, eliminating the need to define separate @Receive
annotations for each topic with the same response model.
-
Example:
@Service
interface CourierService {
@GlobalListener
@Receive
fun handleGlobalTopic(@TopicMap topics: List<String>) : Model
}
Benefits:
- Code Elegance: The service interface becomes more concise and easier to manage, as it can handle multiple topic subscriptions with a single method.
- Consistency: When topics share the same response model, there's no need to duplicate the
@Receive
annotations and response model declarations.
- Maintenance: Changes to the response model or subscription logic can be applied globally, minimizing the chances of errors due to manual code replication.
Additional Consideration:
The proposed "Global Listener" should be flexible enough to handle dynamic parameters or wildcards in topic patterns, ensuring it can cater to a wide range of use cases.
Conclusion:
I believe that implementing a "Global Listener" mechanism as described above could significantly enhance the efficiency and maintainability of the Gojek Courier service interface. It would streamline the process of subscribing to multiple topics with consistent response models, while also adhering to best practices for reducing redundancy in code.
Thank you for considering this feature request. I'm looking forward to your feedback and thoughts on this idea.
Best Regards,
M E Mohit