├── sofa-samples-springboot2 ├── .DS_Store ├── sofa-echo-api │ ├── .DS_Store │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── alipay │ │ │ └── sofa │ │ │ └── ms │ │ │ └── service │ │ │ └── SofaEchoService.java │ └── pom.xml ├── sofa-echo-client │ ├── app │ │ ├── web │ │ │ ├── src │ │ │ │ └── main │ │ │ │ │ ├── resources │ │ │ │ │ ├── config │ │ │ │ │ │ ├── application-dev.properties │ │ │ │ │ │ ├── application-test.properties │ │ │ │ │ │ └── application.properties │ │ │ │ │ ├── static │ │ │ │ │ │ └── index.html │ │ │ │ │ ├── META-INF │ │ │ │ │ │ └── sofa-samples-client │ │ │ │ │ │ │ └── sofa-samples-springboot2-web.xml │ │ │ │ │ └── logback-spring.xml │ │ │ │ │ └── java │ │ │ │ │ └── com │ │ │ │ │ └── alipay │ │ │ │ │ └── sofa │ │ │ │ │ └── ms │ │ │ │ │ └── SOFABootClientSpringApplication.java │ │ │ └── pom.xml │ │ └── endpoint │ │ │ ├── src │ │ │ └── main │ │ │ │ ├── resources │ │ │ │ └── META-INF │ │ │ │ │ └── sofa-samples-client │ │ │ │ │ └── sofa-samples-springboot2-endpoint.xml │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── alipay │ │ │ │ └── sofa │ │ │ │ └── ms │ │ │ │ └── endpoint │ │ │ │ └── reference │ │ │ │ └── SofaEchoConsumer.java │ │ │ └── pom.xml │ ├── start.sh │ ├── Dockerfile │ └── pom.xml ├── sofa-echo-server │ ├── app │ │ ├── web │ │ │ ├── src │ │ │ │ └── main │ │ │ │ │ ├── resources │ │ │ │ │ ├── config │ │ │ │ │ │ ├── application-dev.properties │ │ │ │ │ │ ├── application-test.properties │ │ │ │ │ │ └── application.properties │ │ │ │ │ ├── static │ │ │ │ │ │ └── index.html │ │ │ │ │ ├── META-INF │ │ │ │ │ │ └── sofa-samples-server │ │ │ │ │ │ │ └── sofa-samples-springboot2-web.xml │ │ │ │ │ └── logback-spring.xml │ │ │ │ │ └── java │ │ │ │ │ └── com │ │ │ │ │ └── alipay │ │ │ │ │ └── sofa │ │ │ │ │ └── ms │ │ │ │ │ └── SOFABootServerSpringApplication.java │ │ │ └── pom.xml │ │ └── endpoint │ │ │ ├── src │ │ │ └── main │ │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── alipay │ │ │ │ │ └── sofa │ │ │ │ │ └── ms │ │ │ │ │ └── endpoint │ │ │ │ │ ├── constants │ │ │ │ │ ├── URLConstants.java │ │ │ │ │ └── RestConstants.java │ │ │ │ │ ├── impl │ │ │ │ │ ├── SofaEchoServiceImpl.java │ │ │ │ │ └── SampleRestFacadeRestImpl.java │ │ │ │ │ ├── exception │ │ │ │ │ ├── CommonException.java │ │ │ │ │ └── SofaRestExceptionHandler.java │ │ │ │ │ ├── filter │ │ │ │ │ └── CommonContainerResponseFilter.java │ │ │ │ │ ├── response │ │ │ │ │ ├── RestSampleFacadeResp.java │ │ │ │ │ └── AbstractFacadeResp.java │ │ │ │ │ ├── model │ │ │ │ │ └── DemoUserModel.java │ │ │ │ │ └── facade │ │ │ │ │ └── SampleRestFacade.java │ │ │ │ └── resources │ │ │ │ └── META-INF │ │ │ │ └── sofa-samples-server │ │ │ │ └── sofa-samples-springboot2-endpoint.xml │ │ │ └── pom.xml │ ├── start.sh │ ├── Dockerfile │ └── pom.xml ├── build.sh └── pom.xml ├── springcloud-samples-springboot2 ├── .DS_Store ├── springcloud-reservation-service │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ ├── bootstrap.yml │ │ │ ├── application-dev.properties │ │ │ └── application.properties │ │ │ └── java │ │ │ └── com │ │ │ └── alipay │ │ │ └── sofa │ │ │ └── ms │ │ │ └── spring │ │ │ └── cloud │ │ │ └── reservation │ │ │ └── service │ │ │ ├── entity │ │ │ ├── SubReq.java │ │ │ ├── Parameter.java │ │ │ ├── RequestModel.java │ │ │ ├── Reservation.java │ │ │ └── Model.java │ │ │ ├── ReservationRepository.java │ │ │ ├── ReservationServiceApplication.java │ │ │ └── controller │ │ │ └── HelloWorldController.java │ ├── .DS_Store │ ├── start.sh │ ├── Dockerfile │ ├── build.sh │ └── pom.xml ├── springcloud-turbine │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── bootstrap.properties │ │ │ └── java │ │ │ └── com │ │ │ └── alipay │ │ │ └── sofa │ │ │ └── ms │ │ │ └── spring │ │ │ └── cloud │ │ │ └── turbine │ │ │ └── TurbineApplication.java │ ├── .DS_Store │ └── pom.xml ├── springcloud-eureka-server │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── bootstrap.properties │ │ │ └── java │ │ │ └── com │ │ │ └── alipay │ │ │ └── sofa │ │ │ └── ms │ │ │ └── spring │ │ │ └── cloud │ │ │ └── eureka │ │ │ └── EurekaServiceApplication.java │ ├── .DS_Store │ └── pom.xml ├── springcloud-hystrix-dashboard │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── bootstrap.properties │ │ │ └── java │ │ │ └── com │ │ │ └── alipay │ │ │ └── sofa │ │ │ └── ms │ │ │ └── spring │ │ │ └── cloud │ │ │ └── hystrix │ │ │ └── dashboard │ │ │ └── HystrixDashboardApplication.java │ ├── .DS_Store │ └── pom.xml ├── springcloud-config-server │ ├── .DS_Store │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yml │ │ │ └── java │ │ │ └── com │ │ │ └── alipay │ │ │ └── sofa │ │ │ └── ms │ │ │ └── spring │ │ │ └── cloud │ │ │ └── config │ │ │ └── ConfigServerApplication.java │ └── pom.xml ├── springcloud-reservation-client │ ├── .DS_Store │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ ├── bootstrap.yml │ │ │ ├── application-dev.properties │ │ │ └── application.properties │ │ │ └── java │ │ │ └── com │ │ │ └── alipay │ │ │ └── sofa │ │ │ └── ms │ │ │ └── spring │ │ │ └── cloud │ │ │ └── reservation │ │ │ └── client │ │ │ ├── dto │ │ │ └── Reservation.java │ │ │ ├── service │ │ │ ├── ReservationServiceFallback.java │ │ │ └── ReservationService.java │ │ │ ├── ReservationClientApplication.java │ │ │ └── controller │ │ │ └── ReservationApiGatewayRestController.java │ ├── start.sh │ ├── Dockerfile │ ├── build.sh │ └── pom.xml ├── spring-cloud-reservation-gateway │ ├── .DS_Store │ ├── src │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── alipay │ │ │ │ └── sofa │ │ │ │ └── ms │ │ │ │ └── spring │ │ │ │ └── cloud │ │ │ │ └── reservation │ │ │ │ └── gateway │ │ │ │ └── ReservationGatewayApplication.java │ │ │ └── resources │ │ │ ├── application.yml │ │ │ └── application-dev.yml │ └── pom.xml ├── README.md ├── build.sh └── pom.xml ├── dubbo-samples-springboot2 ├── dubbo-echo-client │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ ├── application.properties │ │ │ ├── application-dev.properties │ │ │ ├── log4j.properties │ │ │ └── spring │ │ │ │ └── echo-consumer.xml │ │ │ └── java │ │ │ └── com │ │ │ └── alipay │ │ │ └── sofa │ │ │ └── ms │ │ │ └── EchoConsumer.java │ ├── start.sh │ ├── .DS_Store │ ├── Dockerfile │ └── pom.xml ├── dubbo-echo-server │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ ├── application.properties │ │ │ ├── application-dev.properties │ │ │ ├── log4j.properties │ │ │ └── spring │ │ │ │ └── echo-provider.xml │ │ │ └── java │ │ │ └── com │ │ │ └── alipay │ │ │ └── sofa │ │ │ └── ms │ │ │ ├── EchoProvider.java │ │ │ └── service │ │ │ └── EchoServiceImpl.java │ ├── start.sh │ ├── .DS_Store │ ├── Dockerfile │ ├── build.sh │ └── pom.xml ├── dubbo-webservice │ ├── start.sh │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.properties │ │ │ └── java │ │ │ └── com │ │ │ └── alipay │ │ │ └── webservice │ │ │ ├── service │ │ │ └── HelloWebService.java │ │ │ ├── WebServiceBootstrap.java │ │ │ ├── impl │ │ │ ├── WebServiceConfig.java │ │ │ └── HelloWebServiceImpl.java │ │ │ ├── controller │ │ │ ├── XrResponseController.java │ │ │ └── WebServiceController.java │ │ │ ├── SocketServerBootstrap.java │ │ │ ├── BEISServerBootstrap.java │ │ │ └── CDServerBootstrap.java │ ├── Dockerfile │ ├── build.sh │ └── pom.xml ├── dubbo-springcloud │ ├── start.sh │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── spring │ │ │ │ └── echo-consumer.xml │ │ │ └── java │ │ │ └── com │ │ │ └── alipay │ │ │ └── sofa │ │ │ └── ms │ │ │ ├── SpringCloudBootstrap.java │ │ │ └── controller │ │ │ └── DemoClientController.java │ ├── Dockerfile │ ├── build.sh │ └── pom.xml ├── dubbo-echo-api │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── alipay │ │ │ └── sofa │ │ │ └── ms │ │ │ └── service │ │ │ ├── model │ │ │ └── SubReq.java │ │ │ └── EchoService.java │ └── pom.xml ├── README.md ├── build.sh └── pom.xml ├── hsf-samples-pandoraboot ├── hsf-echo-client │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.properties │ │ │ └── java │ │ │ └── com │ │ │ └── alibaba │ │ │ └── edas │ │ │ ├── HealthCheckController.java │ │ │ ├── HsfConfig.java │ │ │ ├── HSFConsumerApplication.java │ │ │ └── SimpleController.java │ └── pom.xml ├── hsf-echo-server │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.properties │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── alibaba │ │ │ │ └── edas │ │ │ │ ├── HealthCheckController.java │ │ │ │ ├── HelloServiceImpl.java │ │ │ │ └── HSFProviderApplication.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── alibaba │ │ │ └── edas │ │ │ └── HelloServiceTest.java │ └── pom.xml ├── hsf-echo-api │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── alibaba │ │ │ └── hsf │ │ │ └── edas │ │ │ └── HelloService.java │ └── pom.xml ├── README.md └── pom.xml ├── README.md ├── .gitignore ├── LICENSE └── pom.xml /sofa-samples-springboot2/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sofastack-guides/sofastack-mesh-demo/HEAD/sofa-samples-springboot2/.DS_Store -------------------------------------------------------------------------------- /springcloud-samples-springboot2/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sofastack-guides/sofastack-mesh-demo/HEAD/springcloud-samples-springboot2/.DS_Store -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-service/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: reservation-service -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-echo-client/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=dubbo-echo-client 2 | logging.path=/home/admin/logs -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-echo-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=dubbo-echo-server 2 | logging.path=/home/admin/logs 3 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-webservice/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | java -Duser.timezone=Asia/Shanghai -jar /home/admin/release/dubbo-webservice-1.0-SNAPSHOT.jar 4 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-api/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sofastack-guides/sofastack-mesh-demo/HEAD/sofa-samples-springboot2/sofa-echo-api/.DS_Store -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-echo-client/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | java -Duser.timezone=Asia/Shanghai -jar /home/admin/release/dubbo-echo-client-1.0-SNAPSHOT.jar 4 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-echo-server/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | java -Duser.timezone=Asia/Shanghai -jar /home/admin/release/dubbo-echo-server-1.0-SNAPSHOT.jar 4 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-springcloud/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | java -Duser.timezone=Asia/Shanghai -jar /home/admin/release/dubbo-springcloud-1.0-SNAPSHOT.jar 4 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-echo-client/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sofastack-guides/sofastack-mesh-demo/HEAD/dubbo-samples-springboot2/dubbo-echo-client/.DS_Store -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-echo-server/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sofastack-guides/sofastack-mesh-demo/HEAD/dubbo-samples-springboot2/dubbo-echo-server/.DS_Store -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-turbine/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=turbine 2 | spring.cloud.config.uri=http://localhost:8888 3 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-echo-client/src/main/resources/application-dev.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=dubbo-echo-client 2 | logging.path=./logs/client 3 | server.port=8777 -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-echo-server/src/main/resources/application-dev.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=dubbo-echo-server 2 | logging.path=./logs/server 3 | server.port=8789 -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-webservice/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=dubbo-webservice 2 | logging.path=./logs/webservice 3 | server.port=8999 -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-service/src/main/resources/application-dev.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=reservation-service 2 | logging.path=./logs/server -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-springcloud/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=dubbo-springcloud 2 | logging.path=./logs/springcloud 3 | server.port=10999 -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-client/app/web/src/main/resources/config/application-dev.properties: -------------------------------------------------------------------------------- 1 | # when spring.profiles.active value contains [dev],this config file will be loaded. -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-client/app/web/src/main/resources/config/application-test.properties: -------------------------------------------------------------------------------- 1 | # when spring.profiles.active value contains [test],this config file will be loaded. -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-server/app/web/src/main/resources/config/application-dev.properties: -------------------------------------------------------------------------------- 1 | # when spring.profiles.active value contains [dev],this config file will be loaded. -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-server/app/web/src/main/resources/config/application-test.properties: -------------------------------------------------------------------------------- 1 | # when spring.profiles.active value contains [test],this config file will be loaded. -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-eureka-server/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=eureka-service 2 | spring.cloud.config.uri=http://localhost:8888 -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-hystrix-dashboard/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=hystrix-dashboard 2 | spring.cloud.config.uri=http://localhost:8888 -------------------------------------------------------------------------------- /hsf-samples-pandoraboot/hsf-echo-client/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=hsf-echo-client 2 | server.port=8086 3 | spring.hsf.version=1.0.0 4 | spring.hsf.timeout=1000 -------------------------------------------------------------------------------- /hsf-samples-pandoraboot/hsf-echo-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=hsf-echo-server 2 | server.port=8087 3 | spring.hsf.version=1.0.0 4 | spring.hsf.timeout=3000 -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-turbine/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sofastack-guides/sofastack-mesh-demo/HEAD/springcloud-samples-springboot2/springcloud-turbine/.DS_Store -------------------------------------------------------------------------------- /hsf-samples-pandoraboot/hsf-echo-api/src/main/java/com/alibaba/hsf/edas/HelloService.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.hsf.edas; 2 | 3 | public interface HelloService { 4 | String echo(String string); 5 | } -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-config-server/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sofastack-guides/sofastack-mesh-demo/HEAD/springcloud-samples-springboot2/springcloud-config-server/.DS_Store -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-eureka-server/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sofastack-guides/sofastack-mesh-demo/HEAD/springcloud-samples-springboot2/springcloud-eureka-server/.DS_Store -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-hystrix-dashboard/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sofastack-guides/sofastack-mesh-demo/HEAD/springcloud-samples-springboot2/springcloud-hystrix-dashboard/.DS_Store -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-client/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sofastack-guides/sofastack-mesh-demo/HEAD/springcloud-samples-springboot2/springcloud-reservation-client/.DS_Store -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-service/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sofastack-guides/sofastack-mesh-demo/HEAD/springcloud-samples-springboot2/springcloud-reservation-service/.DS_Store -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-client/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | java -Dmesh_http_read_timeout=600000 -Duser.timezone=Asia/Shanghai -jar /home/admin/release/sofa-echo-client-web-1.0-SNAPSHOT-executable.jar 5 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-server/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | java -Dmesh_http_read_timeout=600000 -Duser.timezone=Asia/Shanghai -jar /home/admin/release/sofa-echo-server-web-1.0-SNAPSHOT-executable.jar 5 | -------------------------------------------------------------------------------- /springcloud-samples-springboot2/spring-cloud-reservation-gateway/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sofastack-guides/sofastack-mesh-demo/HEAD/springcloud-samples-springboot2/spring-cloud-reservation-gateway/.DS_Store -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-echo-api/src/main/java/com/alipay/sofa/ms/service/model/SubReq.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.service.model; 2 | 3 | public class SubReq { 4 | public int a; 5 | public int b; 6 | 7 | } -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-client/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: reservation-client 4 | 5 | #eureka: 6 | # client: 7 | logging: 8 | path: ./logs 9 | # enabled: false -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-client/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | java -Dmesh_http_read_timeout=600000 -Duser.timezone=Asia/Shanghai -jar /home/admin/release/springcloud-reservation-client-1.0-SNAPSHOT.jar 5 | -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-service/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | java -Dmesh_http_read_timeout=600000 -Duser.timezone=Asia/Shanghai -jar /home/admin/release/springcloud-reservation-service-1.0-SNAPSHOT.jar 5 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-client/app/web/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |

the static page in SOFA Boot based on Spring Boot

10 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-server/app/web/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |

the static page in SOFA Boot based on Spring Boot

10 | -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-client/src/main/resources/application-dev.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=reservation-client 2 | SOFA_INSTANCE_ID=000001 3 | SOFA_ANTVIP_ENDPOINT=11.239.139.142 4 | SOFA_ACCESS_KEY=xxx 5 | SOFA_SECRET_KEY=yyy 6 | logging.path=./logs/client -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-service/src/main/java/com/alipay/sofa/ms/spring/cloud/reservation/service/entity/SubReq.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.spring.cloud.reservation.service.entity; 2 | 3 | public class SubReq { 4 | public int a; 5 | public int b; 6 | } -------------------------------------------------------------------------------- /dubbo-samples-springboot2/README.md: -------------------------------------------------------------------------------- 1 | # dubbo mesh demo 2 | 3 | setp1: 4 | start zookeeper first on mac. 5 | 6 | step2: 7 | start dubbo-echo-server with jvm arguments: -Dspring.profiles.active=dev 8 | 9 | step3: 10 | start dubbo-echo-client with jvm arguments: -Dspring.profiles.active=dev -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-config-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: config-server 4 | cloud: 5 | config: 6 | server: 7 | git: 8 | uri: https://github.com/nobodyiam/config-repo.git 9 | 10 | server: 11 | port: 8888 12 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-echo-client/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | ###set log levels### 2 | log4j.rootLogger=info, stdout 3 | ###output to the console### 4 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 5 | log4j.appender.stdout.Target=System.out 6 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 7 | log4j.appender.stdout.layout.ConversionPattern=[%d{dd/MM/yy HH:mm:ss:SSS z}] %t %5p %c{2}: %m%n -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-echo-server/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | ###set log levels### 2 | log4j.rootLogger=info, stdout 3 | ###output to the console### 4 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 5 | log4j.appender.stdout.Target=System.out 6 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 7 | log4j.appender.stdout.layout.ConversionPattern=[%d{dd/MM/yy HH:mm:ss:SSS z}] %t %5p %c{2}: %m%n -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-api/src/main/java/com/alipay/sofa/ms/service/SofaEchoService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Alipay.com Inc. 3 | * Copyright (c) 2004-2020 All Rights Reserved. 4 | */ 5 | package com.alipay.sofa.ms.service; 6 | 7 | /** 8 | * @author yiji@apache.org 9 | * @version : EchoService.java, v 0.1 2020年02月24日 2:47 下午 yiji Exp $ 10 | */ 11 | public interface SofaEchoService { 12 | String echo(String message); 13 | } -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-server/app/endpoint/src/main/java/com/alipay/sofa/ms/endpoint/constants/URLConstants.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.endpoint.constants; 2 | 3 | /** 4 | * URL constants 5 | * 6 | * Created by yangguanchao on 16/11/18. 7 | */ 8 | public class URLConstants { 9 | 10 | /** 11 | * rest prefix address 12 | */ 13 | public static final String REST_API_PEFFIX = "/webapi"; 14 | } 15 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-webservice/src/main/java/com/alipay/webservice/service/HelloWebService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Alipay.com Inc. 3 | * Copyright (c) 2004-2020 All Rights Reserved. 4 | */ 5 | package com.alipay.webservice.service; 6 | 7 | import javax.jws.WebParam; 8 | import javax.jws.WebService; 9 | 10 | @WebService 11 | public interface HelloWebService { 12 | 13 | String sayHello(@WebParam(name = "name") String name); 14 | 15 | } -------------------------------------------------------------------------------- /hsf-samples-pandoraboot/hsf-echo-client/src/main/java/com/alibaba/edas/HealthCheckController.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.edas; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | @RestController 7 | public class HealthCheckController { 8 | 9 | @RequestMapping("/health") 10 | public String heakthCheck() { 11 | return "success"; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /hsf-samples-pandoraboot/hsf-echo-server/src/main/java/com/alibaba/edas/HealthCheckController.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.edas; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | @RestController 7 | public class HealthCheckController { 8 | 9 | @RequestMapping("/health") 10 | public String healthCheck() { 11 | return "success"; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # sofastack-mesh-demo 2 | 3 | # start without mesh (with sofa registry) 4 | 5 | -DSOFA_INSTANCE_ID=000001 6 | -DSOFA_ANTVIP_ENDPOINT=11.239.139.142 7 | -DSOFA_ACCESS_KEY= 8 | -DSOFA_SECRET_KEY= 9 | -Dspring.profiles.active=dev 10 | 11 | # start with mesh (with sofa registry) 12 | 13 | -DMOSN_ENABLE=true 14 | -DSOFA_INSTANCE_ID=000001 15 | -DSOFA_ANTVIP_ENDPOINT=11.239.139.142 16 | -DSOFA_ACCESS_KEY= 17 | -DSOFA_SECRET_KEY= 18 | -Dspring.profiles.active=dev -------------------------------------------------------------------------------- /hsf-samples-pandoraboot/hsf-echo-client/src/main/java/com/alibaba/edas/HsfConfig.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.edas; 2 | 3 | import com.alibaba.boot.hsf.annotation.HSFConsumer; 4 | import com.alibaba.hsf.edas.HelloService; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | 8 | @Configuration 9 | public class HsfConfig { 10 | 11 | @HSFConsumer(clientTimeout = 3000, serviceVersion = "1.0.0") 12 | private HelloService helloService; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /hsf-samples-pandoraboot/hsf-echo-server/src/main/java/com/alibaba/edas/HelloServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.edas; 2 | 3 | import com.alibaba.boot.hsf.annotation.HSFProvider; 4 | import com.alibaba.hsf.edas.HelloService; 5 | 6 | 7 | @HSFProvider(serviceInterface = HelloService.class, serviceVersion = "1.0.0") 8 | public class HelloServiceImpl implements HelloService { 9 | @Override 10 | public String echo(String string) { 11 | return string; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-client/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | info.id=${spring.application.name} 2 | server.port=${PORT:${SERVER_PORT:0}} 3 | logging.path=/home/admin/logs 4 | logging.level.root=info 5 | logging.level.org.springframework.security=ERROR 6 | logging.level.com.netflix.discovery=ERROR 7 | 8 | server.port=${PORT:9999} 9 | feign.hystrix.enabled=true 10 | management.security.enabled=false 11 | management.endpoints.web.exposure.include = hystrix.stream -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Java template 3 | # Compiled class file 4 | *.class 5 | 6 | # Log file 7 | *.log 8 | 9 | # BlueJ files 10 | *.ctxt 11 | 12 | # Mobile Tools for Java (J2ME) 13 | .mtj.tmp/ 14 | 15 | # Package Files # 16 | *.jar 17 | *.war 18 | *.nar 19 | *.ear 20 | *.zip 21 | *.tar.gz 22 | *.rar 23 | *.iml 24 | 25 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 26 | hs_err_pid* 27 | .idea 28 | target/ 29 | logs/ 30 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-webservice/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jre-alpine 2 | MAINTAINER yiji 3 | 4 | RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ 5 | && echo "Asia/Shanghai" > /etc/timezone 6 | 7 | ADD target/dubbo-webservice-1.0-SNAPSHOT.jar /home/admin/release/dubbo-webservice-1.0-SNAPSHOT.jar 8 | 9 | ADD start.sh /home/admin/release/start.sh 10 | 11 | RUN chmod a+x /home/admin/release/start.sh 12 | 13 | ENTRYPOINT ["/bin/sh", "/home/admin/release/start.sh"] 14 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-echo-client/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jre-alpine 2 | MAINTAINER yiji 3 | 4 | RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ 5 | && echo "Asia/Shanghai" > /etc/timezone 6 | 7 | ADD target/dubbo-echo-client-1.0-SNAPSHOT.jar /home/admin/release/dubbo-echo-client-1.0-SNAPSHOT.jar 8 | 9 | ADD start.sh /home/admin/release/start.sh 10 | 11 | RUN chmod a+x /home/admin/release/start.sh 12 | 13 | ENTRYPOINT ["/bin/sh", "/home/admin/release/start.sh"] 14 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-echo-server/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jre-alpine 2 | MAINTAINER yiji 3 | 4 | RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ 5 | && echo "Asia/Shanghai" > /etc/timezone 6 | 7 | ADD target/dubbo-echo-server-1.0-SNAPSHOT.jar /home/admin/release/dubbo-echo-server-1.0-SNAPSHOT.jar 8 | 9 | ADD start.sh /home/admin/release/start.sh 10 | 11 | RUN chmod a+x /home/admin/release/start.sh 12 | 13 | ENTRYPOINT ["/bin/sh", "/home/admin/release/start.sh"] 14 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-springcloud/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jre-alpine 2 | MAINTAINER yiji 3 | 4 | RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ 5 | && echo "Asia/Shanghai" > /etc/timezone 6 | 7 | ADD target/dubbo-springcloud-1.0-SNAPSHOT.jar /home/admin/release/dubbo-springcloud-1.0-SNAPSHOT.jar 8 | 9 | ADD start.sh /home/admin/release/start.sh 10 | 11 | RUN chmod a+x /home/admin/release/start.sh 12 | 13 | ENTRYPOINT ["/bin/sh", "/home/admin/release/start.sh"] 14 | -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-client/src/main/java/com/alipay/sofa/ms/spring/cloud/reservation/client/dto/Reservation.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.spring.cloud.reservation.client.dto; 2 | 3 | /** 4 | * @author yiji@apache.org 5 | */ 6 | public class Reservation { 7 | private Long id; 8 | private String reservationName; 9 | 10 | public Long getId() { 11 | return id; 12 | } 13 | 14 | public String getReservationName() { 15 | return reservationName; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-client/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jre-alpine 2 | MAINTAINER yiji 3 | 4 | RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ 5 | && echo "Asia/Shanghai" > /etc/timezone 6 | 7 | ADD target/sofa-echo-client-web-1.0-SNAPSHOT-executable.jar /home/admin/release/sofa-echo-client-web-1.0-SNAPSHOT-executable.jar 8 | 9 | ADD start.sh /home/admin/release/start.sh 10 | 11 | RUN chmod a+x /home/admin/release/start.sh 12 | 13 | ENTRYPOINT ["/bin/sh", "/home/admin/release/start.sh"] 14 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-server/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jre-alpine 2 | MAINTAINER yiji 3 | 4 | RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ 5 | && echo "Asia/Shanghai" > /etc/timezone 6 | 7 | ADD target/sofa-echo-server-web-1.0-SNAPSHOT-executable.jar /home/admin/release/sofa-echo-server-web-1.0-SNAPSHOT-executable.jar 8 | 9 | ADD start.sh /home/admin/release/start.sh 10 | 11 | RUN chmod a+x /home/admin/release/start.sh 12 | 13 | ENTRYPOINT ["/bin/sh", "/home/admin/release/start.sh"] 14 | -------------------------------------------------------------------------------- /hsf-samples-pandoraboot/README.md: -------------------------------------------------------------------------------- 1 | 2 | - doc : https://help.aliyun.com/document_detail/91225.html 3 | - console: http://127.0.0.1:8080/#/serviceManagement?dataId=&group=&appName=&namespace=&serverId= 4 | 5 | 6 | 排除!alipay-cloud-server@public,!edas-oss-central,!edas-oss-plugin-central仓库镜像配置 7 | 8 | ``` 9 | 10 | mirror-all 11 | *,!alipay-cloud-server@public,!edas-oss-central,!edas-oss-plugin-central 12 | mirror 13 | http://mvn.cloud.alipay.com/nexus/content/groups/public 14 | 15 | ``` -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-client/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jre-alpine 2 | MAINTAINER jason 3 | 4 | RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ 5 | && echo "Asia/Shanghai" > /etc/timezone 6 | 7 | ADD target/springcloud-reservation-client-1.0-SNAPSHOT.jar /home/admin/release/springcloud-reservation-client-1.0-SNAPSHOT.jar 8 | 9 | ADD start.sh /home/admin/release/start.sh 10 | 11 | RUN chmod a+x /home/admin/release/start.sh 12 | 13 | ENTRYPOINT ["/bin/sh", "/home/admin/release/start.sh"] 14 | -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-service/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jre-alpine 2 | MAINTAINER jason 3 | 4 | RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ 5 | && echo "Asia/Shanghai" > /etc/timezone 6 | 7 | ADD target/springcloud-reservation-service-1.0-SNAPSHOT.jar /home/admin/release/springcloud-reservation-service-1.0-SNAPSHOT.jar 8 | 9 | ADD start.sh /home/admin/release/start.sh 10 | 11 | RUN chmod a+x /home/admin/release/start.sh 12 | 13 | ENTRYPOINT ["/bin/sh", "/home/admin/release/start.sh"] 14 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-echo-api/src/main/java/com/alipay/sofa/ms/service/EchoService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Alipay.com Inc. 3 | * Copyright (c) 2004-2020 All Rights Reserved. 4 | */ 5 | package com.alipay.sofa.ms.service; 6 | 7 | import com.alipay.sofa.ms.service.model.SubReq; 8 | 9 | /** 10 | * @author yiji@apache.org 11 | * @version : EchoService.java, v 0.1 2020年02月24日 2:47 下午 yiji Exp $ 12 | */ 13 | public interface EchoService { 14 | String echo(String message); 15 | 16 | Integer add(Integer a, Integer b); 17 | 18 | Integer sub(SubReq subReq); 19 | } -------------------------------------------------------------------------------- /hsf-samples-pandoraboot/hsf-echo-client/src/main/java/com/alibaba/edas/HSFConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.edas; 2 | 3 | import com.taobao.pandora.boot.PandoraBootstrap; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | public class HSFConsumerApplication { 9 | 10 | public static void main(String[] args) { 11 | PandoraBootstrap.run(args); 12 | SpringApplication.run(HSFConsumerApplication.class, args); 13 | PandoraBootstrap.markStartupAndWait(); 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.alipay.sofa.ms 7 | sofa-samples-springboot2 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | sofa-echo-api 13 | 14 | 15 | -------------------------------------------------------------------------------- /springcloud-samples-springboot2/README.md: -------------------------------------------------------------------------------- 1 | # spring cloud mesh demo 2 | 3 | ## Introduction 4 | 5 | This is a demo Spring Boot project which shows the use of Spring Cloud families including: 6 | 7 | * Spring Cloud Config 8 | * Spring Cloud Netflix 9 | - Eureka 10 | - Hystrix 11 | - Zuul 12 | - Ribbon 13 | - Turbine 14 | * Spring Cloud Feign 15 | * Spring Cloud Sleuth 16 | 17 | step1: 18 | start springcloud-config-server 19 | 20 | step2: 21 | start springcloud-eureka-server 22 | 23 | step3: 24 | springcloud-reservation-service 25 | 26 | step4: 27 | springcloud-reservation-client -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-echo-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.alipay.sofa.ms 7 | dubbo-samples-springboot2 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | dubbo-echo-api 13 | 14 | 15 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-webservice/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | version="$1" 4 | 5 | if [[ -z "$version" ]] 6 | then 7 | echo "Usage: build.sh image-version" 8 | exit 1; 9 | else 10 | echo "Start building with image-version: $version" 11 | fi 12 | 13 | mvn clean package 14 | 15 | docker build -t dubbo-webservice:${version} . 16 | 17 | docker tag dubbo-webservice:${version} reg-cnsh-nf.cloud.alipay.com/library/dubbo-webservice:${version} 18 | docker tag dubbo-webservice:${version} ms.docker.hub.com:6003/library/dubbo-webservice:${version} 19 | 20 | echo ms.docker.hub.com:6003/library/dubbo-webservice:${version} -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-echo-server/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | version="$1" 4 | 5 | if [[ -z "$version" ]] 6 | then 7 | echo "Usage: build.sh image-version" 8 | exit 1; 9 | else 10 | echo "Start building with image-version: $version" 11 | fi 12 | 13 | mvn clean package 14 | 15 | docker build -t dubbo-echo-server:${version} . 16 | 17 | docker tag dubbo-echo-server:${version} reg-cnsh-nf.cloud.alipay.com/library/dubbo-echo-server:${version} 18 | docker tag dubbo-echo-server:${version} ms.docker.hub.com:6003/library/dubbo-echo-server:${version} 19 | 20 | echo ms.docker.hub.com:6003/library/dubbo-echo-server:${version} -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-springcloud/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | version="$1" 4 | 5 | if [[ -z "$version" ]] 6 | then 7 | echo "Usage: build.sh image-version" 8 | exit 1; 9 | else 10 | echo "Start building with image-version: $version" 11 | fi 12 | 13 | mvn clean package 14 | 15 | docker build -t dubbo-springcloud:${version} . 16 | 17 | docker tag dubbo-springcloud:${version} reg-cnsh-nf.cloud.alipay.com/library/dubbo-springcloud:${version} 18 | docker tag dubbo-springcloud:${version} ms.docker.hub.com:6003/library/dubbo-springcloud:${version} 19 | 20 | echo ms.docker.hub.com:6003/library/dubbo-springcloud:${version} -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-server/app/endpoint/src/main/java/com/alipay/sofa/ms/endpoint/impl/SofaEchoServiceImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Alipay.com Inc. 3 | * Copyright (c) 2004-2020 All Rights Reserved. 4 | */ 5 | package com.alipay.sofa.ms.endpoint.impl; 6 | 7 | import com.alipay.sofa.ms.service.SofaEchoService; 8 | 9 | /** 10 | * @author yiji 11 | * @version : SofaEchoServiceImpl.java, v 0.1 2020年04月21日 1:50 下午 yiji Exp $ 12 | */ 13 | public class SofaEchoServiceImpl implements SofaEchoService { 14 | @Override 15 | public String echo(String message) { 16 | // we don't care about message content. 17 | return "success"; 18 | } 19 | } -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-eureka-server/src/main/java/com/alipay/sofa/ms/spring/cloud/eureka/EurekaServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.spring.cloud.eureka; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | /** 8 | * Created by Jason on 5/4/16. 9 | */ 10 | @EnableEurekaServer 11 | @SpringBootApplication 12 | public class EurekaServiceApplication { 13 | public static void main(String[] args) { 14 | SpringApplication.run(EurekaServiceApplication.class, args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-client/src/main/java/com/alipay/sofa/ms/spring/cloud/reservation/client/service/ReservationServiceFallback.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.spring.cloud.reservation.client.service; 2 | 3 | import com.alipay.sofa.ms.spring.cloud.reservation.client.dto.Reservation; 4 | import java.util.Collections; 5 | import org.springframework.hateoas.Resources; 6 | import org.springframework.stereotype.Service; 7 | 8 | @Service 9 | public class ReservationServiceFallback implements ReservationService { 10 | 11 | @Override 12 | public Resources queryReservations() { 13 | return new Resources<>(Collections.emptyList()); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-turbine/src/main/java/com/alipay/sofa/ms/spring/cloud/turbine/TurbineApplication.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.spring.cloud.turbine; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.netflix.turbine.EnableTurbine; 7 | 8 | @SpringBootApplication 9 | @EnableDiscoveryClient 10 | @EnableTurbine 11 | public class TurbineApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(TurbineApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-config-server/src/main/java/com/alipay/sofa/ms/spring/cloud/config/ConfigServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.spring.cloud.config; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | import org.springframework.cloud.config.server.EnableConfigServer; 6 | 7 | /** 8 | * @author yiji@apache.org 9 | */ 10 | @EnableConfigServer 11 | @SpringBootApplication 12 | public class ConfigServerApplication { 13 | 14 | public static void main(String[] args) { 15 | new SpringApplicationBuilder(ConfigServerApplication.class) 16 | .run(args); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | version="$1" 4 | 5 | if [[ -z "$version" ]] 6 | then 7 | echo "Usage: build.sh image-version" 8 | exit 1; 9 | else 10 | echo "Start building with image-version: $version" 11 | fi 12 | 13 | mvn clean package -pl dubbo-echo-client,dubbo-echo-server -am 14 | 15 | cd dubbo-echo-client 16 | 17 | docker build -t dubbo-echo-client:${version} . 18 | 19 | docker tag dubbo-echo-client:${version} reg-cnsh-nf.cloud.alipay.com/library/dubbo-echo-client:${version} 20 | 21 | cd ../dubbo-echo-server/ 22 | 23 | docker build -t dubbo-echo-server:${version} . 24 | 25 | docker tag dubbo-echo-server:${version} reg-cnsh-nf.cloud.alipay.com/library/dubbo-echo-server:${version} -------------------------------------------------------------------------------- /hsf-samples-pandoraboot/hsf-echo-server/src/main/java/com/alibaba/edas/HSFProviderApplication.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.edas; 2 | 3 | import com.taobao.pandora.boot.PandoraBootstrap; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | public class HSFProviderApplication { 9 | 10 | public static void main(String[] args) { 11 | // 启动 Pandora Boot 用于加载 Pandora 容器 12 | PandoraBootstrap.run(args); 13 | SpringApplication.run(HSFProviderApplication.class, args); 14 | // 标记服务启动完成,并设置线程 wait。防止用户业务代码运行完毕退出后,导致容器退出。 15 | PandoraBootstrap.markStartupAndWait(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-client/app/web/src/main/resources/META-INF/sofa-samples-client/sofa-samples-springboot2-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-server/app/web/src/main/resources/META-INF/sofa-samples-server/sofa-samples-springboot2-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-client/app/web/src/main/resources/config/application.properties: -------------------------------------------------------------------------------- 1 | #required 2 | spring.application.name=sofa-echo-client 3 | 4 | #set_logging_level 5 | logging.level.com.alipay.sofa.ms=INFO 6 | 7 | logging.path=./logs/client 8 | 9 | # security 10 | endpoints.metrics.enabled=false 11 | endpoints.heapdump.enabled=false 12 | endpoints.env.enabled=false 13 | endpoints.actuator.enabled=false 14 | endpoints.beans.enabled=false 15 | endpoints.configprops.enabled=false 16 | endpoints.dump.enabled=false 17 | endpoints.info.enabled=false 18 | endpoints.logfile.enabled=false 19 | endpoints.trace.enabled=false 20 | endpoints.mappings.enabled=false 21 | endpoints.autoconfig.enabled=false 22 | server.port=8060 -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-server/app/web/src/main/resources/config/application.properties: -------------------------------------------------------------------------------- 1 | #required 2 | spring.application.name=sofa-echo-server 3 | 4 | #set_logging_level 5 | logging.level.com.alipay.sofa.ms=INFO 6 | 7 | logging.path=./logs/server 8 | 9 | server.port=8080 10 | 11 | # security 12 | endpoints.metrics.enabled=false 13 | endpoints.heapdump.enabled=false 14 | endpoints.env.enabled=false 15 | endpoints.actuator.enabled=false 16 | endpoints.beans.enabled=false 17 | endpoints.configprops.enabled=false 18 | endpoints.dump.enabled=false 19 | endpoints.info.enabled=false 20 | endpoints.logfile.enabled=false 21 | endpoints.trace.enabled=false 22 | endpoints.mappings.enabled=false 23 | endpoints.autoconfig.enabled=false -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-client/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | version="$1" 4 | 5 | if [[ -z "$version" ]] 6 | then 7 | echo "Usage: build.sh image-version" 8 | exit 1; 9 | else 10 | echo "Start building with image-version: $version" 11 | fi 12 | 13 | mvn clean package 14 | 15 | docker build -t springcloud-reservation-client:${version} . 16 | 17 | docker tag springcloud-reservation-client:${version} reg-cnsh-nf.cloud.alipay.com/library/springcloud-reservation-client:${version} 18 | docker tag springcloud-reservation-client:${version} ms.docker.hub.com:6003/library/springcloud-reservation-client:${version} 19 | 20 | echo ms.docker.hub.com:6003/library/springcloud-reservation-client:${version} -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-service/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | version="$1" 4 | 5 | if [[ -z "$version" ]] 6 | then 7 | echo "Usage: build.sh image-version" 8 | exit 1; 9 | else 10 | echo "Start building with image-version: $version" 11 | fi 12 | 13 | mvn clean package 14 | 15 | docker build -t springcloud-reservation-service:${version} . 16 | 17 | docker tag springcloud-reservation-service:${version} reg-cnsh-nf.cloud.alipay.com/library/springcloud-reservation-service:${version} 18 | docker tag springcloud-reservation-service:${version} ms.docker.hub.com:6003/library/springcloud-reservation-service:${version} 19 | 20 | echo ms.docker.hub.com:6003/library/springcloud-reservation-service:${version} -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-service/src/main/java/com/alipay/sofa/ms/spring/cloud/reservation/service/entity/Parameter.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.spring.cloud.reservation.service.entity; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Parameter implements Serializable { 6 | public String type; 7 | public Object value; 8 | public String getType() { 9 | return type; 10 | } 11 | public Parameter setType(String type) { 12 | this.type = type; 13 | return this; 14 | } 15 | public Object getValue() { 16 | return value; 17 | } 18 | public Parameter setValue(Object value) { 19 | this.value = value; 20 | return this; 21 | } 22 | } -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=reservation-service 2 | info.id=${spring.application.name} 3 | server.port=${PORT:${SERVER_PORT:0}} 4 | logging.path=/home/admin/logs 5 | logging.level.root=info 6 | logging.level.org.springframework.security=ERROR 7 | logging.level.com.netflix.discovery=ERROR 8 | 9 | server.port=${PORT:8080} 10 | 11 | # database 12 | spring.datasource.url = jdbc:h2:mem:~/reservationdb;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1 13 | spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy 14 | spring.h2.console.enabled = true 15 | spring.h2.console.settings.web-allow-others=true 16 | spring.jpa.properties.hibernate.show_sql=true -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-springcloud/src/main/java/com/alipay/sofa/ms/SpringCloudBootstrap.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Alipay.com Inc. 3 | * Copyright (c) 2004-2020 All Rights Reserved. 4 | */ 5 | package com.alipay.sofa.ms; 6 | 7 | import org.springframework.boot.SpringApplication; 8 | import org.springframework.boot.autoconfigure.SpringBootApplication; 9 | import org.springframework.context.annotation.ImportResource; 10 | 11 | /** 12 | * @author yiji@apache.org 13 | * @version : WebServiceBootstrap.java 14 | */ 15 | @SpringBootApplication 16 | @ImportResource("spring/echo-consumer.xml") 17 | public class SpringCloudBootstrap { 18 | 19 | public static void main(String[] args) { 20 | SpringApplication.run(SpringCloudBootstrap.class, args); 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-echo-server/src/main/java/com/alipay/sofa/ms/EchoProvider.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Alipay.com Inc. 3 | * Copyright (c) 2004-2020 All Rights Reserved. 4 | */ 5 | package com.alipay.sofa.ms; 6 | 7 | import org.springframework.boot.SpringApplication; 8 | import org.springframework.boot.autoconfigure.SpringBootApplication; 9 | import org.springframework.context.annotation.ImportResource; 10 | 11 | /** 12 | * @author yiji@apache.org 13 | * @version : EchoProvider.java, v 0.1 2020年02月24日 2:49 下午 yiji Exp $ 14 | */ 15 | @SpringBootApplication 16 | @ImportResource("spring/echo-provider.xml") 17 | public class EchoProvider { 18 | 19 | public static void main(String[] args) { 20 | SpringApplication.run(EchoProvider.class, args); 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /hsf-samples-pandoraboot/hsf-echo-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | hsf-samples-pandoraboot 7 | com.alipay.sofa.ms 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | hsf-echo-api 13 | 14 | 15 | 8 16 | 8 17 | 18 | 19 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-server/app/endpoint/src/main/java/com/alipay/sofa/ms/endpoint/exception/CommonException.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.endpoint.exception; 2 | 3 | /** 4 | * CommonException 5 | *

