Nick-The-Uncharted commented on issue #2534:
URL: 
https://github.com/apache/servicecomb-java-chassis/issues/2534#issuecomment-908846270


   这样应该能大概率复现
   ```java
   import lombok.extern.slf4j.Slf4j;
   
   import org.apache.servicecomb.core.BootListener;
   import org.apache.servicecomb.provider.pojo.RpcReference;
   import org.springframework.beans.factory.InitializingBean;
   import org.springframework.scheduling.annotation.Scheduled;
   import org.springframework.stereotype.Component;
   import org.springframework.web.bind.annotation.GetMapping;
   import org.springframework.web.bind.annotation.RequestMapping;
   
   /**
    * 
用于持续注册调用org.apache.servicecomb.registry.consumer.MicroserviceManager#getOrCreateMicroserviceVersions
 
    *
    * @author h00430087
    * @since 2021-08-31
    */
   @Component
   @Slf4j
   public class EarlyConsumer implements BootListener {
       @RpcReference(microserviceName = "health", schemaId = "heartbeat")
       private HealthSchema healthSchema;
       @RequestMapping("/v1")
       public interface HealthSchema {
           @GetMapping(value = "/heartbeat")
           void heartbeat();
       }
   
       private volatile boolean stopped = false;
   
       @Scheduled(fixedRate = 100)
       public void loop() {
           if (stopped) {
               return;
           }
           LOGGER.info("calling service");
           try {
               healthSchema.heartbeat();
           } catch (Throwable e) {
               // ignore error
           }
       }
   
       @Override
       public void onAfterRegistry(BootEvent event) {
           stopped = true;
       }
   }
   ```
   
   ```java
   /**
    * 正常调用,没有EarlyConsumer肯定百分百成功
    *
    * @author h00430087
    * @since 2021-08-31
    */
   @Component
   @Slf4j
   public class NormalConsumer implements BootListener {
       @RpcReference(microserviceName = "health", schemaId = "heartbeat")
       private HealthSchema healthSchema;
       @RequestMapping("/v1")
       public interface HealthSchema {
           @GetMapping(value = "/heartbeat")
           void heartbeat();
       }
   
       @Override
       public void onAfterRegistry(BootListener.BootEvent event) {
           LOGGER.info("calling service after register");
           try {
               healthSchema.heartbeat();
               LOGGER.info("heartbeat succ");
           } catch (Throwable e) {
               LOGGER.error("exception occur when calling after register", e);
           }
       }
   
   
       @Override
       public int getOrder() {
           // 比ThirdServiceRegister晚
           return 0;
       }
   }
   ```
   
   ```
   @Component
   public class Register extends ThirdServiceWithInvokerRegister {
       public Register() {
           super("health");
           addSchema("heartbeat", NormalConsumer.HealthSchema.class);
       }
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to