All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aliyun.openservices.ons.api.exactlyonce.ExactlyOnceCheckSendbackHook Maven / Gradle / Ivy

There is a newer version: 1.9.3.Final
Show newest version
package com.aliyun.openservices.ons.api.exactlyonce;

import com.aliyun.openservices.shade.com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import com.aliyun.openservices.shade.com.alibaba.rocketmq.client.hook.CheckSendBackHook;
import com.aliyun.openservices.shade.com.alibaba.rocketmq.common.message.MessageExt;

import com.aliyun.openservices.ons.api.exactlyonce.aop.model.MQTxContext;
import com.aliyun.openservices.ons.api.exactlyonce.datasource.DataSourceConfig;
import com.aliyun.openservices.ons.api.exactlyonce.manager.util.DBAccessUtil;
import com.aliyun.openservices.ons.api.exactlyonce.manager.util.TxContextUtil;

/**
 * @author gongshi
 */
public class ExactlyOnceCheckSendbackHook implements CheckSendBackHook {
    private String consumerGroup;
    private DataSourceConfig config;

    public ExactlyOnceCheckSendbackHook(String consumerGroup, DataSourceConfig config) {
        this.consumerGroup = consumerGroup;
        this.config = config;
    }

    public DataSourceConfig getConfig() {
        return config;
    }

    public void setConfig(DataSourceConfig config) {
        this.config = config;
    }

    @Override
    public String hookName() {
        return "ExactlyOnceCheckSendbackHook";
    }

    @Override
    public boolean needSendBack(MessageExt msg, ConsumeConcurrentlyContext context) {
        if (consumerGroup == null || config == null) {
            return true;
        }
        MQTxContext txContext = new MQTxContext();
        txContext.setMessageId(TxContextUtil.buildInternalMsgId(msg, consumerGroup));
        txContext.setDataSourceConfig(config);
        return !DBAccessUtil.isRecordExist(txContext);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy