mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Polish alibaba/spring-cloud-alibaba#1665 : [Sample] Upgrading the Dubbo Sample
This commit is contained in:
parent
c0bcd52381
commit
f34a8a13c6
@ -17,7 +17,8 @@
|
|||||||
package com.alibaba.cloud.dubbo.bootstrap;
|
package com.alibaba.cloud.dubbo.bootstrap;
|
||||||
|
|
||||||
import com.alibaba.cloud.dubbo.service.EchoService;
|
import com.alibaba.cloud.dubbo.service.EchoService;
|
||||||
import org.apache.dubbo.config.annotation.Reference;
|
|
||||||
|
import org.apache.dubbo.config.annotation.DubboReference;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
@ -33,7 +34,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@RestController
|
@RestController
|
||||||
public class DubboSpringCloudClientBootstrap {
|
public class DubboSpringCloudClientBootstrap {
|
||||||
|
|
||||||
@Reference
|
@DubboReference
|
||||||
private EchoService echoService;
|
private EchoService echoService;
|
||||||
|
|
||||||
@GetMapping("/echo")
|
@GetMapping("/echo")
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
dubbo:
|
dubbo:
|
||||||
registry:
|
|
||||||
address: spring-cloud://localhost
|
|
||||||
cloud:
|
cloud:
|
||||||
subscribed-services: spring-cloud-alibaba-dubbo-server
|
subscribed-services: spring-cloud-alibaba-dubbo-server
|
||||||
|
protocols:
|
||||||
|
dubbo:
|
||||||
|
port: -1
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
|
@ -23,7 +23,8 @@ import com.alibaba.cloud.dubbo.annotation.DubboTransported;
|
|||||||
import com.alibaba.cloud.dubbo.service.RestService;
|
import com.alibaba.cloud.dubbo.service.RestService;
|
||||||
import com.alibaba.cloud.dubbo.service.User;
|
import com.alibaba.cloud.dubbo.service.User;
|
||||||
import com.alibaba.cloud.dubbo.service.UserService;
|
import com.alibaba.cloud.dubbo.service.UserService;
|
||||||
import org.apache.dubbo.config.annotation.Reference;
|
|
||||||
|
import org.apache.dubbo.config.annotation.DubboReference;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
@ -60,10 +61,10 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
|||||||
@EnableCaching
|
@EnableCaching
|
||||||
public class DubboSpringCloudConsumerBootstrap {
|
public class DubboSpringCloudConsumerBootstrap {
|
||||||
|
|
||||||
@Reference
|
@DubboReference
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
|
||||||
@Reference(version = "1.0.0", protocol = "dubbo")
|
@DubboReference(version = "1.0.0", protocol = "dubbo")
|
||||||
private RestService restService;
|
private RestService restService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -1,15 +1,10 @@
|
|||||||
dubbo:
|
dubbo:
|
||||||
registry:
|
|
||||||
# The Spring Cloud Dubbo's registry extension
|
|
||||||
## the default value of dubbo-provider-services is "*", that means to subscribe all providers,
|
|
||||||
## thus it's optimized if subscriber specifies the required providers.
|
|
||||||
address: spring-cloud://localhost
|
|
||||||
# The traditional Dubbo's registry also is supported
|
|
||||||
# address: zookeeper://127.0.0.1:2181
|
|
||||||
cloud:
|
cloud:
|
||||||
# The subscribed services in consumer side
|
# The subscribed services in consumer side
|
||||||
subscribed-services: ${provider.application.name}
|
subscribed-services: ${provider.application.name}
|
||||||
|
protocols:
|
||||||
|
dubbo:
|
||||||
|
port: -1
|
||||||
consumer:
|
consumer:
|
||||||
check: false
|
check: false
|
||||||
|
|
||||||
|
@ -20,12 +20,12 @@ import java.util.Collection;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.dubbo.config.annotation.Service;
|
import org.apache.dubbo.config.annotation.DubboService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In-Memory {@link UserService} implementation.
|
* In-Memory {@link UserService} implementation.
|
||||||
*/
|
*/
|
||||||
@Service(protocol = "dubbo")
|
@DubboService(protocol = "dubbo")
|
||||||
public class InMemoryUserService implements UserService {
|
public class InMemoryUserService implements UserService {
|
||||||
|
|
||||||
private Map<Long, User> usersRepository = new HashMap<>();
|
private Map<Long, User> usersRepository = new HashMap<>();
|
||||||
|
@ -30,7 +30,8 @@ import javax.ws.rs.Produces;
|
|||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.apache.dubbo.config.annotation.Service;
|
import org.apache.dubbo.config.annotation.DubboService;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -42,7 +43,7 @@ import static org.springframework.util.MimeTypeUtils.APPLICATION_JSON_VALUE;
|
|||||||
*
|
*
|
||||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||||
*/
|
*/
|
||||||
@Service(version = "1.0.0", protocol = { "dubbo", "rest" })
|
@DubboService(version = "1.0.0", protocol = { "dubbo", "rest" })
|
||||||
@Path("/")
|
@Path("/")
|
||||||
public class StandardRestService implements RestService {
|
public class StandardRestService implements RestService {
|
||||||
|
|
||||||
|
@ -20,12 +20,12 @@ import java.util.Collection;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.dubbo.config.annotation.Service;
|
import org.apache.dubbo.config.annotation.DubboService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In-Memory {@link UserService} implementation.
|
* In-Memory {@link UserService} implementation.
|
||||||
*/
|
*/
|
||||||
@Service(protocol = "dubbo")
|
@DubboService(protocol = "dubbo")
|
||||||
public class InMemoryUserService implements UserService {
|
public class InMemoryUserService implements UserService {
|
||||||
|
|
||||||
private Map<Long, User> usersRepository = new HashMap<>();
|
private Map<Long, User> usersRepository = new HashMap<>();
|
||||||
|
@ -19,7 +19,8 @@ package com.alibaba.cloud.dubbo.service;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.dubbo.config.annotation.Service;
|
import org.apache.dubbo.config.annotation.DubboService;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -39,7 +40,7 @@ import static com.alibaba.cloud.dubbo.util.LoggerUtils.log;
|
|||||||
*
|
*
|
||||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||||
*/
|
*/
|
||||||
@Service(version = "1.0.0")
|
@DubboService(version = "1.0.0")
|
||||||
@RestController
|
@RestController
|
||||||
public class SpringRestService implements RestService {
|
public class SpringRestService implements RestService {
|
||||||
|
|
||||||
|
@ -3,16 +3,7 @@ dubbo:
|
|||||||
base-packages: com.alibaba.cloud.dubbo.service
|
base-packages: com.alibaba.cloud.dubbo.service
|
||||||
protocols:
|
protocols:
|
||||||
dubbo:
|
dubbo:
|
||||||
name: dubbo
|
|
||||||
port: -1
|
port: -1
|
||||||
registries:
|
|
||||||
new:
|
|
||||||
address: spring-cloud://localhost
|
|
||||||
# registry:
|
|
||||||
# The Spring Cloud Dubbo's registry extension
|
|
||||||
# address: spring-cloud://localhost
|
|
||||||
# The traditional Dubbo's registry
|
|
||||||
# address: nacos://127.0.0.1:8848
|
|
||||||
|
|
||||||
feign:
|
feign:
|
||||||
hystrix:
|
hystrix:
|
||||||
|
@ -17,7 +17,8 @@
|
|||||||
package com.alibaba.cloud.dubbo.bootstrap;
|
package com.alibaba.cloud.dubbo.bootstrap;
|
||||||
|
|
||||||
import com.alibaba.cloud.dubbo.service.EchoService;
|
import com.alibaba.cloud.dubbo.service.EchoService;
|
||||||
import org.apache.dubbo.config.annotation.Service;
|
|
||||||
|
import org.apache.dubbo.config.annotation.DubboService;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
@ -36,7 +37,7 @@ public class DubboSpringCloudServerBootstrap {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Service
|
@DubboService
|
||||||
class EchoServiceImpl implements EchoService {
|
class EchoServiceImpl implements EchoService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -4,8 +4,6 @@ dubbo:
|
|||||||
protocol:
|
protocol:
|
||||||
name: dubbo
|
name: dubbo
|
||||||
port: -1
|
port: -1
|
||||||
registry:
|
|
||||||
address: spring-cloud://localhost
|
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user