Distributed caching practical solutions Solutions to Common Problems

Vernacular to explain the distributed cache concurrency conflict problems and their solutions: zk Distributed Lock

I. Background

If you prefer to watch video tutorials, video tutorials can see this headline numbers released, absolutely vernacular, hands-on experience with you during the presentation of the entire conflict and solutions: two ways, randomly selected  practical exercise based caching architecture of distributed zk lock solve the distributed cache concurrency conflicts

1, the source schema:

2, distributed cache concurrency conflicts

Second, the project to integrate

1, ad serving system

** Features: ** source for the media advertising services

  • Get ad from the local cache
  • Get ad from redis cache
  • Get ad from db, and update the cache to redis

2 cache service system

  • News monitoring, real-time incremental update cache redis
  • The timing of the whole amount of cache update redis

3, ad management system

  • Additions and deletions to change search advertising
  • Send advertising messages to change mq

Three, rabbitmq message repeated Solutions

1. What causes duplicate messages it?

When using the publisher confirm producer mechanism, sending the message waits for a confirmation RabbitMQ return, this time off the network, the producer capture abnormal case, to ensure reliability of the message and choose to resend, so there are two RabbitMQ the same message. In this way, when consumer spending, will be repeated consumption, especially in the trading system / recharge system / bank transfer system ......, this problem is big.

2. Solution

Here introduce into the idea of ​​simply under the treatment program, we will be back when the distributed transaction, and then details the reliability of this one

  • For each message delivered by producers, both with a unique UUID
  • Consumers repeatability through this unique UUID UUID to verify the message:
    • Producer: key twice sent must be consistent (so before sending the key must be persistent)
    • Unique key may be stored in the distributed cache, such as: redis, you can set a cache time
public class AdMessage {

    /** * 操作类型:1为新增,2是修改 */ private int operation; /** * 主键字段,值为具体的ID值 */ private Long id; /** * 消息的唯一key:用于消息去重 */ private String uuidKey; /** * 广告信息: */ private String content; } 

Fourth, the practical exercise based zk Distributed Lock solve the distributed cache concurrency conflicts

Download Code: https://gitee.com/jikeh/JiKeHCN-RELEASE.git

Project name: Advertising services system: spring-boot-ad-service caching service system: spring-boot-cache ad management system: spring-boot-ad

1, zk distributed lock

  • Native zookeeper achieve Distributed Lock
  • Use curator framework to achieve zookeeper distributed lock

2, ad serving systems zk Distributed Lock Application

3, ad cache system application zk Distributed Lock

4, practical exercise

1) simulate concurrent conflict scenarios

Guess you like

Origin www.cnblogs.com/java188/p/12123658.html