solon.cloud.httputils
<dependency>
<groupId>org.noear</groupId>
<artifactId>solon.cloud.httputils</artifactId>
</dependency>
1、描述
分布式扩展插件。在 solon.cloud 插件的基础上,提供基于服务名的http调用。(替代 httputils-solon-cloud-plugin;v1.11.6 后支持)
为什么要替换?
httputils-solon-cloud-plugin 并不能算是 solon cloud 规范的实现,以 solon-cloud-plugin 结尾不构严肃。
2、使用示例
基于服务名的调用示例:(本质是基于注册与发布服务)
public class App {
public static void maing(String[] args) {
Solon.start(App.class, args);
//通过服务名进行http请求
HttpUtils.http("HelloService","/hello").get();
HttpUtils.http("HelloService","/hello").data("name", "world").post();
}
}
顺带放了一个预热工具,让自己可以请求自己。从而达到简单预热效果:
public class App {
public static void maing(String[] args) {
Solon.start(App.class, args);
//用http请求自己进行预热
PreheatUtils.preheat("/healthz");
//用bean预热
HelloService service = Solon.context().getBean(HelloService.class);
service.hello();
}
}
3、作为普通http工具类使用
public class App {
public static void maing(String[] args) {
Solon.start(App.class, args);
HttpUtils.http("http://localhost:8080/hello").get();
HttpUtils.http("http://localhost:8080/hello?name=world").get();
//x-www-form-urlencoded
HttpUtils.http("http://localhost:8080/hello").data("name","world").post();
//form-data
HttpUtils.http("http://localhost:8080/hello").data("name","world").multipart(true).post();
}
}