dubbo http流量接入dubbo后端服务

简介

dubbo协议是基于TCP的二进制私有协议,更适合作为后端微服务间的高效RPC通信协议,也导致dubbo协议对于前端流量接入不是很友好。在dubo框架中,有两种方式可以解决这个问题:

  • 多协议发布【推荐】,为dubbo协议服务暴露rest风格的http协议访问方式。
  • 通过网关实现 http->dubbo协议转换,这种方式需要将http协议转换为后端服务能识别的dubbo协议,要求网关必须支持dubbo协议。

同时发布http、dubbo协议

dubbo框架支持为同一个服务发布多个协议,并且支持客户端通过同一个端口以不同的协议访问服务。

发布方式一

dubbo协议的基础上增加tri协议

yml 复制代码
dubbo:
  protocol:
    name: dubbo
    port: 20080
    ext-protocol: tri
java 复制代码
public interface DemoService01 {
    String buyApple(Apple apple);
    String sayHello(String name);
}

public class Apple implements Serializable {
    private static final long serialVersionUID = 1L;
    
    private String name;
    
    public Apple(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Apple{" +
                "name='" + name + '\'' +
                '}';
    }
}

访问

shell 复制代码
curl --header "Content-Type:application/json"  --data '{"name":"apple"}' http://localhost:20880/com.doudou.rpc.api.DemoService01/buyApple 

curl --header "Content-Type:text/html"  --data "name" http://localhost:20880/com.doudou.rpc.api.DemoService01/sayHello 
发布方式二

只使用tri协议

yaml 复制代码
dubbo:
  protocol:
    name: tri
    port: 50053

访问

shell 复制代码
curl --header "Content-Type:application/json"  --data '{"name":"apple"}' http://localhost:50053/com.doudou.rpc.api.DemoService01/buyApple 

curl --header "Content-Type:text/html"  --data "name" http://localhost:50053/com.doudou.rpc.api.DemoService01/sayHello 

使用网关转http协议为dubbo协议

网关需要实现的关键点:

  • 协议转换,支持http到dubbo协议的转换,包括参数映射。
  • 自动地址发现,支持Nacos、Zookeeper、Kubernetes等主流注册中心,动态感知后端dubbo实例变化。
  • 结合dubbo协议的路由,如在发起 dubbo 协议调用时,支持按照特定规则地址筛选、传递附加参数到 dubbo 后端服务。

支持的开源网关

  • Higress
  • Apache APISIX
  • Apache Shenyu

参考HTTP网关接入->dubbo协议

相关推荐
板鸭〈小号〉12 小时前
UDP-Server(3)chat聊天室
网络·网络协议·udp
weixin_4569042716 小时前
使用HTTPS 服务在浏览器端使用摄像头的方式解析
网络协议·http·https
疯狂的维修19 小时前
关于Gateway configration studio软件配置网关
网络协议·c#·自动化·gateway
wow_DG20 小时前
【WebSocket✨】入门之旅(五):WebSocket 的安全性
网络·websocket·网络协议
拷贝码农卡卡东1 天前
pre-commit run --all-files 报错:http.client.RemoteDisconnected
网络·网络协议·http
DoWhatUWant1 天前
域格YM310 X09移芯CAT1模组HTTPS连接服务器
服务器·网络协议·https
又菜又爱玩呜呜呜~1 天前
go使用反射获取http.Request参数到结构体
开发语言·http·golang
言之。1 天前
TCP 拥塞控制设计空间课程要点总结
网络·网络协议·tcp/ip
cellurw1 天前
Linux下C语言实现HTTP+SQLite3电子元器件查询系统
linux·c语言·http