Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2204

@async vs message queue difference

$
0
0

I have a spring boot project, deploying in two servers and using nginx. One method in the project will do:

  1. set some key-values in redis

  2. insert something in db

After 1, I want to do 2 in async way.

One solution is to let doDB() be a springboot @async method:

Class A {    public void ***() {        doRedis() // 1.set some key-values in redis        doDB() // 2.insert something in db    }}Class B {    @async    doDB()}

Another solution is to send message to MQ:

Class A {    public void ***() {        doRedis() // 1.set some key-values in redis        sendMessage()     }}Class B {    onMessage(){        doDB()    }}

If Class A and B are both in the spring boot project, just deploying this project in two servers. I think using @async is enough, there is no need to use MQ to achieve the async way because there is no difference between server one to do Class B doDB() and server two to do Class B doDB(). If class B is in another project, then using MQ is good because it's decoupling for project one doing redis work and project two doing db work.

Is it right? Thanks!


Viewing all articles
Browse latest Browse all 2204

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>