6 | * Created by yangguanchao on 16/11/18. 7 | */ 8 | public class CommonException extends Exception{ 9 | 10 | /*** 11 | * you should define you errorCode here, this is only an example 12 | */ 13 | private String errorCode = "CommonError"; 14 | 15 | public CommonException(String message, Throwable cause) { 16 | super(message, cause); 17 | } 18 | 19 | public String getErrorCode() { 20 | return errorCode; 21 | } 22 | 23 | public void setErrorCode(String errorCode) { 24 | this.errorCode = errorCode; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-server/app/endpoint/src/main/java/com/alipay/sofa/ms/endpoint/filter/CommonContainerResponseFilter.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.endpoint.filter; 2 | 3 | import org.jboss.resteasy.plugins.interceptors.CorsFilter; 4 | import javax.ws.rs.container.PreMatching; 5 | import javax.ws.rs.ext.Provider; 6 | import java.util.Set; 7 | 8 | 9 | /** 10 | * to add a self define filter to assure the port of 8080 can access the data exported on 8341 by rest service 11 | * 12 | *

13 | * Created by yangguanchao on 16/9/12. 14 | */ 15 | @Provider 16 | @PreMatching 17 | public class CommonContainerResponseFilter extends CorsFilter { 18 | 19 | public void setAllowedOrigins(Set allowedOrigins) { 20 | this.allowedOrigins = allowedOrigins; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-server/app/endpoint/src/main/java/com/alipay/sofa/ms/endpoint/constants/RestConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Alipay.com Inc. 3 | * Copyright (c) 2004-2015 All Rights Reserved. 4 | */ 5 | package com.alipay.sofa.ms.endpoint.constants; 6 | 7 | import javax.ws.rs.core.MediaType; 8 | 9 | /** 10 | * constants 11 | * 12 | * @author hui.shih 13 | * @version $Id: RestConstants.java, v 0.1 2015-8-24 下午2:28:34 hui.shih Exp $ 14 | */ 15 | public class RestConstants { 16 | 17 | /** 18 | * response encoding 19 | */ 20 | public static final String DEFAULT_CHARSET = "UTF-8"; 21 | /** 22 | * Content-Type 23 | */ 24 | public static final String DEFAULT_CONTENT_TYPE = MediaType.APPLICATION_JSON + ";" + MediaType.CHARSET_PARAMETER + "=" + DEFAULT_CHARSET; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /hsf-samples-pandoraboot/hsf-echo-client/src/main/java/com/alibaba/edas/SimpleController.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.edas; 2 | 3 | import com.alibaba.hsf.edas.HelloService; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestMethod; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | 11 | @RestController 12 | public class SimpleController { 13 | 14 | 15 | @Autowired 16 | private HelloService helloService; 17 | 18 | @RequestMapping(value = "/hsf-echo/{str}", method = RequestMethod.GET) 19 | public String echo(@PathVariable String str) { 20 | return helloService.echo(str); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /springcloud-samples-springboot2/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | version="$1" 4 | 5 | if [[ -z "$version" ]] 6 | then 7 | echo "Usage: build.sh image-version" 8 | exit 1; 9 | else 10 | echo "Start building with image-version: $version" 11 | fi 12 | 13 | mvn clean package -pl springcloud-reservation-client,springcloud-reservation-service -am 14 | 15 | cd springcloud-reservation-client 16 | 17 | docker build -t springcloudreservationclient:${version} . 18 | 19 | docker tag springcloudreservationclient:${version} reg-cnsh-nf.cloud.alipay.com/library/springcloudreservationclient:${version} 20 | 21 | cd ../springcloud-reservation-service/ 22 | 23 | docker build -t springcloudreservationservice:${version} . 24 | 25 | docker tag springcloudreservationservice:${version} reg-cnsh-nf.cloud.alipay.com/library/springcloudreservationservice:${version} -------------------------------------------------------------------------------- /sofa-samples-springboot2/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | version="$1" 4 | 5 | if [[ -z "$version" ]] 6 | then 7 | echo "Usage: build.sh image-version" 8 | exit 1; 9 | else 10 | echo "Start building with image-version: $version" 11 | fi 12 | 13 | cd sofa-echo-server 14 | mvn clean package 15 | 16 | cd ../sofa-echo-client/ 17 | mvn clean package 18 | 19 | cd ../sofa-echo-server 20 | echo "building sofa-echo-server with image-version: $version" 21 | docker build -t sofa-echo-server:${version} . 22 | docker tag sofa-echo-server:${version} reg-cnsh-nf.cloud.alipay.com/library/sofa-echo-server:${version} 23 | 24 | cd ../sofa-echo-client/ 25 | echo "building sofa-echo-client with image-version: $version" 26 | docker build -t sofa-echo-client:${version} . 27 | 28 | docker tag sofa-echo-client:${version} reg-cnsh-nf.cloud.alipay.com/library/sofa-echo-client:${version} -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-hystrix-dashboard/src/main/java/com/alipay/sofa/ms/spring/cloud/hystrix/dashboard/HystrixDashboardApplication.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.spring.cloud.hystrix.dashboard; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 6 | 7 | /** 8 | * open http://localhost:8010/hystrix with stream as http://localhost:9999/actuator/hystrix.stream or http://localhost:9088/turbine.stream 9 | * 10 | * @author yiji@apache.org 11 | */ 12 | @EnableHystrixDashboard 13 | @SpringBootApplication 14 | public class HystrixDashboardApplication { 15 | public static void main(String[] args) { 16 | SpringApplication.run(HystrixDashboardApplication.class, args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-server/app/endpoint/src/main/java/com/alipay/sofa/ms/endpoint/response/RestSampleFacadeResp.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.endpoint.response; 2 | 3 | /** 4 | * the wrapper of the response data in the format of json 5 | *

6 | * Created by yangguanchao on 16/11/18. 7 | */ 8 | public class RestSampleFacadeResp extends AbstractFacadeResp { 9 | 10 | /** 11 | * the data in the response 12 | */ 13 | private T data; 14 | 15 | 16 | public RestSampleFacadeResp() { 17 | super(true); 18 | } 19 | 20 | public T getData() { 21 | return data; 22 | } 23 | 24 | public void setData(T data) { 25 | this.data = data; 26 | } 27 | 28 | @Override 29 | public String toString() { 30 | return "RestSampleFacadeResp{" + 31 | "data=" + data + 32 | '}'; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-config-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.alipay.sofa.ms 7 | springcloud-samples-springboot2 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | springcloud-config-server 13 | 14 | 15 | 16 | 17 | org.springframework.cloud 18 | spring-cloud-config-server 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-service/src/main/java/com/alipay/sofa/ms/spring/cloud/reservation/service/entity/RequestModel.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.spring.cloud.reservation.service.entity; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | public class RequestModel implements Serializable { 8 | public Map attachments; 9 | public List parameters; 10 | 11 | public Map getAttachments() { 12 | return attachments; 13 | } 14 | 15 | public RequestModel setAttachments(Map attachments) { 16 | this.attachments = attachments; 17 | return this; 18 | } 19 | 20 | public List getParameters() { 21 | return parameters; 22 | } 23 | 24 | public RequestModel setParameters( 25 | List parameters) { 26 | this.parameters = parameters; 27 | return this; 28 | } 29 | } -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-client/app/endpoint/src/main/resources/META-INF/sofa-samples-client/sofa-samples-springboot2-endpoint.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-webservice/src/main/java/com/alipay/webservice/WebServiceBootstrap.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Alipay.com Inc. 3 | * Copyright (c) 2004-2020 All Rights Reserved. 4 | */ 5 | package com.alipay.webservice; 6 | 7 | import org.springframework.boot.SpringApplication; 8 | import org.springframework.boot.autoconfigure.SpringBootApplication; 9 | 10 | /** 11 | * @author yiji@apache.org 12 | * @version : WebServiceBootstrap.java 13 | */ 14 | @SpringBootApplication 15 | public class WebServiceBootstrap { 16 | 17 | public static void main(String[] args) { 18 | 19 | // start netty server 20 | new Thread(new Runnable() { 21 | @Override 22 | public void run() { 23 | try { 24 | SocketServerBootstrap.main(args); 25 | } catch (InterruptedException e) { 26 | e.printStackTrace(); 27 | } 28 | } 29 | }).start(); 30 | 31 | SpringApplication.run(WebServiceBootstrap.class, args); 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-service/src/main/java/com/alipay/sofa/ms/spring/cloud/reservation/service/ReservationRepository.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.spring.cloud.reservation.service; 2 | 3 | import com.alipay.sofa.ms.spring.cloud.reservation.service.entity.Reservation; 4 | 5 | import org.springframework.data.repository.PagingAndSortingRepository; 6 | import org.springframework.data.repository.query.Param; 7 | import org.springframework.data.rest.core.annotation.RepositoryRestResource; 8 | import org.springframework.data.rest.core.annotation.RestResource; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * @author yiji@apache.org 14 | */ 15 | @RepositoryRestResource 16 | public interface ReservationRepository extends PagingAndSortingRepository { 17 | 18 | /** 19 | * http://localhost:8000/reservations/search/by-name?name=Tom 20 | * @param reservationName 21 | * @return 22 | */ 23 | @RestResource(path = "by-name") 24 | List findByReservationName(@Param("name") String reservationName); 25 | } 26 | -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-eureka-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.alipay.sofa.ms 7 | springcloud-samples-springboot2 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | springcloud-eureka-server 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-config 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-netflix-eureka-server 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-webservice/src/main/java/com/alipay/webservice/impl/WebServiceConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Alipay.com Inc. 3 | * Copyright (c) 2004-2020 All Rights Reserved. 4 | */ 5 | package com.alipay.webservice.impl; 6 | 7 | import com.alipay.webservice.service.HelloWebService; 8 | import org.apache.cxf.Bus; 9 | import org.apache.cxf.bus.spring.SpringBus; 10 | import org.apache.cxf.jaxws.EndpointImpl; 11 | import org.springframework.context.annotation.Bean; 12 | import org.springframework.context.annotation.Configuration; 13 | 14 | import javax.xml.ws.Endpoint; 15 | 16 | @Configuration 17 | public class WebServiceConfig { 18 | 19 | @Bean(name = Bus.DEFAULT_BUS_ID) 20 | public SpringBus springBus() { 21 | return new SpringBus(); 22 | } 23 | 24 | @Bean 25 | public HelloWebService webService() { 26 | return new HelloWebServiceImpl(); 27 | } 28 | 29 | @Bean 30 | public Endpoint endpoint() { 31 | EndpointImpl endpoint = new EndpointImpl(springBus(), webService()); 32 | endpoint.publish("/ws/api"); 33 | return endpoint; 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 SOFAStack Guides 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-client/app/web/src/main/java/com/alipay/sofa/ms/SOFABootClientSpringApplication.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.context.ApplicationContext; 7 | import org.springframework.context.annotation.ImportResource; 8 | 9 | /** 10 | * @author yiji@apache.org 11 | */ 12 | @ImportResource({"classpath*:META-INF/sofa-samples-client/*.xml"}) 13 | @org.springframework.boot.autoconfigure.SpringBootApplication 14 | public class SOFABootClientSpringApplication { 15 | 16 | // init the logger 17 | private static final Logger logger = LoggerFactory.getLogger(SOFABootClientSpringApplication.class); 18 | 19 | public static void main(String[] args) { 20 | 21 | SpringApplication springApplication = new SpringApplication(SOFABootClientSpringApplication.class); 22 | ApplicationContext applicationContext = springApplication.run(args); 23 | 24 | if (logger.isInfoEnabled()) { 25 | logger.info("application start"); 26 | } 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-server/app/web/src/main/java/com/alipay/sofa/ms/SOFABootServerSpringApplication.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.context.ApplicationContext; 7 | import org.springframework.context.annotation.ImportResource; 8 | 9 | /** 10 | * @author yiji@apache.org 11 | */ 12 | @ImportResource({"classpath*:META-INF/sofa-samples-server/*.xml"}) 13 | @org.springframework.boot.autoconfigure.SpringBootApplication 14 | public class SOFABootServerSpringApplication { 15 | 16 | // init the logger 17 | private static final Logger logger = LoggerFactory.getLogger(SOFABootServerSpringApplication.class); 18 | 19 | public static void main(String[] args) { 20 | 21 | SpringApplication springApplication = new SpringApplication(SOFABootServerSpringApplication.class); 22 | ApplicationContext applicationContext = springApplication.run(args); 23 | 24 | if (logger.isInfoEnabled()) { 25 | logger.info("application start"); 26 | } 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.alipay.sofa.ms 7 | sofastack-mesh-demo 8 | 1.0-SNAPSHOT 9 | 10 | 11 | 4.0.0 12 | 13 | sofa-samples-springboot2 14 | pom 15 | 16 | 17 | sofa-echo-api 18 | sofa-echo-server 19 | sofa-echo-client 20 | 21 | 22 | 23 | 24 | 25 | com.alipay.sofa.ms 26 | sofa-echo-api 27 | ${project.parent.version} 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-server/app/endpoint/src/main/java/com/alipay/sofa/ms/endpoint/model/DemoUserModel.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.endpoint.model; 2 | 3 | /** 4 | * user info model 5 | *

6 | * Created by yangguanchao on 16/8/27. 7 | */ 8 | public class DemoUserModel { 9 | 10 | private int userId; 11 | 12 | private String userName; 13 | 14 | private String realName; 15 | 16 | public String getUserName() { 17 | return userName; 18 | } 19 | 20 | public void setUserName(String userName) { 21 | this.userName = userName; 22 | } 23 | 24 | public String getRealName() { 25 | return realName; 26 | } 27 | 28 | public void setRealName(String realName) { 29 | this.realName = realName; 30 | } 31 | 32 | public int getUserId() { 33 | return userId; 34 | } 35 | 36 | public void setUserId(int userId) { 37 | this.userId = userId; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return "DemoUserModel{" + 43 | "userId=" + userId + 44 | ", userName='" + userName + '\'' + 45 | ", realName='" + realName + '\'' + 46 | '}'; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /springcloud-samples-springboot2/spring-cloud-reservation-gateway/src/main/java/com/alipay/sofa/ms/spring/cloud/reservation/gateway/ReservationGatewayApplication.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Alipay.com Inc. 3 | * Copyright (c) 2004-2020 All Rights Reserved. 4 | */ 5 | package com.alipay.sofa.ms.spring.cloud.reservation.gateway; 6 | 7 | import org.springframework.boot.SpringApplication; 8 | import org.springframework.boot.autoconfigure.SpringBootApplication; 9 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 10 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 11 | import org.springframework.cloud.openfeign.EnableFeignClients; 12 | 13 | /** 14 | * http://localhost:7799/reservations/hello 转发到reservation-service应用8080端口 15 | * http://localhost:8080/reservations/hello 16 | * 17 | * @author yiji@apache.org 18 | * @version : ReservationGatewayApplication.java, v 0.1 2020年02月26日 8:10 下午 yiji Exp $ 19 | */ 20 | @EnableCircuitBreaker 21 | @EnableDiscoveryClient 22 | @EnableFeignClients 23 | @SpringBootApplication 24 | public class ReservationGatewayApplication { 25 | 26 | public static void main(String[] args) { 27 | SpringApplication.run(ReservationGatewayApplication.class, args); 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-server/app/endpoint/src/main/java/com/alipay/sofa/ms/endpoint/response/AbstractFacadeResp.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.endpoint.response; 2 | 3 | /** 4 | * common response data 5 | *

6 | * Created by yangguanchao on 16/09/07. 7 | */ 8 | public class AbstractFacadeResp { 9 | 10 | /** 11 | * the tag to representation the response is a success response or not 12 | */ 13 | private boolean success = false; 14 | 15 | /** 16 | * inner error info 17 | */ 18 | private String resultMsg; 19 | 20 | /** 21 | * the requestId 22 | */ 23 | private String requestId; 24 | 25 | public AbstractFacadeResp(boolean success) { 26 | this.success = success; 27 | } 28 | 29 | public boolean isSuccess() { 30 | return success; 31 | } 32 | 33 | public void setSuccess(boolean success) { 34 | this.success = success; 35 | } 36 | 37 | public String getResultMsg() { 38 | return resultMsg; 39 | } 40 | 41 | public void setResultMsg(String resultMsg) { 42 | this.resultMsg = resultMsg; 43 | } 44 | 45 | public String getRequestId() { 46 | return requestId; 47 | } 48 | 49 | public void setRequestId(String requestId) { 50 | this.requestId = requestId; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-service/src/main/java/com/alipay/sofa/ms/spring/cloud/reservation/service/ReservationServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.spring.cloud.reservation.service; 2 | 3 | import com.alipay.sofa.ms.spring.cloud.reservation.service.entity.Reservation; 4 | import com.google.common.base.Splitter; 5 | 6 | import org.springframework.boot.CommandLineRunner; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | import org.springframework.boot.builder.SpringApplicationBuilder; 9 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 10 | import org.springframework.context.annotation.Bean; 11 | 12 | /** 13 | * @author yiji@apache.org 14 | */ 15 | @EnableDiscoveryClient 16 | @SpringBootApplication 17 | public class ReservationServiceApplication { 18 | @Bean 19 | CommandLineRunner runner(ReservationRepository rr) { 20 | return args -> { 21 | rr.deleteAll(); 22 | 23 | Splitter.on(",").omitEmptyStrings().trimResults().split("Tom, Jerry") 24 | .forEach(x -> rr.save(new Reservation(x))); 25 | rr.findAll().forEach(System.out::println); 26 | }; 27 | } 28 | 29 | public static void main(String[] args) { 30 | new SpringApplicationBuilder(ReservationServiceApplication.class) 31 | .run(args); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-service/src/main/java/com/alipay/sofa/ms/spring/cloud/reservation/service/entity/Reservation.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.spring.cloud.reservation.service.entity; 2 | 3 | import com.google.common.base.MoreObjects; 4 | 5 | import javax.persistence.Entity; 6 | import javax.persistence.GeneratedValue; 7 | import javax.persistence.Id; 8 | 9 | /** 10 | * @author yiji@apache.org 11 | */ 12 | @Entity 13 | public class Reservation { 14 | @Id 15 | @GeneratedValue 16 | private Long id; 17 | 18 | private String reservationName; 19 | 20 | public Reservation() { 21 | } 22 | 23 | public Reservation(String reservationName) { 24 | this.reservationName = reservationName; 25 | } 26 | 27 | public Long getId() { 28 | return id; 29 | } 30 | 31 | public void setId(Long id) { 32 | this.id = id; 33 | } 34 | 35 | public String getReservationName() { 36 | return reservationName; 37 | } 38 | 39 | public void setReservationName(String reservationName) { 40 | this.reservationName = reservationName; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return MoreObjects.toStringHelper(this) 46 | .omitNullValues() 47 | .add("id", id) 48 | .add("reservationName", reservationName) 49 | .toString(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-webservice/src/main/java/com/alipay/webservice/controller/XrResponseController.java: -------------------------------------------------------------------------------- 1 | package com.alipay.webservice.controller; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | @RestController 7 | @RequestMapping("/") 8 | public class XrResponseController { 9 | 10 | @RequestMapping("") 11 | public String getRespMsg() { 12 | return "00000706

CIMT000070from spring " 13 | + "cloudC482021121416133613538C4906221113270051159201000092010000" 15 | + "202106221113275431" 16 | + ".01020210617CN0010001FB.ICP" 18 | + ".X011000000000000000
3001504094"; 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-service/src/main/java/com/alipay/sofa/ms/spring/cloud/reservation/service/entity/Model.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.spring.cloud.reservation.service.entity; 2 | 3 | import java.io.Serializable; 4 | import java.util.Map; 5 | 6 | public class Model implements Serializable { 7 | public Map attachments; 8 | public Object value; 9 | public String exception; 10 | 11 | public Map getAttachments() { 12 | return attachments; 13 | } 14 | 15 | public Model setAttachments(Map attachments) { 16 | this.attachments = attachments; 17 | return this; 18 | } 19 | 20 | public Object getValue() { 21 | return value; 22 | } 23 | 24 | public Model setValue(Object value) { 25 | this.value = value; 26 | return this; 27 | } 28 | 29 | public String getException() { 30 | return exception; 31 | } 32 | 33 | public Model setException(String exception) { 34 | this.exception = exception; 35 | return this; 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return "Model{" + 41 | "attachments=" + attachments + 42 | ", value=" + value + 43 | ", exception='" + exception + '\'' + 44 | '}'; 45 | } 46 | } -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-hystrix-dashboard/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.alipay.sofa.ms 7 | springcloud-samples-springboot2 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | springcloud-hystrix-dashboard 13 | 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-actuator 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-config 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-netflix-eureka-client 26 | 27 | 28 | org.springframework.cloud 29 | spring-cloud-starter-netflix-hystrix-dashboard 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-webservice/src/main/java/com/alipay/webservice/impl/HelloWebServiceImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Alipay.com Inc. 3 | * Copyright (c) 2004-2020 All Rights Reserved. 4 | */ 5 | package com.alipay.webservice.impl; 6 | 7 | 8 | import com.alipay.webservice.service.HelloWebService; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import javax.jws.WebParam; 13 | import javax.jws.WebService; 14 | import java.net.InetAddress; 15 | import java.net.UnknownHostException; 16 | import java.text.SimpleDateFormat; 17 | import java.util.Date; 18 | 19 | @WebService(endpointInterface = "com.alipay.webservice.service.HelloWebService", 20 | targetNamespace = "http://service.webservice.alipay.com/") 21 | public class HelloWebServiceImpl implements HelloWebService { 22 | 23 | private static final Logger LOGGER = LoggerFactory.getLogger(HelloWebServiceImpl.class); 24 | 25 | @Override 26 | public String sayHello(@WebParam(name = "name") String name) { 27 | String now = new SimpleDateFormat("HH:mm:ss").format(new Date()); 28 | String ip = null; 29 | try { 30 | ip = InetAddress.getLocalHost().getHostAddress(); 31 | } catch (UnknownHostException e) { 32 | e.printStackTrace(); 33 | } 34 | String msg = "[" + now + "] Hello " + name 35 | + ", request from consumer, this is web service " + ip; 36 | LOGGER.info(msg); 37 | 38 | return msg; 39 | } 40 | } -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-turbine/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.alipay.sofa.ms 7 | springcloud-samples-springboot2 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | springcloud-turbine 13 | 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-actuator 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-config 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-netflix-eureka-client 26 | 27 | 28 | org.springframework.cloud 29 | spring-cloud-starter-netflix-turbine 30 | 31 | 32 | org.springframework.cloud 33 | spring-cloud-starter-netflix-hystrix 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-springcloud/src/main/java/com/alipay/sofa/ms/controller/DemoClientController.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.controller; 2 | 3 | import com.alipay.sofa.ms.service.EchoService; 4 | import com.alipay.sofa.ms.service.model.SubReq; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.RequestBody; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | /** 12 | * @author tancong date 2021/12/12 6:32 下午 13 | * @description: TODO 14 | */ 15 | @RestController 16 | @RequestMapping("/meshtest") 17 | public class DemoClientController { 18 | 19 | @Autowired 20 | private EchoService echoService; 21 | 22 | @RequestMapping("/dubbo/hello") 23 | public String helloWorld(@RequestParam String message) { 24 | try { 25 | return echoService.echo(message); 26 | } catch (Exception e) { 27 | e.printStackTrace(); 28 | return e.getMessage(); 29 | } 30 | } 31 | 32 | @RequestMapping("/dubbo/add") 33 | public Integer add(@RequestParam int a, @RequestParam int b ) { 34 | return echoService.add(a, b); 35 | } 36 | 37 | @RequestMapping("/dubbo/sub") 38 | public Integer sub(@RequestBody SubReq subReq) { 39 | return echoService.sub(subReq); 40 | } 41 | 42 | } 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-webservice/src/main/java/com/alipay/webservice/controller/WebServiceController.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Alipay.com Inc. 3 | * Copyright (c) 2004-2020 All Rights Reserved. 4 | */ 5 | package com.alipay.webservice.controller; 6 | 7 | import org.apache.cxf.endpoint.Client; 8 | import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.RestController; 13 | 14 | @RestController 15 | @RequestMapping("/meshtest/ws") 16 | public class WebServiceController { 17 | 18 | private static final Logger logger = LoggerFactory.getLogger(WebServiceController.class); 19 | 20 | private static final JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance(); 21 | 22 | @RequestMapping("/test") 23 | public String getRtMsg() { 24 | try { 25 | Client client = dcf.createClient("http://127.0.0.1:8999/services/ws/api?wsdl"); 26 | Object[] objects = new Object[0]; 27 | try { 28 | objects = client.invoke("sayHello", "meshTest"); 29 | logger.info("返回数据:" + objects[0]); 30 | return objects[0].toString(); 31 | } catch (java.lang.Exception e) { 32 | logger.error("error: ", e); 33 | return e.getMessage(); 34 | } 35 | } catch (Exception e) { 36 | logger.error("/meshtest/ws/test error", e); 37 | return e.getMessage(); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-client/app/endpoint/src/main/java/com/alipay/sofa/ms/endpoint/reference/SofaEchoConsumer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Alipay.com Inc. 3 | * Copyright (c) 2004-2020 All Rights Reserved. 4 | */ 5 | package com.alipay.sofa.ms.endpoint.reference; 6 | 7 | import com.alipay.sofa.ms.service.SofaEchoService; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.beans.BeansException; 11 | import org.springframework.context.ApplicationContext; 12 | import org.springframework.context.ApplicationContextAware; 13 | 14 | import java.util.concurrent.TimeUnit; 15 | 16 | /** 17 | * @author yiji 18 | * @version : EchoConsumer.java, v 0.1 2020年04月21日 2:44 下午 yiji Exp $ 19 | */ 20 | public class SofaEchoConsumer implements ApplicationContextAware { 21 | 22 | private static final Logger logger = LoggerFactory.getLogger(SofaEchoConsumer.class); 23 | 24 | @Override 25 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 26 | SofaEchoService echoService = (SofaEchoService) applicationContext.getBean("echoService"); // get remote service proxy 27 | new Thread(() -> { 28 | for (; ; ) { 29 | try { 30 | TimeUnit.SECONDS.sleep(1L); 31 | String status1 = echoService.echo("Hello world!"); 32 | logger.info(">>>>>>>> echo result: " + status1); 33 | } catch (Exception e) { 34 | logger.error(">>>>>>>> echo result: " + e.getMessage()); 35 | } 36 | } 37 | }).start(); 38 | } 39 | } -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-springcloud/src/main/resources/spring/echo-consumer.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 26 | 27 | 28 | 29 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-server/app/endpoint/src/main/resources/META-INF/sofa-samples-server/sofa-samples-springboot2-endpoint.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | http://localhost:8080 15 | http://localhost:8341 16 | 17 | chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-echo-server/src/main/java/com/alipay/sofa/ms/service/EchoServiceImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Alipay.com Inc. 3 | * Copyright (c) 2004-2020 All Rights Reserved. 4 | */ 5 | package com.alipay.sofa.ms.service; 6 | 7 | import com.alipay.sofa.ms.service.model.SubReq; 8 | import org.apache.dubbo.rpc.RpcContext; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import java.text.SimpleDateFormat; 13 | import java.util.Date; 14 | 15 | /** 16 | * @author yiji@apache.org 17 | * @version : EchoServiceImpl.java, v 0.1 2020年02月24日 2:47 下午 yiji Exp $ 18 | */ 19 | public class EchoServiceImpl implements EchoService { 20 | 21 | private static final Logger LOGGER = LoggerFactory.getLogger(EchoServiceImpl.class); 22 | 23 | public String echo(String message) { 24 | String now = new SimpleDateFormat("HH:mm:ss").format(new Date()); 25 | LOGGER.info("[" + now + "] Hello " + message 26 | + ", request from consumer: " + RpcContext.getContext().getRemoteAddress()); 27 | return "[dubbo] hello " + message + "!"; 28 | } 29 | 30 | @Override 31 | public Integer add(Integer a, Integer b) { 32 | String now = new SimpleDateFormat("HH:mm:ss").format(new Date()); 33 | LOGGER.info("[" + now + "] add (" + a + "+" + b + ") =" + (a+b) 34 | + ", request from consumer: " + RpcContext.getContext().getRemoteAddress()); 35 | return a + b; 36 | } 37 | 38 | @Override 39 | public Integer sub(SubReq subReq) { 40 | String now = new SimpleDateFormat("HH:mm:ss").format(new Date()); 41 | LOGGER.info("[" + now + "] add (" + subReq.a + "-" + subReq.b + ") =" + (subReq.a+subReq.b) 42 | + ", request from consumer: " + RpcContext.getContext().getRemoteAddress()); 43 | return subReq.a+subReq.b; 44 | } 45 | } -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-echo-client/src/main/resources/spring/echo-consumer.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /springcloud-samples-springboot2/spring-cloud-reservation-gateway/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 7799 3 | 4 | spring: 5 | application: 6 | name: reservation-gateway 7 | cloud: 8 | gateway: 9 | routes: 10 | - id: dingtalk_route 11 | uri: lb://reservation-service 12 | # 对应跟钉钉对接不需要验证的部分,现在同样是在手机端,与 /pro/v1/mobile/** 相同 13 | # uri: http://localhost:2005 14 | predicates: 15 | - Path=/reservations/** 16 | #- Path=/pro/v1/dingtalk/** 17 | # filters: 18 | # - name: RequestRateLimiter 19 | # args: 20 | # redis-rate-limiter.replenishRate: 100 21 | # redis-rate-limiter.burstCapacity: 200 22 | # key-resolver: "#{@ipKeyResolver}" 23 | - id: mobile_route 24 | uri: lb://pro-web-dingtalk 25 | # uri: http://localhost:2005 26 | predicates: 27 | - Path=/pro/v1/mobile/** 28 | # filters: 29 | # - name: RequestRateLimiter 30 | # args: 31 | # redis-rate-limiter.replenishRate: 100 32 | # redis-rate-limiter.burstCapacity: 200 33 | # key-resolver: "#{@ipKeyResolver}" 34 | ## 默认过滤器,目前配置了熔断器 35 | default-filters: 36 | # - name: Hystrix 37 | # args: 38 | # name: slowPaas 39 | # fallbackUri: forward:/serviceFallback 40 | # consul: 41 | # host: 10.27.0.236 42 | # enabled: true 43 | # port: 8500 44 | # discovery: 45 | # health-check-interval: 15s 46 | ## 编码方式处理 47 | http: 48 | encoding: 49 | charset: UTF-8 50 | enabled: true 51 | force: true 52 | ## 默认日志等级 53 | logging: 54 | level: 55 | root: info 56 | io.lettuce.core.protocol.RedisStateMachine: info 57 | path: /home/admin/logs -------------------------------------------------------------------------------- /springcloud-samples-springboot2/spring-cloud-reservation-gateway/src/main/resources/application-dev.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 7799 3 | 4 | spring: 5 | application: 6 | name: reservation-gateway 7 | cloud: 8 | gateway: 9 | routes: 10 | - id: dingtalk_route 11 | uri: lb://reservation-service 12 | # 对应跟钉钉对接不需要验证的部分,现在同样是在手机端,与 /pro/v1/mobile/** 相同 13 | # uri: http://localhost:2005 14 | predicates: 15 | - Path=/reservations/** 16 | #- Path=/pro/v1/dingtalk/** 17 | # filters: 18 | # - name: RequestRateLimiter 19 | # args: 20 | # redis-rate-limiter.replenishRate: 100 21 | # redis-rate-limiter.burstCapacity: 200 22 | # key-resolver: "#{@ipKeyResolver}" 23 | - id: mobile_route 24 | uri: lb://pro-web-dingtalk 25 | # uri: http://localhost:2005 26 | predicates: 27 | - Path=/pro/v1/mobile/** 28 | # filters: 29 | # - name: RequestRateLimiter 30 | # args: 31 | # redis-rate-limiter.replenishRate: 100 32 | # redis-rate-limiter.burstCapacity: 200 33 | # key-resolver: "#{@ipKeyResolver}" 34 | ## 默认过滤器,目前配置了熔断器 35 | default-filters: 36 | # - name: Hystrix 37 | # args: 38 | # name: slowPaas 39 | # fallbackUri: forward:/serviceFallback 40 | # consul: 41 | # host: 10.27.0.236 42 | # enabled: true 43 | # port: 8500 44 | # discovery: 45 | # health-check-interval: 15s 46 | ## 编码方式处理 47 | http: 48 | encoding: 49 | charset: UTF-8 50 | enabled: true 51 | force: true 52 | ## 默认日志等级 53 | logging: 54 | level: 55 | root: info 56 | io.lettuce.core.protocol.RedisStateMachine: info 57 | path: ./logs/gateway -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-echo-client/src/main/java/com/alipay/sofa/ms/EchoConsumer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Alipay.com Inc. 3 | * Copyright (c) 2004-2020 All Rights Reserved. 4 | */ 5 | package com.alipay.sofa.ms; 6 | 7 | import com.alipay.sofa.ms.service.EchoService; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.beans.BeansException; 11 | import org.springframework.boot.SpringApplication; 12 | import org.springframework.boot.autoconfigure.SpringBootApplication; 13 | import org.springframework.context.ApplicationContext; 14 | import org.springframework.context.ApplicationContextAware; 15 | import org.springframework.context.annotation.ImportResource; 16 | 17 | import java.util.concurrent.TimeUnit; 18 | 19 | /** 20 | * @author yiji@apache.org 21 | * @version : EchoConsumer.java, v 0.1 2020年02月24日 4:23 下午 yiji Exp $ 22 | */ 23 | @SpringBootApplication 24 | @ImportResource("spring/echo-consumer.xml") 25 | public class EchoConsumer implements ApplicationContextAware { 26 | 27 | private static final Logger LOGGER = LoggerFactory.getLogger(EchoConsumer.class); 28 | 29 | public static void main(String[] args) { 30 | SpringApplication.run(EchoConsumer.class, args); 31 | } 32 | 33 | @Override 34 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 35 | EchoService echoService = (EchoService) applicationContext.getBean("echoService"); // get remote service proxy 36 | new Thread(() -> { 37 | for (; ; ) { 38 | try { 39 | TimeUnit.SECONDS.sleep(1L); 40 | String status1 = echoService.echo("Hello world!"); 41 | LOGGER.info(">>>>>>>> echo result: " + status1); 42 | } catch (Exception e) { 43 | LOGGER.error(">>>>>>>> echo result: " + e.getMessage()); 44 | } 45 | } 46 | }).start(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /hsf-samples-pandoraboot/hsf-echo-server/src/test/java/com/alibaba/edas/HelloServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.edas; 2 | 3 | import com.alibaba.boot.hsf.annotation.HSFConsumer; 4 | import com.alibaba.hsf.edas.HelloService; 5 | import com.taobao.hsf.remoting.service.GenericService; 6 | import com.taobao.pandora.boot.test.junit4.DelegateTo; 7 | import com.taobao.pandora.boot.test.junit4.PandoraBootRunner; 8 | import junit.framework.TestCase; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | import org.mockito.AdditionalAnswers; 12 | import org.mockito.Mockito; 13 | import org.springframework.boot.test.context.SpringBootTest; 14 | import org.springframework.stereotype.Component; 15 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 16 | 17 | @RunWith(PandoraBootRunner.class) 18 | @DelegateTo(SpringJUnit4ClassRunner.class) 19 | // 加载测试需要的类,一定要加入 Spring Boot 的启动类,其次需要加入本类。 20 | @SpringBootTest(classes = {HSFProviderApplication.class, HelloServiceTest.class}) 21 | @Component 22 | public class HelloServiceTest { 23 | 24 | /** 25 | * 当使用 @HSFConsumer 时,一定要在 @SpringBootTest 类加载中,加载本类,通过本类来注入对象,否则当做泛化时,会出现类转换异常。 26 | */ 27 | @HSFConsumer(generic = true) 28 | HelloService helloService; 29 | 30 | //普通的调用 31 | @Test 32 | public void testInvoke() { 33 | TestCase.assertEquals("hello world", helloService.echo("hello world")); 34 | } 35 | 36 | //泛化调用 37 | @Test 38 | public void testGenericInvoke() { 39 | GenericService service = (GenericService) helloService; 40 | Object result = service.$invoke("echo", new String[]{"java.lang.String"}, new Object[]{"hello world"}); 41 | TestCase.assertEquals("hello world", result); 42 | } 43 | 44 | //返回值 Mock 45 | @Test 46 | public void testMock() { 47 | HelloService mock = Mockito.mock(HelloService.class, AdditionalAnswers.delegatesTo(helloService)); 48 | Mockito.when(mock.echo("")).thenReturn("beta"); 49 | TestCase.assertEquals("beta", mock.echo("")); 50 | } 51 | } -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-echo-server/src/main/resources/spring/echo-provider.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-client/app/endpoint/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | 7 | com.alipay.sofa.ms 8 | sofa-echo-client 9 | 1.0-SNAPSHOT 10 | ../../pom.xml 11 | 12 | 13 | sofa-echo-client-endpoint 14 | 15 | http://maven.apache.org 16 | 17 | 18 | 19 | 20 | com.alipay.sofa.ms 21 | sofa-echo-api 22 | 23 | 24 | 25 | 26 | org.springframework 27 | spring-core 28 | 29 | 30 | org.springframework 31 | spring-context 32 | 33 | 34 | 35 | 36 | com.alipay.sofa 37 | rest-enterprise-sofa-boot-starter 38 | 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-autoconfigure 43 | 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-starter-logging 48 | 49 | 50 | 51 | com.alipay.sofa 52 | rpc-enterprise-sofa-boot-starter 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-server/app/endpoint/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | 7 | com.alipay.sofa.ms 8 | sofa-echo-server 9 | 1.0-SNAPSHOT 10 | ../../pom.xml 11 | 12 | 13 | sofa-echo-server-endpoint 14 | 15 | http://maven.apache.org 16 | 17 | 18 | 19 | 20 | com.alipay.sofa.ms 21 | sofa-echo-api 22 | 23 | 24 | 25 | 26 | org.springframework 27 | spring-core 28 | 29 | 30 | org.springframework 31 | spring-context 32 | 33 | 34 | 35 | 36 | com.alipay.sofa 37 | rest-enterprise-sofa-boot-starter 38 | 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-autoconfigure 43 | 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-starter-logging 48 | 49 | 50 | 51 | com.alipay.sofa 52 | rpc-enterprise-sofa-boot-starter 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-service/src/main/java/com/alipay/sofa/ms/spring/cloud/reservation/service/controller/HelloWorldController.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Alipay.com Inc. 3 | * Copyright (c) 2004-2020 All Rights Reserved. 4 | */ 5 | package com.alipay.sofa.ms.spring.cloud.reservation.service.controller; 6 | 7 | import com.alibaba.fastjson.JSON; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | import com.alipay.sofa.ms.spring.cloud.reservation.service.entity.Model; 11 | import com.alipay.sofa.ms.spring.cloud.reservation.service.entity.RequestModel; 12 | import com.alipay.sofa.ms.spring.cloud.reservation.service.entity.SubReq; 13 | import org.springframework.web.bind.annotation.*; 14 | 15 | /** 16 | * @author yiji@apache.org 17 | * @version : HelloWorldController.java, v 0.1 2020年02月26日 8:32 下午 yiji Exp $ 18 | */ 19 | @RestController 20 | @RequestMapping("/reservations") 21 | public class HelloWorldController { 22 | 23 | @RequestMapping("/hello") 24 | public String helloWorld() { 25 | return JSON.toJSONString( "hello world!"); 26 | } 27 | 28 | @RequestMapping("/model") 29 | @ResponseBody 30 | public Model model(@RequestBody RequestModel model){ 31 | System.out.println(model.toString()); 32 | return new Model().setValue("hello world!"); 33 | } 34 | 35 | @RequestMapping("/echo") 36 | public String echo(String message){ 37 | System.out.println(message); 38 | return "[spring cloud] hello " + message + "!"; 39 | } 40 | 41 | @RequestMapping("/{message}/echo") 42 | public String echo2(@PathVariable String message){ 43 | System.out.println(message); 44 | return "[spring cloud] hello " + message + "!"; 45 | } 46 | 47 | @RequestMapping("/add") 48 | public String add(@RequestParam int a, @RequestParam int b ) { 49 | return String.valueOf(a + b); 50 | } 51 | 52 | @RequestMapping("/sub") 53 | public String sub(@RequestBody SubReq subReq) { 54 | return String.valueOf(subReq.a - subReq.b); 55 | } 56 | } -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-server/app/endpoint/src/main/java/com/alipay/sofa/ms/endpoint/exception/SofaRestExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.endpoint.exception; 2 | 3 | import com.alibaba.common.lang.StringUtil; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.stereotype.Component; 7 | 8 | import javax.ws.rs.core.Response; 9 | import javax.ws.rs.ext.ExceptionMapper; 10 | import javax.ws.rs.ext.Provider; 11 | import java.text.MessageFormat; 12 | import java.util.Arrays; 13 | import java.util.HashMap; 14 | import java.util.Map; 15 | 16 | /** 17 | * SofaRestExceptionHandler 18 | *

19 | * Sofa Rest exception handler, it is better for you to define your owner exception handler 20 | *

21 | * Created by yangguanchao on 16/11/18. 22 | */ 23 | @Component 24 | @Provider 25 | public class SofaRestExceptionHandler implements ExceptionMapper { 26 | 27 | private static final Logger logger = LoggerFactory 28 | .getLogger(SofaRestExceptionHandler.class); 29 | 30 | 31 | public static final String ERROR_CODE_KEY = "code"; 32 | public static final String MESSAGES_KEY = "messages"; 33 | private static final int ERROR_STATUS = 451; 34 | 35 | @Override 36 | public Response toResponse(Throwable ex) { 37 | String errorCode = "NO Common Error Code!!"; 38 | String message = ""; 39 | 40 | if (ex instanceof CommonException) { 41 | CommonException casted = (CommonException) ex; 42 | errorCode = StringUtil.isBlank(casted.getErrorCode()) ? errorCode : casted 43 | .getErrorCode(); 44 | message = casted.getMessage(); 45 | 46 | } else { 47 | errorCode = "NO Common Error Code!!"; 48 | message = MessageFormat.format("Unknown Exception[{0}]", ex.getMessage()); 49 | } 50 | 51 | logger.error("web api error!", ex); 52 | logger.error("errorCode={0}, message={1}", errorCode, message); 53 | 54 | Map errorMap = new HashMap(); 55 | errorMap.put(ERROR_CODE_KEY, errorCode); 56 | errorMap.put(MESSAGES_KEY, Arrays.asList(message)); 57 | return Response.status(ERROR_STATUS).entity(errorMap).build(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-webservice/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.alipay.sofa.ms 7 | dubbo-samples-springboot2 8 | 1.0-SNAPSHOT 9 | 10 | 11 | 4.0.0 12 | 13 | dubbo-webservice 14 | 15 | 16 | 8 17 | 8 18 | 19 | 20 | 21 | 22 | 23 | org.slf4j 24 | log4j-over-slf4j 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter 30 | 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-web-services 36 | 37 | 38 | 39 | 40 | org.apache.cxf 41 | cxf-spring-boot-starter-jaxws 42 | 3.3.10 43 | 44 | 45 | 46 | io.netty 47 | netty-all 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | org.springframework.boot 56 | spring-boot-maven-plugin 57 | 2.0.5.RELEASE 58 | 59 | 60 | 61 | repackage 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-server/app/endpoint/src/main/java/com/alipay/sofa/ms/endpoint/impl/SampleRestFacadeRestImpl.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.endpoint.impl; 2 | 3 | 4 | import com.alipay.sofa.ms.endpoint.exception.CommonException; 5 | import com.alipay.sofa.ms.endpoint.facade.SampleRestFacade; 6 | import com.alipay.sofa.ms.endpoint.model.DemoUserModel; 7 | import com.alipay.sofa.ms.endpoint.response.RestSampleFacadeResp; 8 | 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import javax.ws.rs.PathParam; 13 | 14 | /** 15 | * rest service interface impl 16 | *

17 | * sofa rest resource to deal with rest request 18 | *

19 | * Created by yangguanchao on 16/11/18. 20 | */ 21 | public class SampleRestFacadeRestImpl implements SampleRestFacade { 22 | 23 | private static final Logger logger = LoggerFactory.getLogger("MDC-EXAMPLE"); 24 | 25 | public RestSampleFacadeResp userInfo(@PathParam("userName") String userName) throws CommonException { 26 | 27 | DemoUserModel demoUserModel = new DemoUserModel(); 28 | demoUserModel.setRealName("Real " + userName); 29 | demoUserModel.setUserName(userName); 30 | 31 | logger.info("rest mdc example"); 32 | 33 | RestSampleFacadeResp result = new RestSampleFacadeResp(); 34 | result.setData(demoUserModel); 35 | result.setSuccess(true); 36 | return result; 37 | } 38 | 39 | public RestSampleFacadeResp addUserInfo(DemoUserModel user) { 40 | int id = 1; 41 | RestSampleFacadeResp result = new RestSampleFacadeResp(); 42 | result.setData(id); 43 | result.setSuccess(true); 44 | return result; 45 | } 46 | 47 | public RestSampleFacadeResp deleteUser(String userName) { 48 | int deletedCount = 1; 49 | RestSampleFacadeResp result = new RestSampleFacadeResp(); 50 | result.setData(deletedCount); 51 | result.setSuccess(true); 52 | return result; 53 | } 54 | 55 | public RestSampleFacadeResp updateUser(@PathParam("userName") String userName, DemoUserModel demoUserModel) { 56 | int updatedCount = 1; 57 | RestSampleFacadeResp result = new RestSampleFacadeResp(); 58 | result.setData(updatedCount); 59 | result.setSuccess(true); 60 | return result; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-server/app/endpoint/src/main/java/com/alipay/sofa/ms/endpoint/facade/SampleRestFacade.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.endpoint.facade; 2 | 3 | 4 | import com.alipay.sofa.ms.endpoint.constants.URLConstants; 5 | import com.alipay.sofa.ms.endpoint.exception.CommonException; 6 | import com.alipay.sofa.ms.endpoint.constants.RestConstants; 7 | import com.alipay.sofa.ms.endpoint.model.DemoUserModel; 8 | import com.alipay.sofa.ms.endpoint.response.RestSampleFacadeResp; 9 | 10 | import javax.ws.rs.*; 11 | 12 | /** 13 | * rest service interface 14 | *

15 | * the get, post, delete, put method each deal with the function of query info, add info, delete info and update info 16 | *

17 | *

18 | *

19 | * Created by yangguanchao on 16/11/18. 20 | */ 21 | @Path(URLConstants.REST_API_PEFFIX + "/users") 22 | @Consumes(RestConstants.DEFAULT_CONTENT_TYPE) 23 | @Produces(RestConstants.DEFAULT_CONTENT_TYPE) 24 | public interface SampleRestFacade { 25 | 26 | /** 27 | * query 28 | * 29 | * http://localhost:8341/webapi/users/xiaoming 30 | * 31 | * @param userName 32 | * @return 33 | */ 34 | @GET 35 | @Path("/{userName}") 36 | public RestSampleFacadeResp userInfo(@PathParam("userName") String userName) throws CommonException; 37 | 38 | /*** 39 | 40 | * 41 | * @param userName user's account name 42 | * @param realName user's real name 43 | * @return 44 | */ 45 | 46 | /** 47 | * add 48 | * 49 | * you can use postman to mock the post request 50 | *

51 | * http://localhost:8341/webapi/users 52 | *

53 | * post method add a user whose information is in the http request 54 | * @param user 55 | * @return 56 | */ 57 | @POST 58 | @Path("/") 59 | public RestSampleFacadeResp addUserInfo(DemoUserModel user); 60 | 61 | /** 62 | * delete 63 | * 64 | * @param userName 65 | * @return 66 | */ 67 | @DELETE 68 | @Path("/{userName}") 69 | public RestSampleFacadeResp deleteUser(@PathParam("userName") String userName); 70 | 71 | /*** 72 | * update 73 | * 74 | * @param userName 75 | * @param demoUserModel 76 | * @return 77 | */ 78 | @PUT 79 | @Path("/{userName}") 80 | public RestSampleFacadeResp updateUser(@PathParam("userName") String userName, DemoUserModel demoUserModel); 81 | } 82 | -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-client/src/main/java/com/alipay/sofa/ms/spring/cloud/reservation/client/ReservationClientApplication.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.spring.cloud.reservation.client; 2 | 3 | import org.springframework.boot.CommandLineRunner; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 7 | import org.springframework.cloud.client.discovery.DiscoveryClient; 8 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 9 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 10 | import org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration; 11 | import org.springframework.cloud.openfeign.EnableFeignClients; 12 | import org.springframework.context.annotation.Bean; 13 | import org.springframework.context.annotation.Primary; 14 | import org.springframework.web.client.RestTemplate; 15 | 16 | /** 17 | * Try the following urls to access reservation service indirectly 18 | * http://localhost:9999/reservations/names or http://localhost:9999/reservations/names-feign to access the reservation service 19 | * 20 | *
21 | * 22 | * Try the following urls to access reservation service directly, i.e. as zuul proxy 23 | * http://localhost:9999/reservation-service/reservations 24 | * 25 | * @author yiji@apache.org 26 | */ 27 | @EnableCircuitBreaker 28 | @EnableDiscoveryClient 29 | @EnableFeignClients 30 | @SpringBootApplication 31 | public class ReservationClientApplication { 32 | @Bean 33 | CommandLineRunner runner(DiscoveryClient dc) { 34 | return args -> { 35 | dc.getInstances("reservation-service") 36 | .forEach(si -> System.out.println(String.format( 37 | "Found %s %s:%s", si.getServiceId(), si.getHost(), si.getPort()))); 38 | }; 39 | } 40 | 41 | /** 42 | * The load balanced rest template, it will be customized with load balancer interceptors 43 | * @see LoadBalancerAutoConfiguration 44 | */ 45 | @LoadBalanced 46 | @Bean 47 | RestTemplate loadBalanced() { 48 | return new RestTemplate(); 49 | } 50 | 51 | /** 52 | * The normal rest template 53 | */ 54 | @Primary 55 | @Bean 56 | RestTemplate restTemplate() { 57 | return new RestTemplate(); 58 | } 59 | 60 | public static void main(String[] args) { 61 | SpringApplication.run(ReservationClientApplication.class, args); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | com.alipay.sofa.ms 8 | sofa-samples-springboot2 9 | 1.0-SNAPSHOT 10 | 11 | 12 | com.alipay.sofa.ms 13 | sofa-echo-client 14 | 1.0-SNAPSHOT 15 | pom 16 | 17 | sofa-samples-springboot2 18 | http://maven.apache.org 19 | 20 | 21 | 22 | 23 | 24 | com.alipay.sofa 25 | sofaboot-enterprise-dependencies 26 | 3.3.2 27 | pom 28 | import 29 | 30 | 31 | 32 | 33 | com.alipay.sofa.ms 34 | sofa-echo-client-endpoint 35 | 1.0-SNAPSHOT 36 | 37 | 38 | com.alipay.sofa.ms 39 | sofa-echo-client-web 40 | 1.0-SNAPSHOT 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.apache.maven.plugins 49 | maven-surefire-plugin 50 | 2.10 51 | 52 | 53 | **/*Tests.java 54 | **/*Test.java 55 | 56 | 57 | **/Abstract*.java 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | app/endpoint 66 | app/web 67 | 68 | 69 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | com.alipay.sofa.ms 8 | sofa-samples-springboot2 9 | 1.0-SNAPSHOT 10 | 11 | 12 | com.alipay.sofa.ms 13 | sofa-echo-server 14 | 1.0-SNAPSHOT 15 | pom 16 | 17 | sofa-samples-springboot2 18 | http://maven.apache.org 19 | 20 | 21 | 22 | 23 | 24 | com.alipay.sofa 25 | sofaboot-enterprise-dependencies 26 | 27 | 3.2.2 28 | pom 29 | import 30 | 31 | 32 | 33 | 34 | com.alipay.sofa.ms 35 | sofa-echo-server-endpoint 36 | 1.0-SNAPSHOT 37 | 38 | 39 | com.alipay.sofa.ms 40 | sofa-echo-server-web 41 | 1.0-SNAPSHOT 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | org.apache.maven.plugins 50 | maven-surefire-plugin 51 | 2.10 52 | 53 | 54 | **/*Tests.java 55 | **/*Test.java 56 | 57 | 58 | **/Abstract*.java 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | app/endpoint 67 | app/web 68 | 69 | 70 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.alipay.sofa.ms 7 | sofastack-mesh-demo 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | dubbo-samples-springboot2 13 | pom 14 | 15 | 16 | 17 | 2.7.5 18 | 2.12.0 19 | 20 | 21 | 22 | dubbo-echo-api 23 | dubbo-echo-client 24 | dubbo-echo-server 25 | dubbo-webservice 26 | dubbo-springcloud 27 | 28 | 29 | 30 | 31 | 32 | com.alipay.sofa.ms 33 | dubbo-echo-api 34 | ${project.parent.version} 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-dependencies 40 | 2.0.8.RELEASE 41 | import 42 | pom 43 | 44 | 45 | 46 | javax.validation 47 | validation-api 48 | 2.0.1.Final 49 | 50 | 51 | 52 | org.apache.dubbo 53 | dubbo 54 | ${dubbo.version} 55 | 56 | 57 | 58 | org.apache.curator 59 | curator-framework 60 | ${curator.version} 61 | 62 | 63 | org.apache.curator 64 | curator-recipes 65 | ${curator.version} 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-server/app/web/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | 7 | com.alipay.sofa.ms 8 | sofa-echo-server 9 | 1.0-SNAPSHOT 10 | ../../pom.xml 11 | 12 | 13 | sofa-echo-server-web 14 | 15 | jar 16 | http://maven.apache.org 17 | 18 | 19 | 20 | 21 | com.alipay.sofa.ms 22 | sofa-echo-server-endpoint 23 | 24 | 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-logging 34 | 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-test 40 | test 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.boot 49 | 50 | spring-boot-maven-plugin 51 | 1.4.2.RELEASE 52 | 53 | 54 | ../../target 55 | executable 56 | 57 | 58 | 59 | 60 | repackage 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-client/app/web/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | 7 | com.alipay.sofa.ms 8 | sofa-echo-client 9 | 1.0-SNAPSHOT 10 | ../../pom.xml 11 | 12 | 13 | sofa-echo-client-web 14 | sofa-echo-client-web 15 | 16 | jar 17 | http://maven.apache.org 18 | 19 | 20 | 21 | 22 | com.alipay.sofa.ms 23 | sofa-echo-client-endpoint 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-web 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-logging 35 | 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | org.springframework.boot 50 | 51 | spring-boot-maven-plugin 52 | 1.4.2.RELEASE 53 | 54 | 55 | ../../target 56 | executable 57 | 58 | 59 | 60 | 61 | repackage 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.alipay.sofa.ms 8 | sofastack-mesh-demo 9 | pom 10 | 微服务相关所有的 demo 项目集合 11 | 12 | dubbo-samples-springboot2 13 | springcloud-samples-springboot2 14 | sofa-samples-springboot2 15 | hsf-samples-pandoraboot 16 | 17 | 1.0-SNAPSHOT 18 | 19 | 20 | 21 | 22 | 23 | com.alipay.sofa 24 | sofa-registry-cloud-all 25 | 1.2.8 26 | 27 | 28 | 29 | com.alipay.sofa 30 | tracer-enterprise-sofa-boot-starter 31 | 3.2.3.JST.1 32 | 33 | 34 | sofa-common-tools 35 | com.alipay.sofa.common 36 | 37 | 38 | 39 | 40 | com.alipay.sofa.common 41 | sofa-common-tools 42 | 1.0.17 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | org.apache.maven.plugins 51 | maven-compiler-plugin 52 | 3.6.0 53 | 54 | 8 55 | 8 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | alipay-cloud-server@public 64 | http://mvn.cloud.alipay.com/nexus/content/groups/open 65 | 66 | false 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /hsf-samples-pandoraboot/hsf-echo-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | hsf-samples-pandoraboot 7 | com.alipay.sofa.ms 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | hsf-echo-client 13 | 14 | 15 | 16 | 17 | com.alipay.sofa.ms 18 | hsf-echo-api 19 | 20 | 21 | 22 | com.alibaba.boot 23 | pandora-hsf-spring-boot-starter 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | com.taobao.pandora 31 | taobao-hsf.sar 32 | 33 | 34 | 35 | 36 | com.taobao.pandora 37 | pandora-boot-test 38 | test 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-starter-test 43 | test 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | org.apache.maven.plugins 52 | maven-compiler-plugin 53 | 3.7.0 54 | 55 | 1.8 56 | 1.8 57 | 58 | 59 | 60 | com.taobao.pandora 61 | pandora-boot-maven-plugin 62 | 2.1.11.8 63 | 64 | 65 | package 66 | 67 | repackage 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /hsf-samples-pandoraboot/hsf-echo-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | hsf-samples-pandoraboot 7 | com.alipay.sofa.ms 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | hsf-echo-server 13 | 14 | 15 | 16 | 17 | com.alipay.sofa.ms 18 | hsf-echo-api 19 | 20 | 21 | 22 | com.alibaba.boot 23 | pandora-hsf-spring-boot-starter 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | com.taobao.pandora 31 | taobao-hsf.sar 32 | 33 | 34 | 35 | 36 | com.taobao.pandora 37 | pandora-boot-test 38 | test 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-starter-test 43 | test 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | org.apache.maven.plugins 52 | maven-compiler-plugin 53 | 3.7.0 54 | 55 | 1.8 56 | 1.8 57 | 58 | 59 | 60 | com.taobao.pandora 61 | pandora-boot-maven-plugin 62 | 2.1.11.8 63 | 64 | 65 | package 66 | 67 | repackage 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-client/src/main/java/com/alipay/sofa/ms/spring/cloud/reservation/client/service/ReservationService.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.spring.cloud.reservation.client.service; 2 | 3 | import com.fasterxml.jackson.databind.DeserializationFeature; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import com.alipay.sofa.ms.spring.cloud.reservation.client.dto.Reservation; 6 | import com.alipay.sofa.ms.spring.cloud.reservation.client.service.ReservationService.CustomerClientConfiguration; 7 | import feign.Logger; 8 | import feign.codec.Decoder; 9 | import java.util.Arrays; 10 | import org.springframework.beans.factory.ObjectFactory; 11 | import org.springframework.boot.autoconfigure.http.HttpMessageConverters; 12 | import org.springframework.cloud.openfeign.FeignClient; 13 | import org.springframework.cloud.openfeign.support.ResponseEntityDecoder; 14 | import org.springframework.cloud.openfeign.support.SpringDecoder; 15 | import org.springframework.context.annotation.Bean; 16 | import org.springframework.context.annotation.Configuration; 17 | import org.springframework.hateoas.MediaTypes; 18 | import org.springframework.hateoas.Resources; 19 | import org.springframework.hateoas.config.EnableHypermediaSupport; 20 | import org.springframework.hateoas.hal.Jackson2HalModule; 21 | import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; 22 | import org.springframework.web.bind.annotation.RequestMapping; 23 | import org.springframework.web.bind.annotation.RequestMethod; 24 | 25 | @FeignClient(value = "reservation-service", configuration = CustomerClientConfiguration.class) 26 | public interface ReservationService { 27 | @RequestMapping(value = "/reservations", method = RequestMethod.GET) 28 | Resources queryReservations(); 29 | 30 | @Configuration 31 | @EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL) 32 | public static class CustomerClientConfiguration { 33 | 34 | @Bean 35 | Logger.Level feignLoggerLevel() { 36 | return Logger.Level.FULL; 37 | } 38 | 39 | @Bean 40 | public Decoder feignDecoder() { 41 | ObjectMapper objectMapper = new ObjectMapper() 42 | .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) 43 | .configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true) 44 | .registerModule(new Jackson2HalModule()); 45 | 46 | MappingJackson2HttpMessageConverter jacksonConverter = new MappingJackson2HttpMessageConverter(); 47 | jacksonConverter.setSupportedMediaTypes(Arrays.asList(MediaTypes.HAL_JSON)); 48 | jacksonConverter.setObjectMapper(objectMapper); 49 | 50 | ObjectFactory objectFactory = () -> new HttpMessageConverters(jacksonConverter); 51 | return new ResponseEntityDecoder(new SpringDecoder(objectFactory)); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-springcloud/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.alipay.sofa.ms 7 | dubbo-samples-springboot2 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | dubbo-springcloud 13 | 14 | 15 | 8 16 | 8 17 | 18 | 19 | 20 | com.alipay.sofa.ms 21 | dubbo-echo-api 22 | 23 | 24 | org.apache.dubbo 25 | dubbo 26 | 27 | 28 | org.slf4j 29 | log4j-over-slf4j 30 | 31 | 32 | 33 | com.alibaba 34 | fastjson 35 | 1.2.47 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter 41 | 42 | 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-starter-web-services 47 | 48 | 49 | 50 | 51 | org.apache.cxf 52 | cxf-spring-boot-starter-jaxws 53 | 3.3.10 54 | 55 | 56 | 57 | io.netty 58 | netty-all 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | org.springframework.boot 67 | spring-boot-maven-plugin 68 | 2.0.5.RELEASE 69 | 70 | 71 | 72 | repackage 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.alipay.sofa.ms 7 | springcloud-samples-springboot2 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | springcloud-reservation-client 13 | 14 | 15 | 16 | 17 | org.springframework.cloud 18 | spring-cloud-starter-config 19 | 20 | 21 | org.springframework.cloud 22 | spring-cloud-starter-netflix-eureka-client 23 | 24 | 25 | 26 | 27 | com.alipay.sofa 28 | sofa-registry-cloud-all 29 | 30 | 31 | 32 | com.alipay.sofa 33 | tracer-enterprise-sofa-boot-starter 34 | 35 | 36 | com.alipay.sofa.common 37 | sofa-common-tools 38 | 39 | 40 | 41 | org.springframework.cloud 42 | spring-cloud-starter-netflix-ribbon 43 | 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-starter-actuator 48 | 49 | 50 | org.springframework.cloud 51 | spring-cloud-starter-netflix-hystrix 52 | 53 | 54 | org.springframework.boot 55 | spring-boot-starter-hateoas 56 | 57 | 58 | org.springframework.cloud 59 | spring-cloud-starter-openfeign 60 | 61 | 62 | 63 | 64 | 65 | 66 | org.slf4j 67 | log4j-over-slf4j 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /hsf-samples-pandoraboot/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.alipay.sofa.ms 7 | sofastack-mesh-demo 8 | 1.0-SNAPSHOT 9 | 10 | 11 | 4.0.0 12 | 13 | hsf-samples-pandoraboot 14 | pom 15 | 16 | 17 | 18 | hsf-echo-api 19 | hsf-echo-server 20 | hsf-echo-client 21 | 22 | 23 | 24 | 8 25 | 8 26 | 27 | 2.1.6.RELEASE 28 | 2019-06-stable 29 | 30 | 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-dependencies 36 | ${spring-boot.version} 37 | pom 38 | import 39 | 40 | 41 | com.taobao.pandora 42 | pandora-boot-starter-bom 43 | ${pandora-boot.version} 44 | pom 45 | import 46 | 47 | 48 | 49 | com.alipay.sofa.ms 50 | hsf-echo-api 51 | ${project.parent.version} 52 | 53 | 54 | 55 | 56 | 57 | 58 | edas-oss-central 59 | taobao mirror central 60 | http://edas-public.oss-cn-hangzhou.aliyuncs.com/repository 61 | 62 | true 63 | 64 | 65 | true 66 | 67 | 68 | 69 | 70 | 71 | edas-oss-plugin-central 72 | http://edas-public.oss-cn-hangzhou.aliyuncs.com/repository 73 | 74 | true 75 | 76 | 77 | true 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /springcloud-samples-springboot2/spring-cloud-reservation-gateway/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.alipay.sofa.ms 7 | springcloud-samples-springboot2 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | spring-cloud-reservation-gateway 13 | 14 | 15 | 16 | 17 | org.springframework.cloud 18 | spring-cloud-starter-config 19 | 20 | 21 | org.springframework.cloud 22 | spring-cloud-starter-netflix-eureka-client 23 | 24 | 25 | 26 | org.springframework.cloud 27 | spring-cloud-starter-gateway 28 | 29 | 30 | 31 | 32 | com.alipay.sofa 33 | sofa-registry-cloud-all 34 | 35 | 36 | 37 | com.alipay.sofa 38 | tracer-enterprise-sofa-boot-starter 39 | 40 | 41 | com.alipay.sofa.common 42 | sofa-common-tools 43 | 44 | 45 | 46 | org.springframework.cloud 47 | spring-cloud-starter-netflix-ribbon 48 | 49 | 50 | 51 | org.springframework.boot 52 | spring-boot-starter-actuator 53 | 54 | 55 | org.springframework.cloud 56 | spring-cloud-starter-netflix-hystrix 57 | 58 | 59 | org.springframework.boot 60 | spring-boot-starter-hateoas 61 | 62 | 63 | org.springframework.boot 64 | spring-boot-starter-web 65 | 66 | 67 | 68 | 69 | org.springframework.cloud 70 | spring-cloud-starter-openfeign 71 | 72 | 73 | 74 | org.slf4j 75 | log4j-over-slf4j 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-echo-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.alipay.sofa.ms 7 | dubbo-samples-springboot2 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | dubbo-echo-client 13 | 14 | 15 | 16 | com.alipay.sofa.ms 17 | dubbo-echo-api 18 | 19 | 20 | 21 | 22 | com.alipay.sofa 23 | sofa-registry-cloud-all 24 | 25 | 26 | 27 | 28 | com.alipay.sofa 29 | tracer-enterprise-sofa-boot-starter 30 | 31 | 32 | com.alipay.sofa.common 33 | sofa-common-tools 34 | 35 | 36 | 37 | org.apache.dubbo 38 | dubbo 39 | 40 | 41 | org.apache.curator 42 | curator-framework 43 | 44 | 45 | org.apache.curator 46 | curator-recipes 47 | 48 | 49 | 50 | org.slf4j 51 | log4j-over-slf4j 52 | 53 | 54 | 55 | org.springframework.boot 56 | spring-boot-starter 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-starter-web 62 | 63 | 64 | org.springframework 65 | spring-webmvc 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | org.springframework.boot 75 | spring-boot-maven-plugin 76 | 2.0.5.RELEASE 77 | 78 | 79 | 80 | repackage 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-echo-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.alipay.sofa.ms 7 | dubbo-samples-springboot2 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | dubbo-echo-server 13 | 14 | 15 | 16 | com.alipay.sofa.ms 17 | dubbo-echo-api 18 | 19 | 20 | 21 | 22 | com.alipay.sofa 23 | sofa-registry-cloud-all 24 | 25 | 26 | 27 | 28 | com.alipay.sofa 29 | tracer-enterprise-sofa-boot-starter 30 | 31 | 32 | com.alipay.sofa.common 33 | sofa-common-tools 34 | 35 | 36 | 37 | org.apache.dubbo 38 | dubbo 39 | 40 | 41 | org.apache.curator 42 | curator-framework 43 | 44 | 45 | org.apache.curator 46 | curator-recipes 47 | 48 | 49 | 50 | org.slf4j 51 | log4j-over-slf4j 52 | 53 | 54 | 55 | org.springframework.boot 56 | spring-boot-starter 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-starter-web 62 | 63 | 64 | org.springframework 65 | spring-webmvc 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | org.springframework.boot 75 | spring-boot-maven-plugin 76 | 2.0.5.RELEASE 77 | 78 | 79 | 80 | repackage 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.alipay.sofa.ms 7 | springcloud-samples-springboot2 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | springcloud-reservation-service 13 | 14 | 15 | com.google.guava 16 | guava 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-actuator 21 | 22 | 23 | org.springframework.cloud 24 | spring-cloud-starter-config 25 | 26 | 27 | org.springframework.cloud 28 | spring-cloud-starter-netflix-eureka-client 29 | 30 | 31 | 32 | 33 | com.alipay.sofa 34 | sofa-registry-cloud-all 35 | 36 | 37 | 38 | com.alipay.sofa 39 | tracer-enterprise-sofa-boot-starter 40 | 41 | 42 | com.alipay.sofa.common 43 | sofa-common-tools 44 | 45 | 46 | 47 | org.springframework.cloud 48 | spring-cloud-starter-netflix-ribbon 49 | 50 | 51 | 52 | org.springframework.boot 53 | spring-boot-starter-data-rest 54 | 55 | 56 | com.h2database 57 | h2 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-starter-data-jpa 62 | 63 | 64 | org.springframework.boot 65 | spring-boot-starter-web 66 | 67 | 68 | org.slf4j 69 | log4j-over-slf4j 70 | 71 | 72 | com.alipay.sofa.ms 73 | dubbo-springcloud 74 | 1.0-SNAPSHOT 75 | compile 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /springcloud-samples-springboot2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | sofastack-mesh-demo 7 | com.alipay.sofa.ms 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | springcloud-samples-springboot2 13 | pom 14 | 15 | 16 | springcloud-config-server 17 | springcloud-reservation-service 18 | springcloud-eureka-server 19 | springcloud-reservation-client 20 | springcloud-hystrix-dashboard 21 | springcloud-turbine 22 | spring-cloud-reservation-gateway 23 | 24 | 25 | 26 | 20.0 27 | Finchley.SR3 28 | 2.0.9.RELEASE 29 | 30 | 31 | 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-dependencies 36 | ${spring_cloud_version} 37 | pom 38 | import 39 | 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-dependencies 44 | ${springboot_version} 45 | pom 46 | import 47 | 48 | 49 | 50 | com.google.guava 51 | guava 52 | ${guava_version} 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-starter-test 62 | test 63 | 64 | 65 | 66 | 67 | 68 | 69 | org.apache.maven.plugins 70 | maven-jar-plugin 71 | 3.2.0 72 | 73 | ${project.artifactId}-${project.version} 74 | 75 | 76 | 77 | org.apache.maven.plugins 78 | maven-surefire-plugin 79 | 2.10 80 | 81 | true 82 | 83 | 84 | 85 | 86 | org.springframework.boot 87 | spring-boot-maven-plugin 88 | 2.0.5.RELEASE 89 | 90 | 91 | 92 | repackage 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /springcloud-samples-springboot2/springcloud-reservation-client/src/main/java/com/alipay/sofa/ms/spring/cloud/reservation/client/controller/ReservationApiGatewayRestController.java: -------------------------------------------------------------------------------- 1 | package com.alipay.sofa.ms.spring.cloud.reservation.client.controller; 2 | 3 | import com.alipay.sofa.ms.spring.cloud.reservation.client.dto.Reservation; 4 | import com.alipay.sofa.ms.spring.cloud.reservation.client.service.ReservationService; 5 | import java.util.Collection; 6 | import java.util.Collections; 7 | import java.util.concurrent.TimeUnit; 8 | import java.util.stream.Collectors; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | import org.springframework.beans.BeansException; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 14 | import org.springframework.context.ApplicationContext; 15 | import org.springframework.context.ApplicationContextAware; 16 | import org.springframework.core.ParameterizedTypeReference; 17 | import org.springframework.hateoas.Resources; 18 | import org.springframework.http.HttpEntity; 19 | import org.springframework.http.HttpHeaders; 20 | import org.springframework.http.HttpMethod; 21 | import org.springframework.http.ResponseEntity; 22 | import org.springframework.web.bind.annotation.RequestHeader; 23 | import org.springframework.web.bind.annotation.RequestMapping; 24 | import org.springframework.web.bind.annotation.RestController; 25 | import org.springframework.web.client.RestTemplate; 26 | 27 | /** 28 | * @author yiji@apache.org 29 | */ 30 | @RestController 31 | @RequestMapping("/reservations") 32 | public class ReservationApiGatewayRestController implements ApplicationContextAware { 33 | 34 | private static final Logger logger = LoggerFactory.getLogger(ReservationApiGatewayRestController.class); 35 | @Autowired 36 | private RestTemplate rt; 37 | 38 | @Autowired 39 | private ReservationService reservationService; 40 | 41 | private Collection getReservationNamesFallback() { 42 | return Collections.emptyList(); 43 | } 44 | 45 | @RequestMapping("/names") 46 | public Collection getReservationNames() { 47 | logger.debug("Get reservation names via rest template!"); 48 | 49 | ParameterizedTypeReference> parameterizedTypeReference = 50 | new ParameterizedTypeReference>() { 51 | }; 52 | 53 | ResponseEntity> exchange = rt.exchange( 54 | "http://reservation-service/reservations", 55 | HttpMethod.GET, null, parameterizedTypeReference); 56 | 57 | return exchange.getBody().getContent().stream().map(Reservation::getReservationName).collect(Collectors.toList()); 58 | } 59 | 60 | @RequestMapping("/names-feign") 61 | public Collection getReservationNamesViaFeign() { 62 | logger.debug("Get reservation names via feign!"); 63 | 64 | Resources reservations = reservationService.queryReservations(); 65 | 66 | return reservations.getContent().stream().map(Reservation::getReservationName).collect(Collectors.toList()); 67 | } 68 | 69 | @RequestMapping("/echo/dubbo") 70 | public String echo(String message){ 71 | HttpHeaders headers = new HttpHeaders(); 72 | headers.add("service", "reservation-client"); 73 | HttpEntity entity = new HttpEntity<>(headers); 74 | ResponseEntity result = rt.exchange( 75 | "http://127.0.0.1:10088/reservations/" + message + "/echo", 76 | HttpMethod.POST, entity, String.class); 77 | return result.getBody(); 78 | } 79 | 80 | @RequestMapping("/echo/springcloud") 81 | public String echo2(String message){ 82 | HttpHeaders headers = new HttpHeaders(); 83 | headers.add("service", "reservation-service"); 84 | HttpEntity entity = new HttpEntity<>(headers); 85 | ResponseEntity result = rt.exchange( 86 | "http://127.0.0.1:10088/reservations/" + message + "/echo", 87 | HttpMethod.POST, entity, String.class); 88 | return result.getBody(); 89 | } 90 | 91 | @RequestMapping("/echo") 92 | public String echo3(String message, @RequestHeader String service){ 93 | HttpHeaders headers = new HttpHeaders(); 94 | headers.add("service", service); 95 | HttpEntity entity = new HttpEntity<>(headers); 96 | ResponseEntity result = rt.exchange( 97 | "http://127.0.0.1:10088/reservations/" + message + "/echo", 98 | HttpMethod.POST, entity, String.class); 99 | return result.getBody(); 100 | } 101 | 102 | @Override 103 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 104 | new Thread(() -> { 105 | for (; ; ) { 106 | try { 107 | TimeUnit.SECONDS.sleep(1L); 108 | Collection result = getReservationNamesViaFeign(); 109 | logger.info(">>>>>>> get reservations via feign: " + result); 110 | logger.info(">>>>>>> get reservations via rt: " + getReservationNames()); 111 | } catch (Exception e) { 112 | logger.error(">>>>>>> get reservations: : " + e.getMessage()); 113 | } 114 | } 115 | }).start(); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-webservice/src/main/java/com/alipay/webservice/SocketServerBootstrap.java: -------------------------------------------------------------------------------- 1 | package com.alipay.webservice; 2 | 3 | import io.netty.bootstrap.ServerBootstrap; 4 | import io.netty.buffer.ByteBuf; 5 | import io.netty.buffer.PooledByteBufAllocator; 6 | import io.netty.channel.Channel; 7 | import io.netty.channel.ChannelDuplexHandler; 8 | import io.netty.channel.ChannelFuture; 9 | import io.netty.channel.ChannelHandler; 10 | import io.netty.channel.ChannelHandlerContext; 11 | import io.netty.channel.ChannelInitializer; 12 | import io.netty.channel.ChannelOption; 13 | import io.netty.channel.nio.NioEventLoopGroup; 14 | import io.netty.channel.socket.nio.NioServerSocketChannel; 15 | import io.netty.channel.socket.nio.NioSocketChannel; 16 | import io.netty.handler.codec.ByteToMessageDecoder; 17 | import io.netty.handler.codec.MessageToByteEncoder; 18 | import io.netty.util.concurrent.DefaultThreadFactory; 19 | import java.util.List; 20 | import java.util.concurrent.CountDownLatch; 21 | 22 | public class SocketServerBootstrap { 23 | 24 | public static void main(String[] args) throws InterruptedException { 25 | startSocketService(9999); 26 | } 27 | 28 | 29 | public static void startSocketService(int port) throws InterruptedException { 30 | 31 | CountDownLatch latch = new CountDownLatch(1); 32 | 33 | ServerBootstrap bootstrap = new ServerBootstrap(); 34 | NioEventLoopGroup bossGroup = new NioEventLoopGroup(1, new DefaultThreadFactory("NettyServerBoss", true)); 35 | NioEventLoopGroup workerGroup = new NioEventLoopGroup(2, new DefaultThreadFactory("NettyServerWorker", true)); 36 | 37 | bootstrap.group(bossGroup, workerGroup) 38 | .channel(NioServerSocketChannel.class) 39 | .childOption(ChannelOption.TCP_NODELAY, Boolean.TRUE) 40 | .childOption(ChannelOption.SO_REUSEADDR, Boolean.TRUE) 41 | .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) 42 | .childHandler(new ChannelInitializer() { 43 | @Override 44 | protected void initChannel(NioSocketChannel ch) throws Exception { 45 | NettyCodecAdapter adapter = new NettyCodecAdapter(); 46 | ch.pipeline() 47 | .addLast("decoder", adapter.getDecoder()) 48 | .addLast("encoder", adapter.getEncoder()) 49 | .addLast("handler", new NettyServerHandler()); 50 | } 51 | }); 52 | // bind 53 | ChannelFuture channelFuture = bootstrap.bind("0.0.0.0", port); 54 | channelFuture.syncUninterruptibly(); 55 | Channel channel = channelFuture.channel(); 56 | 57 | latch.await(); 58 | } 59 | 60 | static class NettyCodecAdapter { 61 | 62 | private final ChannelHandler encoder = new InternalEncoder(); 63 | 64 | private final ChannelHandler decoder = new InternalDecoder(); 65 | 66 | public ChannelHandler getEncoder() { 67 | return encoder; 68 | } 69 | 70 | public ChannelHandler getDecoder() { 71 | return decoder; 72 | } 73 | 74 | private class InternalEncoder extends MessageToByteEncoder { 75 | 76 | 77 | @Override 78 | protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception { 79 | // 构造socket协议响应报文 80 | String packet = String.valueOf(msg); 81 | String lenOfPacket = String.valueOf(packet.getBytes().length); 82 | if (lenOfPacket.length() < 8) { 83 | int remain = 8 - lenOfPacket.length(); 84 | String prefix = ""; 85 | for (int i = 0; i < remain; i++) { 86 | prefix += "0"; 87 | } 88 | lenOfPacket = prefix + lenOfPacket; 89 | } 90 | out.writeBytes(lenOfPacket.getBytes()); 91 | out.writeBytes(packet.getBytes()); 92 | } 93 | } 94 | 95 | private class InternalDecoder extends ByteToMessageDecoder { 96 | 97 | @Override 98 | protected void decode(ChannelHandlerContext ctx, ByteBuf input, List out) throws Exception { 99 | int saveReaderIndex; 100 | // decode object. 101 | do { 102 | saveReaderIndex = input.readerIndex(); 103 | // 8字节长度 104 | if (input.readableBytes() < 8) { 105 | break; 106 | } 107 | 108 | byte[] header = new byte[8]; 109 | input.readBytes(header); 110 | 111 | // 解析socket头部长度 112 | // 8字节长度,不足前缀是0 113 | String length = new String(header); 114 | while (length.startsWith("0")) { 115 | if (length.length() > 1) { 116 | length = length.substring(1); 117 | } 118 | } 119 | 120 | int packetLength = Integer.parseInt(length); 121 | int available = input.readableBytes(); 122 | if (packetLength > available) { 123 | // rollback buffer reader index 124 | input.readerIndex(saveReaderIndex); 125 | break; 126 | } 127 | 128 | byte[] payload = new byte[packetLength]; 129 | input.readBytes(payload); 130 | 131 | out.add(new String(payload)); 132 | 133 | if (input.readableBytes() > 0) { 134 | byte b = input.readByte(); 135 | while (b == '\r' || b == '\n') { 136 | if (input.isReadable()) { 137 | b = input.readByte(); 138 | } else { 139 | break; 140 | } 141 | } 142 | if (input.isReadable()) { 143 | input.readerIndex(input.readerIndex() - 1); 144 | } 145 | } 146 | 147 | } while (input.readableBytes() > 0); 148 | } 149 | } 150 | } 151 | 152 | @io.netty.channel.ChannelHandler.Sharable 153 | static class NettyServerHandler extends ChannelDuplexHandler { 154 | @Override 155 | public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { 156 | 157 | // 把 转成 158 | // 把 转成 159 | String body = String.valueOf(msg); 160 | 161 | body = body.replaceAll("0", "1"); 162 | 163 | body = body.replaceAll("", ""); 164 | body = body.replaceAll("", ""); 165 | 166 | System.out.println("ready response: " + body); 167 | 168 | ctx.channel().writeAndFlush(body); 169 | } 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-webservice/src/main/java/com/alipay/webservice/BEISServerBootstrap.java: -------------------------------------------------------------------------------- 1 | package com.alipay.webservice; 2 | 3 | import io.netty.bootstrap.ServerBootstrap; 4 | import io.netty.buffer.ByteBuf; 5 | import io.netty.buffer.PooledByteBufAllocator; 6 | import io.netty.channel.Channel; 7 | import io.netty.channel.ChannelDuplexHandler; 8 | import io.netty.channel.ChannelFuture; 9 | import io.netty.channel.ChannelHandler; 10 | import io.netty.channel.ChannelHandlerContext; 11 | import io.netty.channel.ChannelInitializer; 12 | import io.netty.channel.ChannelOption; 13 | import io.netty.channel.nio.NioEventLoopGroup; 14 | import io.netty.channel.socket.nio.NioServerSocketChannel; 15 | import io.netty.channel.socket.nio.NioSocketChannel; 16 | import io.netty.handler.codec.ByteToMessageDecoder; 17 | import io.netty.handler.codec.MessageToByteEncoder; 18 | import io.netty.util.concurrent.DefaultThreadFactory; 19 | import java.nio.charset.StandardCharsets; 20 | import java.util.List; 21 | import java.util.concurrent.CountDownLatch; 22 | 23 | public class BEISServerBootstrap { 24 | 25 | public static void main(String[] args) throws InterruptedException { 26 | startSocketService(7766); 27 | } 28 | 29 | 30 | public static void startSocketService(int port) throws InterruptedException { 31 | 32 | CountDownLatch latch = new CountDownLatch(1); 33 | 34 | ServerBootstrap bootstrap = new ServerBootstrap(); 35 | NioEventLoopGroup bossGroup = new NioEventLoopGroup(1, new DefaultThreadFactory("NettyServerBoss", true)); 36 | NioEventLoopGroup workerGroup = new NioEventLoopGroup(2, new DefaultThreadFactory("NettyServerWorker", true)); 37 | 38 | bootstrap.group(bossGroup, workerGroup) 39 | .channel(NioServerSocketChannel.class) 40 | .childOption(ChannelOption.TCP_NODELAY, Boolean.TRUE) 41 | .childOption(ChannelOption.SO_REUSEADDR, Boolean.TRUE) 42 | .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) 43 | .childHandler(new ChannelInitializer() { 44 | @Override 45 | protected void initChannel(NioSocketChannel ch) throws Exception { 46 | NettyCodecAdapter adapter = new NettyCodecAdapter(); 47 | ch.pipeline() 48 | .addLast("decoder", adapter.getDecoder()) 49 | .addLast("encoder", adapter.getEncoder()) 50 | .addLast("handler", new NettyServerHandler()); 51 | } 52 | }); 53 | // bind 54 | ChannelFuture channelFuture = bootstrap.bind("0.0.0.0", port); 55 | channelFuture.syncUninterruptibly(); 56 | Channel channel = channelFuture.channel(); 57 | 58 | latch.await(); 59 | } 60 | 61 | static class NettyCodecAdapter { 62 | 63 | private final ChannelHandler encoder = new InternalEncoder(); 64 | 65 | private final ChannelHandler decoder = new InternalDecoder(); 66 | 67 | public ChannelHandler getEncoder() { 68 | return encoder; 69 | } 70 | 71 | public ChannelHandler getDecoder() { 72 | return decoder; 73 | } 74 | 75 | private class InternalEncoder extends MessageToByteEncoder { 76 | 77 | 78 | @Override 79 | protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception { 80 | // 构造socket协议响应报文 81 | String packet = String.valueOf(msg); 82 | out.writeBytes(packet.getBytes()); 83 | } 84 | } 85 | 86 | private class InternalDecoder extends ByteToMessageDecoder { 87 | 88 | @Override 89 | protected void decode(ChannelHandlerContext ctx, ByteBuf input, List out) throws Exception { 90 | int saveReaderIndex; 91 | // decode object. 92 | do { 93 | saveReaderIndex = input.readerIndex(); 94 | // 8字节长度 95 | if (input.readableBytes() < 128) { 96 | break; 97 | } 98 | 99 | byte[] headerBytes = new byte[128]; 100 | input.readBytes(headerBytes); 101 | String header = new String(headerBytes); 102 | // 解析socket头部长度 103 | // 8字节长度,不足前缀是0 104 | String length = header.substring(18, 26); 105 | while (length.startsWith("0")) { 106 | if (length.length() > 1) { 107 | length = length.substring(1); 108 | } 109 | } 110 | 111 | int packetLength = Integer.parseInt(length); 112 | int available = input.readableBytes(); 113 | if (packetLength > available) { 114 | // rollback buffer reader index 115 | input.readerIndex(saveReaderIndex); 116 | break; 117 | } 118 | 119 | byte[] payload = new byte[packetLength]; 120 | input.readBytes(payload); 121 | 122 | out.add(new String(payload)); 123 | 124 | System.out.println(new String(payload)); 125 | 126 | if (input.readableBytes() > 0) { 127 | byte b = input.readByte(); 128 | while (b == '\r' || b == '\n') { 129 | if (input.isReadable()) { 130 | b = input.readByte(); 131 | } else { 132 | break; 133 | } 134 | } 135 | if (input.isReadable()) { 136 | input.readerIndex(input.readerIndex() - 1); 137 | } 138 | } 139 | 140 | } while (input.readableBytes() > 0); 141 | } 142 | } 143 | } 144 | 145 | @ChannelHandler.Sharable 146 | static class NettyServerHandler extends ChannelDuplexHandler { 147 | @Override 148 | public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { 149 | 150 | // 把 转成 151 | // 把 转成 152 | String body = "\n" 153 | + "\n" 154 | + "\n" 155 | + "\n" 156 | + "[DFDK_BRNC140030280001#ESBOUT1_0570_E007]:[BOBITSAdapter]IO异常!\n" 157 | + "E007\n" 158 | + "\n" 159 | + "1410\n" 160 | + "3028\n" 161 | + "1\n" 162 | + "01\n" 163 | + "BRNC1400302800\n" 164 | + "\n" 165 | + "\n" 166 | + "\n" 167 | + ""; 168 | 169 | String lenOfPacket = String.valueOf(body.getBytes(StandardCharsets.UTF_8).length); 170 | if (lenOfPacket.length() < 8) { 171 | int remain = 8 - lenOfPacket.length(); 172 | String prefix = ""; 173 | for (int i = 0; i < remain; i++) { 174 | prefix += "0"; 175 | } 176 | lenOfPacket = prefix + lenOfPacket; 177 | } 178 | 179 | String header = "{BOBXML:PUBKEY " + lenOfPacket 180 | + "0234567800000001 {BOBXML: " 181 | + " }"; 182 | 183 | System.out.println("ready response: " + header + body); 184 | 185 | ctx.channel().writeAndFlush(header + body); 186 | } 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-client/app/web/src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | %d{HH:mm:ss.SSS} %-5level %logger{80} - %msg%n 13 | 14 | 15 | 16 | 17 | 18 | true 19 | 20 | 21 | error 22 | 23 | 24 | ${logging.path}/sofa-samples-springboot2/common-error.log 25 | 26 | 27 | 28 | ${logging.path}/sofa-samples-springboot2/common-error.log.%d{yyyy-MM-dd} 29 | 30 | 30 31 | 32 | 33 | 34 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n 35 | 36 | UTF-8 37 | 38 | 39 | 40 | 41 | true 42 | 43 | ${logging.level} 44 | 45 | ${logging.path}/sofa-samples-springboot2/common-default.log 46 | 47 | 48 | 49 | ${logging.path}/sofa-samples-springboot2/common-default.log.%d{yyyy-MM-dd} 50 | 51 | 52 | 30 53 | 54 | 55 | 56 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n 57 | 58 | UTF-8 59 | 60 | 61 | 62 | 63 | 64 | true 65 | 66 | ${logging.level} 67 | 68 | ${logging.path}/sofa-samples-springboot2/mdc-example.log 69 | 70 | 71 | 72 | ${logging.path}/sofa-samples-springboot2/mdc-example.log.%d{yyyy-MM-dd} 73 | 74 | 75 | 30 76 | 77 | 78 | 79 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level [%X{SOFA-TraceId},%X{SOFA-SpanId}] %logger{50} - %msg%n 80 | 81 | UTF-8 82 | 83 | 84 | 85 | 86 | 87 | 88 | true 89 | 90 | ${logging.level} 91 | 92 | ${logging.path}/sofa-samples-springboot2/sofa-samples-springboot2-default-dev.log 93 | 94 | 95 | 96 | 97 | ${logging.path}/sofa-samples-springboot2/sofa-samples-springboot2-default-dev.log.%d{yyyy-MM-dd} 98 | 99 | 100 | 30 101 | 102 | 103 | 104 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n 105 | 106 | UTF-8 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | true 115 | 116 | ${logging.level} 117 | 118 | ${logging.path}/sofa-samples-springboot2/sofa-samples-springboot2-default-test.log 119 | 120 | 121 | 122 | 123 | ${logging.path}/sofa-samples-springboot2/sofa-samples-springboot2-default-test.log.%d{yyyy-MM-dd} 124 | 125 | 126 | 30 127 | 128 | 129 | 130 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n 131 | 132 | UTF-8 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /sofa-samples-springboot2/sofa-echo-server/app/web/src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | %d{HH:mm:ss.SSS} %-5level %logger{80} - %msg%n 13 | 14 | 15 | 16 | 17 | 18 | true 19 | 20 | 21 | error 22 | 23 | 24 | ${logging.path}/sofa-samples-springboot2/common-error.log 25 | 26 | 27 | 28 | ${logging.path}/sofa-samples-springboot2/common-error.log.%d{yyyy-MM-dd} 29 | 30 | 30 31 | 32 | 33 | 34 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n 35 | 36 | UTF-8 37 | 38 | 39 | 40 | 41 | true 42 | 43 | ${logging.level} 44 | 45 | ${logging.path}/sofa-samples-springboot2/common-default.log 46 | 47 | 48 | 49 | ${logging.path}/sofa-samples-springboot2/common-default.log.%d{yyyy-MM-dd} 50 | 51 | 52 | 30 53 | 54 | 55 | 56 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n 57 | 58 | UTF-8 59 | 60 | 61 | 62 | 63 | 64 | true 65 | 66 | ${logging.level} 67 | 68 | ${logging.path}/sofa-samples-springboot2/mdc-example.log 69 | 70 | 71 | 72 | ${logging.path}/sofa-samples-springboot2/mdc-example.log.%d{yyyy-MM-dd} 73 | 74 | 75 | 30 76 | 77 | 78 | 79 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level [%X{SOFA-TraceId},%X{SOFA-SpanId}] %logger{50} - %msg%n 80 | 81 | UTF-8 82 | 83 | 84 | 85 | 86 | 87 | 88 | true 89 | 90 | ${logging.level} 91 | 92 | ${logging.path}/sofa-samples-springboot2/sofa-samples-springboot2-default-dev.log 93 | 94 | 95 | 96 | 97 | ${logging.path}/sofa-samples-springboot2/sofa-samples-springboot2-default-dev.log.%d{yyyy-MM-dd} 98 | 99 | 100 | 30 101 | 102 | 103 | 104 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n 105 | 106 | UTF-8 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | true 115 | 116 | ${logging.level} 117 | 118 | ${logging.path}/sofa-samples-springboot2/sofa-samples-springboot2-default-test.log 119 | 120 | 121 | 122 | 123 | ${logging.path}/sofa-samples-springboot2/sofa-samples-springboot2-default-test.log.%d{yyyy-MM-dd} 124 | 125 | 126 | 30 127 | 128 | 129 | 130 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n 131 | 132 | UTF-8 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /dubbo-samples-springboot2/dubbo-webservice/src/main/java/com/alipay/webservice/CDServerBootstrap.java: -------------------------------------------------------------------------------- 1 | package com.alipay.webservice; 2 | 3 | import io.netty.bootstrap.ServerBootstrap; 4 | import io.netty.buffer.ByteBuf; 5 | import io.netty.buffer.PooledByteBufAllocator; 6 | import io.netty.channel.Channel; 7 | import io.netty.channel.ChannelDuplexHandler; 8 | import io.netty.channel.ChannelFuture; 9 | import io.netty.channel.ChannelHandler; 10 | import io.netty.channel.ChannelHandlerContext; 11 | import io.netty.channel.ChannelInitializer; 12 | import io.netty.channel.ChannelOption; 13 | import io.netty.channel.nio.NioEventLoopGroup; 14 | import io.netty.channel.socket.nio.NioServerSocketChannel; 15 | import io.netty.channel.socket.nio.NioSocketChannel; 16 | import io.netty.handler.codec.ByteToMessageDecoder; 17 | import io.netty.handler.codec.MessageToByteEncoder; 18 | import io.netty.util.concurrent.DefaultThreadFactory; 19 | import java.nio.charset.StandardCharsets; 20 | import java.util.List; 21 | import java.util.concurrent.CountDownLatch; 22 | 23 | public class CDServerBootstrap { 24 | 25 | public static void main(String[] args) throws InterruptedException { 26 | startSocketService(10150); 27 | } 28 | 29 | 30 | public static void startSocketService(int port) throws InterruptedException { 31 | 32 | CountDownLatch latch = new CountDownLatch(1); 33 | 34 | ServerBootstrap bootstrap = new ServerBootstrap(); 35 | NioEventLoopGroup bossGroup = new NioEventLoopGroup(1, new DefaultThreadFactory("NettyServerBoss", true)); 36 | NioEventLoopGroup workerGroup = new NioEventLoopGroup(2, new DefaultThreadFactory("NettyServerWorker", true)); 37 | 38 | bootstrap.group(bossGroup, workerGroup) 39 | .channel(NioServerSocketChannel.class) 40 | .childOption(ChannelOption.TCP_NODELAY, Boolean.TRUE) 41 | .childOption(ChannelOption.SO_REUSEADDR, Boolean.TRUE) 42 | .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) 43 | .childHandler(new ChannelInitializer() { 44 | @Override 45 | protected void initChannel(NioSocketChannel ch) throws Exception { 46 | NettyCodecAdapter adapter = new NettyCodecAdapter(); 47 | ch.pipeline() 48 | .addLast("decoder", adapter.getDecoder()) 49 | .addLast("encoder", adapter.getEncoder()) 50 | .addLast("handler", new NettyServerHandler()); 51 | } 52 | }); 53 | // bind 54 | ChannelFuture channelFuture = bootstrap.bind("0.0.0.0", port); 55 | channelFuture.syncUninterruptibly(); 56 | Channel channel = channelFuture.channel(); 57 | 58 | latch.await(); 59 | } 60 | 61 | static class NettyCodecAdapter { 62 | 63 | private final ChannelHandler encoder = new InternalEncoder(); 64 | 65 | private final ChannelHandler decoder = new InternalDecoder(); 66 | 67 | public ChannelHandler getEncoder() { 68 | return encoder; 69 | } 70 | 71 | public ChannelHandler getDecoder() { 72 | return decoder; 73 | } 74 | 75 | private class InternalEncoder extends MessageToByteEncoder { 76 | 77 | 78 | @Override 79 | protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception { 80 | // 构造socket协议响应报文 81 | String packet = String.valueOf(msg); 82 | String lenOfPacket = String.valueOf(packet.getBytes(StandardCharsets.UTF_8).length); 83 | if (lenOfPacket.length() < 10) { 84 | int remain = 10 - lenOfPacket.length(); 85 | String prefix = ""; 86 | for (int i = 0; i < remain; i++) { 87 | prefix += "0"; 88 | } 89 | lenOfPacket = prefix + lenOfPacket; 90 | } 91 | out.writeBytes(lenOfPacket.getBytes()); 92 | out.writeBytes(packet.getBytes()); 93 | } 94 | } 95 | 96 | private class InternalDecoder extends ByteToMessageDecoder { 97 | 98 | @Override 99 | protected void decode(ChannelHandlerContext ctx, ByteBuf input, List out) throws Exception { 100 | int saveReaderIndex; 101 | // decode object. 102 | do { 103 | saveReaderIndex = input.readerIndex(); 104 | // 8字节长度 105 | if (input.readableBytes() < 10) { 106 | break; 107 | } 108 | 109 | byte[] header = new byte[10]; 110 | input.readBytes(header); 111 | 112 | // 解析socket头部长度 113 | // 8字节长度,不足前缀是0 114 | String length = new String(header); 115 | while (length.startsWith("0")) { 116 | if (length.length() > 1) { 117 | length = length.substring(1); 118 | } 119 | } 120 | 121 | int packetLength = Integer.parseInt(length); 122 | int available = input.readableBytes(); 123 | if (packetLength > available) { 124 | // rollback buffer reader index 125 | input.readerIndex(saveReaderIndex); 126 | break; 127 | } 128 | 129 | byte[] payload = new byte[packetLength]; 130 | input.readBytes(payload); 131 | 132 | out.add(new String(payload)); 133 | 134 | if (input.readableBytes() > 0) { 135 | byte b = input.readByte(); 136 | while (b == '\r' || b == '\n') { 137 | if (input.isReadable()) { 138 | b = input.readByte(); 139 | } else { 140 | break; 141 | } 142 | } 143 | if (input.isReadable()) { 144 | input.readerIndex(input.readerIndex() - 1); 145 | } 146 | } 147 | 148 | } while (input.readableBytes() > 0); 149 | } 150 | } 151 | } 152 | 153 | @ChannelHandler.Sharable 154 | static class NettyServerHandler extends ChannelDuplexHandler { 155 | @Override 156 | public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { 157 | 158 | String req = (String) msg; 159 | 160 | System.out.println("receive request:\n" + req); 161 | 162 | // 把 转成 163 | // 把 转成 164 | String body = String.valueOf("\n" 165 | + "\n" 166 | + "\n" 167 | + "\n" 168 | + "\n" 169 | + "\n" 170 | + "\n" 171 | + "\n" 172 | + "\n" 173 | + "999999\n" 174 | + "\n" 175 | + "\n" 176 | + "JDBC调用失败!\n" 177 | + "\n" 178 | + "\n" 179 | + "\n" 180 | + "\n" 181 | + "\n" 182 | + "\n" 183 | + "\n" 184 | + "\n" 185 | + "ANIU001000000218782\n" 186 | + "\n" 187 | + "\n" 188 | + "9527\n" 189 | + "\n" 190 | + "\n" 191 | + "BRNC1200952700\n" 192 | + "\n" 193 | + "\n" 194 | + "1210\n" 195 | + "\n" 196 | + "\n" 197 | + "F\n" 198 | + "\n" 199 | + "\n" 200 | + "135519\n" 201 | + "\n" 202 | + "\n" 203 | + "EsbBJFront\n" 204 | + "\n" 205 | + "\n" 206 | + "\n" 207 | + "\n" 208 | + "\n" 209 | + "20220113\n" 210 | + "\n" 211 | + "\n" 212 | + "\n" 213 | + "\n" 214 | + "\n" 215 | + "\n" 216 | + "\n" 217 | + "\n" 218 | + "\n" 219 | + "\n" 220 | + "\n" 221 | + "00301\n" 222 | + "\n" 223 | + "\n" 224 | + "BOBQZ2\n" 225 | + "\n" 226 | + "\n" 227 | + "00301\n" 228 | + "\n" 229 | + "\n" 230 | + "\n" 231 | + "\n" 232 | + "\n" 233 | + "\n" 234 | + "\n" 235 | + "\n" 236 | + "\n" 237 | + "\n" 238 | + ""); 239 | 240 | System.out.println("ready response(length: " + body.getBytes(StandardCharsets.UTF_8).length + "): " + body); 241 | 242 | ctx.channel().writeAndFlush(body); 243 | } 244 | } 245 | } 246 | --------------------------------------------------------------------------------