Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event listener filenames #1478

Open
sldblog opened this issue Feb 25, 2023 · 0 comments
Open

Event listener filenames #1478

sldblog opened this issue Feb 25, 2023 · 0 comments

Comments

@sldblog
Copy link
Contributor

sldblog commented Feb 25, 2023

Short problem statement; why is this a problem?

We have a few strategies to name our listeners. We should explicitly pick one or guide when to pick one or the other.

The typical "find" pattern is "what happens after {event}", so naming should probably support that use case.

Link to different approaches

  1. One file per multiple listeners listening to the same event; the file is named after the event:

    @Service
    class ReferralConcludedListener(
    private val snsPublisher: SNSPublisher,
    ) : ApplicationListener<ReferralConcludedEvent>, SNSService {

    @Service
    class ReferralConcludedIntegrationListener(
    @Value("\${interventions-ui.baseurl}") private val interventionsUIBaseURL: String,
    @Value("\${interventions-ui.locations.probation-practitioner.end-of-service-report}") private val ppEndOfServiceReportLocation: String,
    @Value("\${community-api.locations.notification-request}") private val communityAPINotificationLocation: String,
    @Value("\${community-api.integration-context}") private val integrationContext: String,
    private val communityAPIClient: CommunityAPIClient,
    ) : ApplicationListener<ReferralConcludedEvent>, CommunityAPIService {

  2. One file per listener; the file is named after what it is doing:

    @Service
    class ReferralMetricsListener(
    val registry: MeterRegistry,
    val repository: ReferralRepository,
    ) : ApplicationListener<ReferralEvent> {

  3. One huge service file, with several @Service classes for doing similar things; the file is named after the "similar thing":

    @Service
    class SNSActionPlanService(
    private val snsPublisher: SNSPublisher,
    ) : ApplicationListener<ActionPlanEvent>, SNSService {

    @Service
    class SNSReferralService(
    private val snsPublisher: SNSPublisher,
    ) : ApplicationListener<ReferralEvent>, SNSService {

    @Service
    class SNSActionPlanAppointmentService(
    private val snsPublisher: SNSPublisher,
    ) : ApplicationListener<ActionPlanAppointmentEvent>, SNSService {

Do you have a proposed solution? Why?

Looking back, working with SNSService.kt was weird. Changes in events rippled over to several listener files.

Working with enums within the events probably does not help, as switches would start adding new warnings for not covering all cases or default to not doing anything. Using ReferralSentEvent would be better than ReferralEvent(type=SENT, ...).

In general, though, we should pick one and stick to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant