Decoupling Spring MVC from HTTPServlet

I worked with Spring for a while to understand that not all incoming requests that I receive in my application are based on HTTP. Some queries are email-based and need email-based responses, others are socket-based (receive notifications when a value changes in my NOSQL store). All of them, although they use more or less the same MVC infrastructure.

So I thought that perhaps back-archiving the application to remove the connection between the controllers and the HTTP infrastructure would help.

The dispatcher should no longer access the controller’s methods, but rather retrieve the request parameters and use them to create an abstract message (or event), which is then placed on the message bus. On the other hand, each controller will sign its actions (instances of the Action class - implementation of the Command template) for different events.

Since I'm new to integrating Spring, JMS, etc., I have no idea which messaging technology to choose. In addition, I am sure that such an architecture has already been developed. Maybe I can't even be on the right track.

I accept all kinds of suggestions on how to proceed.

+6
source share
1 answer

You are right that a messaging solution with a little help from some integration patterns is the “right” way.

Are you saying that emails and some NoSQL database already get into your controller? This means that there is some level of translation between these systems and your controllers. With Spring integration, you would use the Mail Reception Channel Adapter to process incoming email messages and TCP and UDP support for NoSQL notifications. Spring MVCs can still be used for "true" web requests by accessing the message feed below it.

Each channel adapter has a unique set of transformers for converting the adaptive message adapter into a canonical format. At the end, messages from each endpoint will be routed to the same message channel .

So your example is perfect for ESB-like solutions. Also check out Mule ESB , which is even more mature and powerful.

+5
source

Source: https://habr.com/ru/post/904028/


All Articles