如何在 Spring 云中的微服务之间传递二进制数据?
How to pass binary data between microservices in Spring Cloud?
我想问一下。如何在 Spring 云中的微服务之间传递二进制数据?
我应该(可以)使用@FeignClient 还是@RibbonClient?应该如何?我已经读到 @FeignClient 没有处理这个问题还有什么? OkHttp?
提前致谢
Spring Cloud 集成了一些 http 客户端,就像您提到的那样。 Ribbon 有一些 non-http clients/transports built in,但我没用过,AFIAK,netflix 也不用。
您可以使用 Spring 云 LoadBalancerClient
interface directly。它使您可以访问主机和端口,然后您可以使用任何您想要的客户端。
public class MyClass {
@Autowired
private LoadBalancerClient loadBalancer;
public void doStuff() {
ServiceInstance instance = loadBalancer.choose("myService");
String host = instance.getHost();
int port = instance.getPort();
// ... do something with the host and port
}
}
我还与 OkHttp 进行了示例集成。
我想问一下。如何在 Spring 云中的微服务之间传递二进制数据?
我应该(可以)使用@FeignClient 还是@RibbonClient?应该如何?我已经读到 @FeignClient 没有处理这个问题还有什么? OkHttp?
提前致谢
Spring Cloud 集成了一些 http 客户端,就像您提到的那样。 Ribbon 有一些 non-http clients/transports built in,但我没用过,AFIAK,netflix 也不用。
您可以使用 Spring 云 LoadBalancerClient
interface directly。它使您可以访问主机和端口,然后您可以使用任何您想要的客户端。
public class MyClass {
@Autowired
private LoadBalancerClient loadBalancer;
public void doStuff() {
ServiceInstance instance = loadBalancer.choose("myService");
String host = instance.getHost();
int port = instance.getPort();
// ... do something with the host and port
}
}
我还与 OkHttp 进行了示例集成。