dubbo of springboot series

dubbo of springboot series

Introduction to dubbo

Apache Dubbo`Is a high performance Java RPC framework.
(1) High performance RPC calls for interface proxy
Provides high-performance proxy-based remote invocation capabilities. Services are interface-granular and shield developers from the underlying details of remote invocations.
(2) Intelligent Load Balancing
Built-in multiple load balancing strategies intelligently perceive the health of downstream nodes, significantly reduce call latencies, and improve system throughput.
(3) Automatic service registration and discovery
Multiple registry services are supported, and service instances are real-time aware offline.
(4) High scalability
Following the microkernel + plug-in design principles, all core capabilities such as Protocol, Transport, Serialization are designed as extension points, with equal treatment of built-in and third-party implementations.
(5) Runtime traffic dispatch
Built-in conditions, scripts and other routing strategies, by configuring different routing rules, can easily achieve gray publishing, same room priority and other functions.
(6) Visual service governance and operation
Provides rich services governance and maintenance tools: query service metadata, service health status and call statistics at any time, send routing policies in real time, and adjust configuration parameters.

dubbo usage (using dubbo direct connection)

1. Create a springboot project named dubbo-service
2. Add dubbo dependencies

<dependency>
     <groupId>org.apache.dubbo</groupId>
     <artifactId>dubbo-spring-boot-starter</artifactId>
     <version>2.7.7</version>
</dependency>

3. Create dubbo provider classes User, UserInfoService, UserInfoServiceImpl

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class User {
    private Long id;
    private String userName;
    private String password;
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private LocalDateTime createTime;
}

public interface UserInfoService {
    /**
     * Get user information
     *
     * @return
     */
    User getUserInfo();
}

@Component
@Service(version = "1.0.0", timeout = 10000, interfaceClass = UserInfoService.class)
public class UserInfoServiceImpl implements UserInfoService {

    @Override
    public User getUserInfo() {
            return User.builder().userName("name").password(UUID.randomUUID().toString().replaceAll("-", ""))
            .createTime(LocalDateTime.now()).build();
    }
}

4. Create dubbo consumer class DubboController

@RestController
public class DubboController {
    @Reference(version = "1.0.0", url = "dubbo://127.0.0.1:12345")
       private UserInfoService userInfoService;

    @RequestMapping("userInfo")
    public User userInfo(){
        return userInfoService.getUserInfo();
    }
}

5. ModificationApplication.propertiesconfiguration file

spring.application.name=dubbo-service
dubbo.scan.base-packages=com.wotrd.dubboprovider.service
# Dubbo Protocol
dubbo.protocol.name=dubbo
dubbo.protocol.port=12345
## Dubbo Registry
dubbo.registry.address=N/A

6. Start the service and access the address http://localhost : 8080/userInfo test returned successfully

{"id":null,"userName":"name","password":"487e5550715b44c3ab1e2a90cacc5d25","createTime":"2020-06-21 23:10:44"}

There is a problem, please leave a message! Personal Blog Address

Keywords: Java Dubbo SpringBoot Apache Spring

Added by cleromancer on Sun, 21 Jun 2020 19:12:57 +0300