Skip to content

Conversation

@artembilan
Copy link
Member

The @EventListener from Spring Framework is a good tool for POJO configuration to subscribe to events from an ApplicationContext. The @Publisher is an AOP tool to publish a Message from POJO method call.

  • Add a test and docs to demonstrate how the @Publisher can be used together with an @EventListener

@artembilan artembilan added this to the 6.1.0 milestone Apr 26, 2023
The `@EventListener` from Spring Framework is a good tool for POJO configuration
to subscribe to events from an `ApplicationContext`.
The `@Publisher` is an AOP tool to publish a `Message` from POJO method call.

* Add a test and docs to demonstrate how the `@Publisher` can be used together with an `@EventListener`
@artembilan artembilan force-pushed the publisher_with_events branch from b2c8649 to 8452802 Compare April 26, 2023 16:49
@artembilan artembilan requested a review from garyrussell May 1, 2023 20:38
Copy link
Contributor

@garyrussell garyrussell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @RabbitListener one looks a bit awkward too.

What drove you to create this PR?

}

@EventListener
@Publisher("eventFromPublisher")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this would work, do we really want to promote it? An ApplicationEventListeningMessageProducer is a much simpler approach.

@artembilan
Copy link
Member Author

What drove you to create this PR?

Yeah... When I asked end-user to catch an application event and publish it into a channel it turned out to not be so smooth to digest.
Their first question was: why do we need extra dependency for events?
Another one that ApplicationEventListeningMessageProducer is a bit long name.
Plus eventTypes is a setter, so it leads to more code lines, then just couple annotations on a POJO method.
Plus method signature dictates type of the event to consume and body result is naturally a message to produce.

Right, with @RabbitListener it is a bit awkward, but at least we it covered in docs if someone comes to us with the question that they know this annotation, but would like to produce to the channel without code, but rather annotation style.

Another thought (but that's for other day contribution) is to have something like IntegrationFlowBuilder fromQueue() in the Amqp factory to avoid extra codding for IntegrationFlow.from(Amqp.).
Something similar for events - fromEvent(Class<?>... eventTypes).

Plus it might be great to look into sensible default beans for something like ConnectionFactory like we do for container factory in the @RabbitListener.
There idea is to come up with some hook which would let end-users to end up with a solution with Spring Integration faster than it is now like they claim to have it with just two annotations for @RabbitListener.

@garyrussell garyrussell merged commit 59e676a into spring-projects:main May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants