MqMessageDataVersionManager.java 815 Bytes
package com.yoho.datasync.producer.canal.common;

import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;

@Component
public class MqMessageDataVersionManager {

    private ConcurrentHashMap<String, AtomicLong> tableDataVersionMap = new ConcurrentHashMap<>();

    /**
     * 为dbName.tableName生成版本号
     * @param dbName
     * @param tableName
     * @return
     */
    public long genTableDataVersion(String dbName, String tableName){
        long currentTimeMillis = System.currentTimeMillis();
        String tableKey = dbName + "." + tableName;
        AtomicLong version = tableDataVersionMap.computeIfAbsent(tableKey, k->new AtomicLong(currentTimeMillis));
        return version.incrementAndGet();
    }
}