The announcement
Today, Marco is pleased to announce that the official Dubbo Spring Boot Starter 1.0.0 public beta has been developed and will soon be released to Maven public repository. It is currently being tested internally.
In order to collect more user feedback, We sincerely invite you to participate in the use, testing and joint maintenance of the project address: github.com/dubbo/dubb…. If you like and want to see what’s going on with the Dubbo Spring Boot project, click the GitHub Star button.
If you have any comments or suggestions, please send feedback here: github.com/dubbo/dubb….
For more plans and details, join the discussion at Dubbo Google Group.
The main features
Dubbo Spring Boot Starter is designed to simplify the development of Dubbo applications in the Spring Boot environment. It mainly includes auto-configure, externalized-configuration and Actuator readiness.
Version depends on
Note that the following dependencies have not yet been published to Maven’s public repository. Please checkout your code locally and build with the command $./ MVNW clean install:
<dependency> <groupId>com.alibaba.boot</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> < version > 1.0.0 - the SNAPSHOT < / version > < / dependency >Copy the code
Meanwhile, the underlying dubbo-spring-boot-starter relies on Dubbo 2.5.9.
Quick learning
Service Interface (RPC)
public interface DemoService {
String sayHello(String name);
}Copy the code
Service Provider
Implementation DemoServer interface to provide services (placed in com. Alibaba. Boot. Dubbo. Demo. The provider. The service package) :
@service (version = "1.0.0", application = "${dubo.application. Id}", protocol = "${dubo.protocol. Id}", registry = "${dubbo.registry.id}" ) public class DefaultDemoService implements DemoService { public String sayHello(String name) { return "Hello, " + name + " (from Spring Boot)"; }}Copy the code
Configure application.properties to provide an externalized configuration source:
# Spring boot application spring.application.name = dubbo-provider-demo server.port = 9090 management.port = 9091 # Dubbo components (such as @service, @reference) scan paths, Multipath to ", "split dubbo. Scan. BasePackages = com. Alibaba. Boot. Dubbo. Demo. The provider. The service # dubbo Config Bean externalized configuration dubbo.application.id = dubbo-provider-demo dubbo.application.name = dubbo-provider-demo dubbo.protocol.id = dubbo dubbo.protocol.name = dubbo dubbo.protocol.port = 12345 dubbo.registry.id = my-registryCopy the code
Provide service provider bootstrap classes:
@SpringBootApplication public class DubboProviderDemo { public static void main(String[] args) { SpringApplication.run(DubboProviderDemo.class,args); }}Copy the code
Service Consumers
Implement service consumers Controller (located in com. Alibaba. Boot. Dubbo. Demo. Consumer. The Controller package) :
@restController Public class DemoConsumerController {@reference (version = "1.0.0", application = "${dubbo.application.id}", url = "dubbo://localhost:12345") private DemoService demoService; @RequestMapping("/sayHello") public String sayHello(@RequestParam String name) { return demoService.sayHello(name); }}Copy the code
Add external configuration to application.properties:
# Spring boot application spring.application.name = dubbo-consumer-demo server.port = 8080 management.port = 8081 # Dubbo Config Bean externalizes Dubbo. Application. Id = Dubbo -consumer-demo Dubbo. Application. Name = Dubbo -consumer-demo dubbo.protocol.id = dubbo dubbo.protocol.name = dubbo dubbo.protocol.port = 12345Copy the code
Provide service consumer guidance classes:
@SpringBootApplication(scanBasePackages = "com.alibaba.boot.dubbo.demo.consumer.controller") public class DubboConsumerDemo { public static void main(String[] args) { SpringApplication.run(DubboConsumerDemo.class,args); }}Copy the code
See the official sample code for details: github.com/dubbo/dubb….
Auto-configure
Externalized-configuration
The Chinese version
Production preparation (Actuator)
Related articles
Annotations to Dubbo’s new programming model drive the external configuration of Dubbo’s new programming model