Graceful publishing

Updated at:

Spring Cloud SOFA provides a graceful publishing feature. This feature registers services only after the application passes its health check. If you enable the prefetch subscription feature, which is enabled by default, the success of the prefetch subscription is also included in the health check. This ensures that the application registers with the service registry only after all required services are successfully subscribed.

The graceful publishing feature is enabled by default, and no configuration is required to use it. The Spring Cloud SOFA health check integrates the native health check feature of Spring Boot. It also extends a new interface to check its own startup logic, such as prefetch subscriptions. You can extend the Spring Cloud SOFA health check interface to add your own check logic. This ensures that services are registered only when the application is ready, which improves service reliability.

For more information about health checks in Spring Cloud SOFA, see Health check (Spring Cloud SOFA Health).

Configure prefetch subscription checks

Because subscriptions to the SOFA service registry are completely asynchronous, Spring Cloud SOFA uses polling to check if all prefetch subscriptions are successful. By default, it retries 20 times with a 1000 ms interval between each check. To subscribe to many services, this configuration might not allow enough time for all subscriptions to succeed. This can cause the application to fail to start. You can extend the waiting time by configuring the following parameters in the application.properties file.

Configuration item

Description

Default value

spring.cloud.sofa.discovery.health-check-retry-count

Count of prefetch subscription checks

20

spring.cloud.sofa.discovery.health-check-retry-interval

Check Interval for Prefetch Subscriptions (milliseconds)

1000

Disable graceful publishing

If you do not need the graceful publishing feature or do not want to use Spring Cloud SOFA to implement it, you can disable the health check before registration. To do this, set the value of spring.cloud.sofa.discovery.register-after-health-check to false in the application.properties file. After this feature is disabled, the service publishing logic reverts to the native Spring Cloud logic, and the service is registered after the web server starts successfully.

spring.cloud.sofa.discovery.register-after-health-check=false

If you do not want to disable the health check but want service registration to proceed even if the health check fails, you can set the value of spring.cloud.sofa.discovery.health-check-strict-check to false.

spring.cloud.sofa.discovery.health-check-strict-check=false