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 "00000706CIMT000070from spring "
13 | + "cloudC482021121416133613538C4906221113270051159201000092010000"
15 | + "202106221113275431"
16 | + ".01020210617CN0010001FB.ICP"
18 | + ".X0110000000000000003001504094";
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