Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of sequential consumption of ActiveMq

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to solve the sequential consumption problem of ActiveMq". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to solve the sequential consumption problem of ActiveMq".

The ABA problem of business

Business 1 fetches data A from the cache, business B fetches data A from the cache and turns An into B, and then B into A. Business 1 finds that the data is still A Magi An at this time, although the business operation is successful, but it doesn't mean the whole process is all right. In addition, although the results of the sequencing problem are likely to be consistent, it does not mean that the other data affected in the process is fine.

As shown in the figure, six pieces of the same data are stored in the library at the same time, but strict logic allows only one item of the same data in the library. If other businesses query the relevant data at this time, multiple results will be returned.

Imagine solution one: atomic counting

Solution: before each piece of data is operated, determine whether the operation data is the same twice, that is, the kv of redis is the same. If it is the same, mark incr for key at this time, step 1, when mq is consumed, compare the step value of this key from redis with the step value passed in. In theory, you only need to record that you want to use kv and the maximum step is worth the operation.

Long incr = redisService.incr (key,1); Object o = redisService.getIncrValue ("key"); if (o.toString (). Equals (vo.getIncr () {/ / business logic}

Result test: this problem also occurs. At first, it is thought that the current page is the same user's operation on the same information, and it will not appear or point out such high concurrency, then regardless of the malicious attack on the interface, what is the result of using jemeter to dynamically pass parameters?

Each parameter input parameter reads the file value, so that each result is a different operation, or two machines operate on the same information for the same account, which will inevitably lead to the problem of inconsistent results caused by network delay.

Imagine solution 2: distributed locks

Solution: lock the current operation and ensure that the same lock is used as the same lock for business processing, and the messages are grouped in cluster mode. the specific scheme is not mature and redisson processing is introduced, but it is also doubtful that the cost and performance of distributed locks are introduced to ensure sequency, and the ideal results are not achieved.

}} Thank you for your reading. The above is the content of "how to solve the problem of sequential consumption of ActiveMq". After the study of this article, I believe you have a deeper understanding of how to solve the problem of sequential consumption of ActiveMq, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report