Supporting Both Feign (HTTP) and Dubbo (RPC) Protocols in Kitty Cloud
This article explains why the Kitty Cloud project integrates both Feign and Dubbo, discusses the need for dual‑protocol support during migration from Dubbo to Spring Cloud, presents three migration strategies, and shows how to implement and configure both HTTP and RPC calls within the same service.
The Kitty Cloud repository (https://github.com/yinjihuan/kitty-cloud) received an issue asking why both Feign and Dubbo are integrated; the author uses this as an opportunity to discuss dual‑protocol support.
Why support two protocols? As an open‑source project, offering both HTTP (Feign/RestTemplate) and RPC (Dubbo) gives users flexibility. HTTP is simple and easy to test with tools like PostMan or Swagger, while Dubbo provides high‑performance RPC for high‑traffic services. Supporting both also eases migration from legacy Dubbo services to Spring Cloud.
Example illustration shows two services initially communicating via RPC; after refactoring service B to HTTP, service A must switch to HTTP calls. Three migration schemes are described:
Scheme 1: Directly replace calls in service A with Feign or RestTemplate, which is impractical for many callers.
Scheme 2: Keep Dubbo calls unchanged for existing RPC services and add HTTP support only for new services by extending Dubbo’s underlying layer.
Scheme 3 (the adopted approach): Enable service B to expose both RPC and HTTP endpoints, allowing existing callers to continue using RPC while new callers can use HTTP.
How to enable both protocols :
Use Dubbo Spring Cloud, the core component of Spring Cloud Alibaba, to bridge Dubbo and Spring Cloud stacks.
Define service interfaces in a separate API module and annotate them with @FeignClient for HTTP.
In the implementation class, expose both protocols by adding @Service (Dubbo) and @RestController (Spring MVC) annotations.
@Autowired<br/>private UserRemoteService userRemoteService;<br/>For Feign injection, use @Autowired; for Dubbo injection, use
@Reference(version = DubboConstant.VERSION_V100, group = DubboConstant.DEFAULT_GROUP, check = false):
@Reference(version = DubboConstant.VERSION_V100, group = DubboConstant.DEFAULT_GROUP, check = false)<br/>private UserRemoteService userRemoteService;<br/>Configure Dubbo to register with the Spring Cloud registry:
dubbo.registry.address=spring-cloud://localhost<br/>Advanced usage allows users to choose the protocol at runtime, potentially by extending Feign or Dubbo layers and using a configuration center to switch between HTTP and RPC, even enabling generic Dubbo calls from Feign.
The author, Yinjihuan, is a technical enthusiast and author of several Spring Cloud books, reachable via WeChat (jihuan900) and the "猿天地" public account.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Full-Stack Internet Architecture
Introducing full-stack Internet architecture technologies centered on Java
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
