You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2021/08/31 02:52:59 UTC
[GitHub] [servicecomb-java-chassis] Nick-The-Uncharted edited a comment on issue #2534: 如果在第三方接口注册前调用第三方接口 则后续注册之后也无法调用 报错
Nick-The-Uncharted edited a comment 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
* @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
* @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: commits-unsubscribe@servicecomb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org