com.feingto.cloud.domain.api.BaseHystrix Maven / Gradle / Ivy
package com.feingto.cloud.domain.api;
import com.feingto.cloud.constants.HystrixConstants;
import com.feingto.cloud.kit.json.JSON;
import com.netflix.hystrix.HystrixCommandProperties;
import lombok.Data;
import lombok.experimental.Accessors;
import org.hibernate.annotations.ColumnDefault;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* 熔断配置
*
* @author longfei
*/
@Data
@Accessors(chain = true)
@MappedSuperclass
public class BaseHystrix implements Serializable {
private static final long serialVersionUID = 609217708661782567L;
@Transient
protected String id;
/**
* 失败率达到多少百分比后熔断
*/
@Column
protected Integer circuitBreakerErrorThresholdPercentage = HystrixConstants.circuitBreakerErrorThresholdPercentage;
/**
* 熔断触发的最小个数/10s
*/
@Column
protected Integer circuitBreakerRequestVolumeThreshold = HystrixConstants.circuitBreakerRequestVolumeThreshold;
/**
* 熔断多少秒后去尝试请求
*/
@Column
protected Integer circuitBreakerSleepWindowInMilliseconds = HystrixConstants.circuitBreakerSleepWindowInMilliseconds;
/**
* 使用命令调用隔离方式, 默认: 采用线程隔离
*/
@Enumerated(EnumType.STRING)
@Column(length = 16)
protected HystrixCommandProperties.ExecutionIsolationStrategy executionIsolationStrategy = HystrixCommandProperties.ExecutionIsolationStrategy.THREAD;
/**
* 线程池基本大小
*/
@Column
protected Integer threadCoreSize = HystrixConstants.coreSize;
/**
* 线程池最大线程数
*/
@Column
protected Integer threadMaximumSize = HystrixConstants.maximumSize;
/**
* 使用信号量隔离时命令调用最大的并发数
*/
@Column
protected Integer executionIsolationSemaphoreMaxConcurrentRequests = HystrixConstants.executionIsolationSemaphoreMaxConcurrentRequests;
/**
* 是否开启fallback降级策略
*/
@Column
@ColumnDefault("false")
protected boolean fallbackEnabled = HystrixConstants.fallbackEnabled;
/**
* 命令fallback(降级)调用最大的并发数
*/
@Column
protected Integer fallbackIsolationSemaphoreMaxConcurrentRequests = HystrixConstants.fallbackIsolationSemaphoreMaxConcurrentRequests;
/**
* 调用超时时间
*/
@Column
protected Integer executionTimeoutInMilliseconds = HystrixConstants.executionTimeoutInMilliseconds;
@Transient
protected List baseApis = new ArrayList<>();
public Message toMessage() {
return MessageBuilder.withPayload(JSON.obj2json(this)).build();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy