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

请问如何根据消息体内容选择服务调用呢? #793

Closed
HKMV opened this issue Nov 27, 2022 · 4 comments
Closed

请问如何根据消息体内容选择服务调用呢? #793

HKMV opened this issue Nov 27, 2022 · 4 comments
Labels
question A question about this library or its usage

Comments

@HKMV
Copy link

HKMV commented Nov 27, 2022

老师您好,我现在有个场景是需要根据调用时参数对象值,进行选择要调用的服务。

我的想法是自己写一个自定义选择策略,但是琢磨了半天,没找到怎么从选择方法中获取参数对象,请问有什么方法可以取到吗?

或者您有更好的方案吗?

期待您的指点。

@HKMV HKMV added the question A question about this library or its usage label Nov 27, 2022
@ST-DDT
Copy link
Collaborator

ST-DDT commented Nov 27, 2022

English


Do you have a fixed set of targets (prod, dev, stage) that you have to switch between or is it generic?

Currently there is no easy way to do that only:

  • inject the channel factory,
  • create/get a channel based on the given parameter
  • and create a stub for it

But, then there is no injection support for the stub/channel.

I plan to create a injection factory: https://github.com/yidongnan/grpc-spring-boot-starter/issues/741#issuecomment-1247148603

Then you can do:

  • inject the GrpcClientInjector
  • call grpcClientInjector.get("targetName", Stub.class)

Does this answer your question?

@HKMV
Copy link
Author

HKMV commented Nov 28, 2022

English


Do you have a fixed set of targets (prod, dev, stage) that you have to switch between or is it generic?

Currently there is no easy way to do that only:

  • inject the channel factory,
  • create/get a channel based on the given parameter
  • and create a stub for it

But, then there is no injection support for the stub/channel.

I plan to create a injection factory: https://github.com/yidongnan/grpc-spring-boot-starter/issues/741#issuecomment-1247148603

Then you can do:

  • inject the GrpcClientInjector
  • call grpcClientInjector.get("targetName", Stub.class)

Does this answer your question?

不是固定的,调用的服务端是会变化的,需要在监听到服务变化时,更新要调用的地址;感谢您提供的思路我去测试一下。

@HKMV
Copy link
Author

HKMV commented Dec 2, 2022

暂时已通过自定义DiscoveryClientResolverFactory实现,期待2.15.0版本的GrpcClientInjector实现,使用GrpcClientInjector应该可以更好的解决我的问题。

@ST-DDT
Copy link
Collaborator

ST-DDT commented Dec 2, 2022

Thanks for your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A question about this library or its usage
Projects
None yet
Development

No branches or pull requests

2 participants