# spring-cloud-thrift-gateway **Repository Path**: micro-project/spring-cloud-thrift-gateway ## Basic Information - **Project Name**: spring-cloud-thrift-gateway - **Description**: 基于Spring Cloud的Thrift网关,组件化Thrift服务端服务发布,通过简单的注解即可将服务发布到注册中心,支持Eureka、Nacos注册中心。 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2021-10-25 - **Last Updated**: 2021-10-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # spring-cloud-thrift-gateway #### 介绍 基于Spring Cloud的Thrift网关,组件化Thrift服务端服务发布,通过简单的注解即可将服务发布到注册中心,支持Eureka、Nacos注册中心。 #### 架构说明 利用Spring Cloud微服务架构的服务注册发现机制,在服务提供方注册到注册中心时,将Thrift服务的信息添加到Matadata中。 网关接收到thrift服务调用时,依据消息体中的相关标志位(目标服务名称)找到目标服务的实例,并从Matadata中获取Thrift服务提供方的地址信息,然后再转发服务调用 ![输入图片说明](https://images.gitee.com/uploads/images/2021/0930/163250_a06bdb60_5378692.png "屏幕截图.png") #### 使用说明 此处省略Spring Cloud微服务基础搭建,及Thrift接口定义和生成。 1. 在服务提供者中添加依赖 ```java com.zzz spring-cloud-starter-thrift 1.0.0 ``` 2. 在服务实现类上添加注解@ThriftService,并在服务启动类上添加注解@EnableThriftServer ```java @ThriftService public class TestServiceImpl implements TestService.Iface { ... } ``` ```java @SpringBootApplication @EnableDiscoveryClient @EnableThriftServer public class TestServiceProviderApplication { public static void main(String[] args) { SpringApplication.run(TestServiceProviderApplication.class, args); } } ``` 3. 服务调用只需要调用gateway的thrift服务,并指定目标服务名称即可 ```java transport = new TFastFramedTransport(new TSocket("127.0.0.1", 4567)); protocol = new TMultiplexedProtocol(new TBinaryProtocol(transport), "test-provider-server:TestService"); ```