A dubbo gateway based Java language.

Overview

Introduction

Dubbo Gateway是一个基于Java语言的Dubbo网关实现。基于Dubbo注册中心的元数据,通过将HTTP请求转换为Dubbo协议,泛化调用的方式返回请求结果。它具有如下的特性:

  1. 使用简单,开箱即用,非常适用于一些接口测试场景;
  2. 灵活可拓展。通过Interceptor的实现,可非常方便实现熔断、限流、路由、定制响应、用户授权等功能。系统也内置了部分Interceptor实现;
  3. 支持仅调用声明为对外开放的Dubbo服务,安全保证。(基于Feature:apache/dubbo#7660 );
  4. 文档自动化生成。基于Javadoc标准的dubbo对外接口生成系统,API写好即可生成文档,同时集成了阿里云OSS,全程仅需几步参数配置,即可可视化预览文档。

Requirements

服务提供者Dubbo 版本:Dubbo 2.7.14+ 或 Dubbo 3.x

Java 版本:1.8+

Guides

以Springboot项目方式,启动Dubbo Gateway网关:

1、添加依赖

新建Springboot工程,添加Dubbo Gateway的核心依赖:

<dependency>
	<groupId>com.kalman03groupId>
	<artifactId>gateway-coreartifactId>
	<version>1.2.0version>
dependency>

当然,还需要添加Dubbo的注册中心依赖,以Zookeeper为例:

<dependency>
	<groupId>org.apache.zookeepergroupId>
	<artifactId>zookeeperartifactId>
	<version>${zookeeper_version}version>
	<exclusions>
		<exclusion>
			<groupId>log4jgroupId>
			<artifactId>log4jartifactId>
		exclusion>
		<exclusion>
			<groupId>org.slf4jgroupId>
			<artifactId>slf4j-log4j12artifactId>
		exclusion>
	exclusions>
dependency>
<dependency>
	<groupId>org.apache.curatorgroupId>
	<artifactId>curator-frameworkartifactId>
	<version>${curator_version}version>
dependency>
<dependency>
	<groupId>org.apache.curatorgroupId>
	<artifactId>curator-recipesartifactId>
	<version>${curator_version}version>
dependency>

2、参数配置

gateway.netty.server.port=80
gateway.netty.server.host=127.0.0.1
gateway.netty.server.connect-timeout=3000
gateway.netty.business.thread-count=50
gateway.dubbo.registry.address=zookeeper://127.0.0.1:2181
gateway.dubbo.openservice=true

3、启动服务

@SpringBootApplication
@EnableAutoConfiguration
public class DubboGatewayTest {

	public static void main(String[] args) {
		try {
			SpringApplication.run(DubboGatewayTest.class, args);
		} catch (Throwable e) {
			e.printStackTrace();
		}
	}

    //可选自定义拦截器
	@Component
	@Order(100)
	@InterceptorRule(routeRuleType = RouteRuleType.PATH, excludePatterns = { "/api/**" })
	class CustomInterceptor implements HandlerInterceptor {
		@Override
		public boolean preHandle(GatewayHttpRequest request, GatewayHttpResponse response) throws Exception {
			System.out.println("preHandle");
			return true;
		}
		@Override
		public void afterCompletion(GatewayHttpRequest request, GatewayHttpResponse response, Exception ex)
				throws Exception {
			System.out.println("afterCompletion");
		}
	}
}

4、访问目标服务

系统内置了PATH路由MIX路由,也同时支持自定义路由实现。下面演示如何通过不同的路由规则访问对应的服务。

  • PATH路由(推荐)

    PATH路由是系统内置默认的路由,也是系统推荐的路由规则,其拥有较多适用性(既可正常调用,也可以满足一些第三方系统的调用要求,比如支付消息回调等),路由规则如下

    HTTP URL:

    http(s)://{domain}:{port}/{appName}/{interfaceName}/{method}/{group}/{version}
    

    HTTP Body (payload or form-data):

    {
      "id": 23,
      "username": "testUser"
    }
    
  • MIX路由

    考虑到有些参数相对于固定不变,且暴露在URL中不尽友善,系统内置了一种MIX的路由规则,将部分路由参数以Header的参数形式进行传递。

    HTTP URL:

    http(s)://{domain}:{port}/{interfaceName}/{method}
    

    HTTP Header:

    x-app-name={appName}
    x-group={group}
    x-version={version}
    x-route-rule=mix
    

    HTTP Body (payload or form-data):

    {
      "id": 23,
      "username": "testUser"
    }
    
  • CUSTOM自定义路由

    CUSTOM路由专为一些对PATH路由MIX路由都不满意的开发者准备,只需要继承AbstractRouteHandlerInterceptor 类,即可轻松实现自定义的路由规则。

Param Transmission

用户端通用参数(诸如请求UA/Referer/IP等)以及Token用户信息等,需要传递到服务提供方。Dubbo Gateway与服务提供者之间内置的参数传递走Dubbo的RpcContext。

Dubbo网关内置了gatewayConsumerFiltergatewayProviderFilter,可作为Dubbo服务提供者的默认Filter实现,通过该Filter可获取用户端请求的一些参数以及自定义拦截器封装的参数。当然,开发者也可自行在服务提供方读取RpcContext中的传递参数。

更多使用方式,参考:gateway-samplesgateway-samples-provider

Attention

Dubbo Gateway对Dubbo服务提供者提供的对外服务有一条要求:只能有一个服务入参,且为对象类型(非普通Java数据类型)

TODO

  • 更丰富的使用案例

欢迎贡献pull request......

Contacts

QQ group:601173814

License

Dubbo Gateway is released under the Apache License Version 2.0. See the LICENSE file for details.

You might also like...

Spring MSA api gateway & service discovery with consul & Jaeger & Cassandra

Spring-Cloud-MSA 준비 Cassandra 서버를 준비한다 table.sql 파일로 keyspace와 테이블을 만들어 둔다 Consul 1.11.1버전 기준 https://www.consul.io/downloads 에서 1.11.1 버전 운영체제 맞게 다운

Nov 22, 2022

Sample Spring-Cloud-Api-Gateway Project of Spring Boot

Sample-Spring-Cloud-Api-Gateway Sample Spring-Cloud-Api-Gateway Project of Spring Boot Proejct Stack Spring Webflux Spring Cloud Gateway Spring Data R

Jan 17, 2022

Demo microservice architecture with Spring ,Spring Cloud Gateway , Spring Cloud config server , Eureuka , keycloak and Docker.

Demo microservice architecture with Spring ,Spring Cloud Gateway , Spring Cloud config server , Eureuka , keycloak and Docker.

spring-microservice Demo microservice architecture with Spring ,Spring Cloud Gateway , Spring Cloud config server , Eureuka , keycloak and Docker. Arc

Sep 13, 2022

A high availability shopping(ecommerce) system using SpringBoot, Spring Cloud, Eureka Server, Spring Cloud Gateway, resillience4j, Kafka, Redis and MySQL.

A high availability shopping(ecommerce) system using SpringBoot, Spring Cloud, Eureka Server, Spring Cloud Gateway, resillience4j, Kafka, Redis and MySQL.

High-availability-shopping-system A high availability shopping(ecommerce) system using SpringBoot, Spring Cloud, Eureka Server, Spring Cloud Gateway,

Oct 26, 2022

Representational State Transfer + Structured Query Language(RSQL): Demo application using RSQL parser to filter records based on provided condition(s)

Representational State Transfer + Structured Query Language: RSQL Demo application using RSQL parser to filter records based on provided condition(s)

Nov 23, 2022

Code4Me provides automatic intelligent code completion based on large pre-trained language models

Code4Me Code4Me provides automatic intelligent code completion based on large pre-trained language models. Code4Me predicts statement (line) completio

Dec 5, 2022

Team 5468's 2022 FRC robot code. This code is written in Java and is based off of WPILib's Java control system and utilizes a command based system

FRC 2022 Team 5468's 2022 FRC robot code. This code is written in Java and is based off of WPILib's Java control system and utilizes a command based s

Oct 4, 2022

Very spicy additions to the Java programming language.

Project Lombok Project Lombok is a java library that automatically plugs into your editor and build tools, spicing up your java. Never write another g

Dec 30, 2022

A list of direct references to classes and interfaces in the Java Language Specification (3d Ed.)

A list of direct references to classes and interfaces in the Java Language Specification (3d Ed.) and a program to compute the indirectly required classes and interfaces

Jun 3, 2022
Owner
老夫正年轻
醒掌杀人剑,醉卧美人膝
老夫正年轻
Clivia is a scalable, high-performance, elastic and responsive API gateway based on spring weblux

clivia是一款基于spring webflux的可扩展、高性能、高弹性、响应式的 API 网关 clivia_V0.0.1 架构概览 模块介绍 clivia-admin-core : 网关配置管理后台核心模块 clivia-client-core : 网关核心模块 clivia-example

palading 14 Jan 9, 2023
芋道 mall 商城,基于微服务的思想,构建在 B2C 电商场景下的项目实战。核心技术栈,是 Spring Boot + Dubbo 。未来,会重构成 Spring Cloud Alibaba 。

[toc] 友情提示:近期在升级和优化该项目,建议先 Star 本项目。主要在做几个事情: 1、微服务技术选型以 Spring Cloud Alibaba 为中心。 2、修改项目分层,并合并部分服务,简化整体服务的复杂性。 3、将管理后台从 React 重构到 Vue 框架。 交流群:传送门 前言

芋道源码 7k Jan 6, 2023
一个涵盖六个专栏:Spring Boot 2.X、Spring Cloud、Spring Cloud Alibaba、Dubbo、分布式消息队列、分布式事务的仓库。希望胖友小手一抖,右上角来个 Star,感恩 1024

友情提示:因为提供了 50000+ 行示例代码,所以艿艿默认注释了所有 Maven Module。 胖友可以根据自己的需要,修改 pom.xml 即可。 一个涵盖六个主流技术栈的正经仓库: 《Spring Boot 专栏》 《Spring Cloud Alibaba 专栏》 《Spring Clou

芋道源码 15.7k Dec 31, 2022
:herb: 基于springboot的快速学习示例,整合自己遇到的开源框架,如:rabbitmq(延迟队列)、Kafka、jpa、redies、oauth2、swagger、jsp、docker、spring-batch、异常处理、日志输出、多模块开发、多环境打包、缓存cache、爬虫、jwt、GraphQL、dubbo、zookeeper和Async等等:pushpin:

欢迎大家留言和PR~ Tip: 技术更新换代太快,本仓库仅做参考,自己的项目具体使用哪个版本还需谨慎思考~(不推荐使用最新的版本,推荐使用(最新-1|2)的版本,会比较稳定) spring-boot-quick 前言   自己很早就想搞一个总的仓库就是将自己平时遇到的和学习到的东西整合在一起,方便后

wangxc 2.1k Jan 2, 2023
A simple implementation of the Dubbo protocol.

Codec-dubbo Codec-dubbo is a binary codec framework for dubbo protocol Features Fully compatible with Dubbo protocol Completely rewritten based on Net

ESA Stack 13 Nov 21, 2022
Apache/Alibaba Dubbo <= 2.7.3 PoC Code for CVE-2021-25641 RCE via Deserialization of Untrusted Data; Affects Versions <= 2.7.6 With Different Gadgets

The 0xDABB of Doom - CVE-2021-25641-Proof-of-Concept Apache/Alibaba Dubbo <= 2.7.3 PoC Code for CVE-2021-25641 RCE via Deserialization of Untrusted Da

Dor Tumarkin 51 Apr 24, 2022
Jamal is a macro language (JAmal MAcro Language)

Jamal Macro Language Jamal is a complex text processor with a wide variety of possible use. The first version of Jamal was developed 20 years ago in P

Peter Verhas 29 Dec 20, 2022
For Jack language. Most of codes were commented with their usage, which can be useful for beginner to realize the running principle of a compiler for object-oriented programming language.

Instructions: Download the Java source codes Store these codes into a local folder and open this folder Click the right key of mouse and click ‘Open i

gooooooood 1.1k Jan 5, 2023
ShenYu is High-Performance Java API Gateway.

Scalable, High Performance, Responsive API Gateway Solution for all MicroServices https://shenyu.apache.org/ English | 简体中文 Architecture Features Shen

The Apache Software Foundation 7.5k Jan 4, 2023
Spring boot microservice example with Eureka Server + Eureka Client + Spring Cloud API Gateway + OAuth2.0 + Circuit Breaker + Resilience4J + FeignClient + RestTemplate

Spring boot microservice example Spring boot microservice example with Eureka Server + Eureka Client + Spring Cloud API Gateway + OAuth2.0 + Circuit B

Subhash Lamba 47 Dec 29, 2022