com.codingapi.tx.springcloud.feign.TransactionRestTemplateInterceptor Maven / Gradle / Ivy
package com.codingapi.tx.springcloud.feign;
import com.codingapi.tx.aop.bean.TxTransactionLocal;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Created by lorne on 2017/6/26.
*/
public class TransactionRestTemplateInterceptor implements RequestInterceptor {
private Logger logger = LoggerFactory.getLogger(TransactionRestTemplateInterceptor.class);
@Override
public void apply(RequestTemplate requestTemplate) {
TxTransactionLocal txTransactionLocal = TxTransactionLocal.current();
String groupId = txTransactionLocal == null ? null : txTransactionLocal.getGroupId();
logger.info("LCN-SpringCloud TxGroup info -> groupId:"+groupId);
if (txTransactionLocal != null) {
requestTemplate.header("tx-group", groupId);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy