优化
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package com.baiyue.common.web;
|
||||
|
||||
import feign.Request;
|
||||
import feign.Capability;
|
||||
import feign.Retryer;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/** Explicitly selected by reliable event clients; never registered as a global configuration. */
|
||||
public class EventDeliveryFeignConfiguration {
|
||||
@Bean
|
||||
public DeliveryTransportCapability eventDeliveryCapability(
|
||||
@Value("${baiyue.event-delivery.connect-timeout-ms:3000}") int connectTimeout,
|
||||
@Value("${baiyue.event-delivery.read-timeout-ms:15000}") int readTimeout,
|
||||
@Value("${baiyue.event-delivery.lease-seconds:60}") long leaseSeconds) {
|
||||
if (connectTimeout < 1 || readTimeout < 1 || leaseSeconds < 1
|
||||
|| leaseSeconds > Integer.MAX_VALUE || (long) connectTimeout + readTimeout >= leaseSeconds * 1000) {
|
||||
throw new IllegalArgumentException("Event delivery timeouts must fit inside the lease");
|
||||
}
|
||||
return new DeliveryTransportCapability(new Request.Options(connectTimeout, TimeUnit.MILLISECONDS, readTimeout, TimeUnit.MILLISECONDS, false));
|
||||
}
|
||||
/** Applied at Feign build time after global/client properties, without changing other clients. */
|
||||
public static final class DeliveryTransportCapability implements Capability {
|
||||
private final Request.Options options;
|
||||
public DeliveryTransportCapability(Request.Options options) { this.options = options; }
|
||||
@Override public Request.Options enrich(Request.Options ignored) { return options; }
|
||||
@Override public Retryer enrich(Retryer ignored) {
|
||||
// The persisted Outbox owns the retry budget.
|
||||
return Retryer.NEVER_RETRY;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user