|
| 1 | +/* |
| 2 | + * Tencent is pleased to support the open source community by making Polaris available. |
| 3 | + * |
| 4 | + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. |
| 5 | + * |
| 6 | + * Licensed under the BSD 3-Clause License (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * https://opensource.org/licenses/BSD-3-Clause |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software distributed |
| 13 | + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 14 | + * CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 15 | + * specific language governing permissions and limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package cn.polarismesh.agent.examples.alibaba.cloud.cloud; |
| 19 | + |
| 20 | +import org.springframework.boot.SpringApplication; |
| 21 | +import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 22 | +import org.springframework.cloud.client.loadbalancer.LoadBalanced; |
| 23 | +import org.springframework.context.annotation.Bean; |
| 24 | +import org.springframework.http.ResponseEntity; |
| 25 | +import org.springframework.web.bind.annotation.GetMapping; |
| 26 | +import org.springframework.web.bind.annotation.PathVariable; |
| 27 | +import org.springframework.web.bind.annotation.RestController; |
| 28 | +import org.springframework.web.client.RestTemplate; |
| 29 | + |
| 30 | +/** |
| 31 | + * @author <a href="mailto:[email protected]">liaochuntao</a> |
| 32 | + */ |
| 33 | +@SpringBootApplication |
| 34 | +public class ConsumerApplication { |
| 35 | + |
| 36 | + public static void main(String[] args) { |
| 37 | + SpringApplication.run(ConsumerApplication.class, args); |
| 38 | + } |
| 39 | + |
| 40 | + @LoadBalanced |
| 41 | + @Bean |
| 42 | + public RestTemplate restTemplate() { |
| 43 | + return new RestTemplate(); |
| 44 | + } |
| 45 | + |
| 46 | + @RestController |
| 47 | + public static class EchoController { |
| 48 | + |
| 49 | + private RestTemplate template; |
| 50 | + |
| 51 | + public EchoController(RestTemplate restTemplate) { |
| 52 | + this.template = restTemplate; |
| 53 | + } |
| 54 | + |
| 55 | + @GetMapping("/echo/{str}") |
| 56 | + public ResponseEntity<String> rest(@PathVariable String str) { |
| 57 | + ResponseEntity<String> response = template.getForEntity("http://service-provider/echo/" + str, |
| 58 | + String.class); |
| 59 | + return response; |
| 60 | + } |
| 61 | + |
| 62 | + |
| 63 | + } |
| 64 | + |
| 65 | +} |
0 commit comments