Skip to content

Commit aa09508

Browse files
author
flygoods
committed
Adding Consul as the Service Discovery and Configuration Center
1 parent b691460 commit aa09508

File tree

66 files changed

+4550
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+4550
-0
lines changed

demo/demo-consul/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Notice
2+
3+
This integration tests is designed for Consul registry and configuration. And extra test cases include:
4+
5+
* Test cases related to SpringMVC annotations that demo-springmvc can not cover.

demo/demo-consul/consumer/pom.xml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<!--
2+
~ Licensed to the Apache Software Foundation (ASF) under one or more
3+
~ contributor license agreements. See the NOTICE file distributed with
4+
~ this work for additional information regarding copyright ownership.
5+
~ The ASF licenses this file to You under the Apache License, Version 2.0
6+
~ (the "License"); you may not use this file except in compliance with
7+
~ the License. You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
<modelVersion>4.0.0</modelVersion>
21+
22+
<parent>
23+
<groupId>org.apache.servicecomb.demo</groupId>
24+
<artifactId>demo-consul</artifactId>
25+
<version>3.3.0-SNAPSHOT</version>
26+
</parent>
27+
28+
<artifactId>consul-consumer</artifactId>
29+
<name>Java Chassis::Demo::Consul::CONSUMER</name>
30+
<packaging>jar</packaging>
31+
32+
<dependencies>
33+
<dependency>
34+
<groupId>org.apache.servicecomb</groupId>
35+
<artifactId>java-chassis-spring-boot-starter-standalone</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>com.google.protobuf</groupId>
39+
<artifactId>protobuf-java</artifactId>
40+
<version>3.25.5</version>
41+
<scope>runtime</scope>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.apache.servicecomb</groupId>
45+
<artifactId>registry-consul</artifactId>
46+
</dependency>
47+
</dependencies>
48+
49+
<build>
50+
<plugins>
51+
<plugin>
52+
<groupId>org.springframework.boot</groupId>
53+
<artifactId>spring-boot-maven-plugin</artifactId>
54+
</plugin>
55+
</plugins>
56+
</build>
57+
58+
<profiles>
59+
<profile>
60+
<id>docker</id>
61+
<build>
62+
<plugins>
63+
<plugin>
64+
<groupId>io.fabric8</groupId>
65+
<artifactId>docker-maven-plugin</artifactId>
66+
</plugin>
67+
<plugin>
68+
<groupId>org.commonjava.maven.plugins</groupId>
69+
<artifactId>directory-maven-plugin</artifactId>
70+
</plugin>
71+
<plugin>
72+
<groupId>com.github.odavid.maven.plugins</groupId>
73+
<artifactId>mixin-maven-plugin</artifactId>
74+
<configuration>
75+
<mixins>
76+
<mixin>
77+
<groupId>org.apache.servicecomb.demo</groupId>
78+
<artifactId>docker-build-config</artifactId>
79+
<version>${project.version}</version>
80+
</mixin>
81+
</mixins>
82+
</configuration>
83+
</plugin>
84+
</plugins>
85+
</build>
86+
</profile>
87+
</profiles>
88+
</project>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.servicecomb.samples;
19+
20+
import org.apache.servicecomb.core.CoreConst;
21+
import org.apache.servicecomb.core.annotation.Transport;
22+
import org.apache.servicecomb.provider.pojo.RpcReference;
23+
import org.apache.servicecomb.provider.rest.common.RestSchema;
24+
import org.springframework.web.bind.annotation.PostMapping;
25+
import org.springframework.web.bind.annotation.RequestMapping;
26+
27+
import io.vertx.core.http.ServerWebSocket;
28+
import io.vertx.core.http.WebSocket;
29+
30+
@RestSchema(schemaId = "ClientWebsocketController")
31+
@RequestMapping(path = "/ws")
32+
public class ClientWebsocketController {
33+
interface ProviderService {
34+
WebSocket websocket();
35+
}
36+
37+
@RpcReference(schemaId = "WebsocketController", microserviceName = "provider")
38+
private ProviderService providerService;
39+
40+
@PostMapping("/websocket")
41+
@Transport(name = CoreConst.WEBSOCKET)
42+
public void websocket(ServerWebSocket serverWebsocket) {
43+
WebSocket providerWebSocket = providerService.websocket();
44+
providerWebSocket.closeHandler(v -> serverWebsocket.close());
45+
providerWebSocket.textMessageHandler(m -> {
46+
serverWebsocket.writeTextMessage(m);
47+
});
48+
serverWebsocket.textMessageHandler(m -> {
49+
providerWebSocket.writeTextMessage(m);
50+
});
51+
}
52+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.servicecomb.samples;
19+
20+
import org.springframework.boot.WebApplicationType;
21+
import org.springframework.boot.autoconfigure.SpringBootApplication;
22+
import org.springframework.boot.builder.SpringApplicationBuilder;
23+
24+
@SpringBootApplication
25+
public class ConsulConsumerApplication {
26+
public static void main(String[] args) throws Exception {
27+
try {
28+
new SpringApplicationBuilder().web(WebApplicationType.NONE).sources(ConsulConsumerApplication.class).run(args);
29+
} catch (Exception e) {
30+
e.printStackTrace();
31+
}
32+
}
33+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.servicecomb.samples;
19+
20+
import org.apache.servicecomb.provider.pojo.RpcReference;
21+
import org.apache.servicecomb.provider.rest.common.RestSchema;
22+
import org.springframework.http.MediaType;
23+
import org.springframework.web.bind.annotation.GetMapping;
24+
import org.springframework.web.bind.annotation.PostMapping;
25+
import org.springframework.web.bind.annotation.RequestBody;
26+
import org.springframework.web.bind.annotation.RequestMapping;
27+
import org.springframework.web.bind.annotation.RequestParam;
28+
import org.springframework.web.bind.annotation.ResponseBody;
29+
30+
@RestSchema(schemaId = "ConsumerController")
31+
@RequestMapping(path = "/")
32+
public class ConsumerController {
33+
@RpcReference(schemaId = "ProviderController", microserviceName = "provider")
34+
private ProviderService providerService;
35+
36+
// consumer service which delegate the implementation to provider service.
37+
@GetMapping("/sayHello")
38+
public String sayHello(@RequestParam("name") String name) {
39+
return providerService.sayHello(name);
40+
}
41+
42+
@GetMapping("/getConfig")
43+
public String getConfig(@RequestParam("key") String key) {
44+
return providerService.getConfig(key);
45+
}
46+
47+
@PostMapping(path = "/testContentType", consumes = MediaType.APPLICATION_JSON_VALUE)
48+
@ResponseBody
49+
public User testContentType(@RequestBody User user) {
50+
return providerService.testContentType(user);
51+
}
52+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.servicecomb.samples;
19+
20+
import java.util.List;
21+
22+
import org.apache.servicecomb.demo.api.IHeaderParamWithListSchemaSpringMvc;
23+
import org.apache.servicecomb.provider.pojo.RpcReference;
24+
import org.apache.servicecomb.provider.rest.common.RestSchema;
25+
26+
@RestSchema(schemaId = "ConsumerHeaderParamWithListSchema", schemaInterface = IHeaderParamWithListSchemaSpringMvc.class)
27+
public class ConsumerHeaderParamWithListSchema implements IHeaderParamWithListSchemaSpringMvc {
28+
@RpcReference(microserviceName = "provider", schemaId = "HeaderParamWithListSchema")
29+
private IHeaderParamWithListSchemaSpringMvc provider;
30+
31+
@Override
32+
public String headerListDefault(List<String> headerList) {
33+
return provider.headerListDefault(headerList);
34+
}
35+
36+
@Override
37+
public String headerListCSV(List<String> headerList) {
38+
return provider.headerListCSV(headerList);
39+
}
40+
41+
@Override
42+
public String headerListMULTI(List<String> headerList) {
43+
return provider.headerListMULTI(headerList);
44+
}
45+
46+
@Override
47+
public String headerListSSV(List<String> headerList) {
48+
return provider.headerListSSV(headerList);
49+
}
50+
51+
@Override
52+
public String headerListPIPES(List<String> headerList) {
53+
return provider.headerListPIPES(headerList);
54+
}
55+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.servicecomb.samples;
18+
19+
20+
import org.apache.servicecomb.core.CoreConst;
21+
import org.apache.servicecomb.core.annotation.Transport;
22+
import org.apache.servicecomb.provider.pojo.RpcReference;
23+
import org.apache.servicecomb.provider.rest.common.RestSchema;
24+
import org.reactivestreams.Publisher;
25+
import org.springframework.web.bind.annotation.GetMapping;
26+
import org.springframework.web.bind.annotation.RequestMapping;
27+
28+
@RestSchema(schemaId = "ReactiveStreamController")
29+
@RequestMapping(path = "/")
30+
public class ConsumerReactiveStreamController {
31+
interface ProviderReactiveStreamController {
32+
Publisher<String> sseString();
33+
34+
Publisher<Model> sseModel();
35+
}
36+
37+
@RpcReference(microserviceName = "provider", schemaId = "ReactiveStreamController")
38+
ProviderReactiveStreamController controller;
39+
40+
public static class Model {
41+
private String name;
42+
43+
private int age;
44+
45+
public Model() {
46+
47+
}
48+
49+
public Model(String name, int age) {
50+
this.name = name;
51+
this.age = age;
52+
}
53+
54+
public int getAge() {
55+
return age;
56+
}
57+
58+
public Model setAge(int age) {
59+
this.age = age;
60+
return this;
61+
}
62+
63+
public String getName() {
64+
return name;
65+
}
66+
67+
public Model setName(String name) {
68+
this.name = name;
69+
return this;
70+
}
71+
}
72+
73+
@GetMapping("/sseString")
74+
@Transport(name = CoreConst.RESTFUL)
75+
public Publisher<String> sseString() {
76+
return controller.sseString();
77+
}
78+
79+
@GetMapping("/sseModel")
80+
@Transport(name = CoreConst.RESTFUL)
81+
public Publisher<Model> sseModel() {
82+
return controller.sseModel();
83+
}
84+
}

0 commit comments

Comments
 (0)