Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何在某次调用中指定服务提供者的 Instence #4567

Open
nogeek-cn opened this issue Oct 24, 2024 · 2 comments
Open

如何在某次调用中指定服务提供者的 Instence #4567

nogeek-cn opened this issue Oct 24, 2024 · 2 comments

Comments

@nogeek-cn
Copy link

我想请教一个问题
服务提供者 地址有一个 List,这个我有办法拿到

我希望,我本次调用,我自己指定调用其中的一个 Instence

问,如何指定???

@liubao68
Copy link
Contributor

可以看看 Endpoint参数

@nogeek-cn
Copy link
Author

文档地址不对

https://servicecomb.apache.org/references/java-chassis/zh_CN/general-development/context.html#context-discoverytree

应该是这个:
案例: 使用 Context 和 DiscoveryTree 实现轮询调用一个微服务的所有实例

  interface DateTimeSchemaWithContextInf {
    Date getDate(InvocationContext context, Date date);
  }

  @RpcReference(microserviceName = "springmvc", schemaId = "DateTimeSchema")
  private DateTimeSchemaWithContextInf dateTimeSchemaWithContextInf;

  // code slip
  for (String endpoint : enpoints) {
    InvocationContext invocationContext = new InvocationContext();
    invocationContext.addLocalContext(LoadbalanceHandler.SERVICECOMB_SERVER_ENDPOINT, parseEndpoint(endpoint));
    Date date = new Date();
    TestMgr.check(date.getTime(), dateTimeSchemaWithContextInf.getDate(invocationContext, date).getTime());
  }

  // code slip
  private Endpoint parseEndpoint(String endpointUri) throws Exception {
    URI formatUri = new URI(endpointUri);
    Transport transport = SCBEngine.getInstance().getTransportManager().findTransport(formatUri.getScheme());
    return new Endpoint(transport, endpointUri);
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants