-
Notifications
You must be signed in to change notification settings - Fork 812
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SCB-2892]support Etcd as Discovery (#4564)
Co-authored-by: chenzhida <[email protected]>
- Loading branch information
1 parent
f1d74e6
commit 19e2610
Showing
49 changed files
with
3,093 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Notice | ||
|
||
This integration tests is designed for Etcd registry and configuration. And extra test cases include: | ||
|
||
* Test cases related to SpringMVC annotations that demo-springmvc can not cover. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<!-- | ||
~ Licensed to the Apache Software Foundation (ASF) under one or more | ||
~ contributor license agreements. See the NOTICE file distributed with | ||
~ this work for additional information regarding copyright ownership. | ||
~ The ASF licenses this file to You under the Apache License, Version 2.0 | ||
~ (the "License"); you may not use this file except in compliance with | ||
~ the License. You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.apache.servicecomb.demo</groupId> | ||
<artifactId>demo-etcd</artifactId> | ||
<version>3.3.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>etcd-consumer</artifactId> | ||
<name>Java Chassis::Demo::Etcd::CONSUMER</name> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.servicecomb</groupId> | ||
<artifactId>java-chassis-spring-boot-starter-standalone</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.protobuf</groupId> | ||
<artifactId>protobuf-java</artifactId> | ||
<version>3.25.3</version> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.servicecomb</groupId> | ||
<artifactId>registry-etcd</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<profiles> | ||
<profile> | ||
<id>docker</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.fabric8</groupId> | ||
<artifactId>docker-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.commonjava.maven.plugins</groupId> | ||
<artifactId>directory-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.github.odavid.maven.plugins</groupId> | ||
<artifactId>mixin-maven-plugin</artifactId> | ||
<configuration> | ||
<mixins> | ||
<mixin> | ||
<groupId>org.apache.servicecomb.demo</groupId> | ||
<artifactId>docker-build-config</artifactId> | ||
<version>${project.version}</version> | ||
</mixin> | ||
</mixins> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
52 changes: 52 additions & 0 deletions
52
...etcd/consumer/src/main/java/org/apache/servicecomb/samples/ClientWebsocketController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.servicecomb.samples; | ||
|
||
import org.apache.servicecomb.core.CoreConst; | ||
import org.apache.servicecomb.core.annotation.Transport; | ||
import org.apache.servicecomb.provider.pojo.RpcReference; | ||
import org.apache.servicecomb.provider.rest.common.RestSchema; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
import io.vertx.core.http.ServerWebSocket; | ||
import io.vertx.core.http.WebSocket; | ||
|
||
@RestSchema(schemaId = "ClientWebsocketController") | ||
@RequestMapping(path = "/ws") | ||
public class ClientWebsocketController { | ||
interface ProviderService { | ||
WebSocket websocket(); | ||
} | ||
|
||
@RpcReference(schemaId = "WebsocketController", microserviceName = "provider") | ||
private ProviderService providerService; | ||
|
||
@PostMapping("/websocket") | ||
@Transport(name = CoreConst.WEBSOCKET) | ||
public void websocket(ServerWebSocket serverWebsocket) { | ||
WebSocket providerWebSocket = providerService.websocket(); | ||
providerWebSocket.closeHandler(v -> serverWebsocket.close()); | ||
providerWebSocket.textMessageHandler(m -> { | ||
serverWebsocket.writeTextMessage(m); | ||
}); | ||
serverWebsocket.textMessageHandler(m -> { | ||
providerWebSocket.writeTextMessage(m); | ||
}); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
demo/demo-etcd/consumer/src/main/java/org/apache/servicecomb/samples/ConsumerController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.servicecomb.samples; | ||
|
||
import org.apache.servicecomb.provider.pojo.RpcReference; | ||
import org.apache.servicecomb.provider.rest.common.RestSchema; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
@RestSchema(schemaId = "ConsumerController") | ||
@RequestMapping(path = "/") | ||
public class ConsumerController { | ||
@RpcReference(schemaId = "ProviderController", microserviceName = "provider") | ||
private ProviderService providerService; | ||
|
||
// consumer service which delegate the implementation to provider service. | ||
@GetMapping("/sayHello") | ||
public String sayHello(@RequestParam("name") String name) { | ||
return providerService.sayHello(name); | ||
} | ||
|
||
@GetMapping("/getConfig") | ||
public String getConfig(@RequestParam("key") String key) { | ||
return providerService.getConfig(key); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...sumer/src/main/java/org/apache/servicecomb/samples/ConsumerHeaderParamWithListSchema.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.servicecomb.samples; | ||
|
||
import java.util.List; | ||
|
||
import org.apache.servicecomb.demo.api.IHeaderParamWithListSchemaSpringMvc; | ||
import org.apache.servicecomb.provider.pojo.RpcReference; | ||
import org.apache.servicecomb.provider.rest.common.RestSchema; | ||
|
||
@RestSchema(schemaId = "ConsumerHeaderParamWithListSchema", schemaInterface = IHeaderParamWithListSchemaSpringMvc.class) | ||
public class ConsumerHeaderParamWithListSchema implements IHeaderParamWithListSchemaSpringMvc { | ||
@RpcReference(microserviceName = "provider", schemaId = "HeaderParamWithListSchema") | ||
private IHeaderParamWithListSchemaSpringMvc provider; | ||
|
||
@Override | ||
public String headerListDefault(List<String> headerList) { | ||
return provider.headerListDefault(headerList); | ||
} | ||
|
||
@Override | ||
public String headerListCSV(List<String> headerList) { | ||
return provider.headerListCSV(headerList); | ||
} | ||
|
||
@Override | ||
public String headerListMULTI(List<String> headerList) { | ||
return provider.headerListMULTI(headerList); | ||
} | ||
|
||
@Override | ||
public String headerListSSV(List<String> headerList) { | ||
return provider.headerListSSV(headerList); | ||
} | ||
|
||
@Override | ||
public String headerListPIPES(List<String> headerList) { | ||
return provider.headerListPIPES(headerList); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
...nsumer/src/main/java/org/apache/servicecomb/samples/ConsumerReactiveStreamController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.servicecomb.samples; | ||
|
||
|
||
import org.apache.servicecomb.core.CoreConst; | ||
import org.apache.servicecomb.core.annotation.Transport; | ||
import org.apache.servicecomb.provider.pojo.RpcReference; | ||
import org.apache.servicecomb.provider.rest.common.RestSchema; | ||
import org.reactivestreams.Publisher; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
@RestSchema(schemaId = "ReactiveStreamController") | ||
@RequestMapping(path = "/") | ||
public class ConsumerReactiveStreamController { | ||
interface ProviderReactiveStreamController { | ||
Publisher<String> sseString(); | ||
|
||
Publisher<Model> sseModel(); | ||
} | ||
|
||
@RpcReference(microserviceName = "provider", schemaId = "ReactiveStreamController") | ||
ProviderReactiveStreamController controller; | ||
|
||
public static class Model { | ||
private String name; | ||
|
||
private int age; | ||
|
||
public Model() { | ||
|
||
} | ||
|
||
public Model(String name, int age) { | ||
this.name = name; | ||
this.age = age; | ||
} | ||
|
||
public int getAge() { | ||
return age; | ||
} | ||
|
||
public Model setAge(int age) { | ||
this.age = age; | ||
return this; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public Model setName(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
} | ||
|
||
@GetMapping("/sseString") | ||
@Transport(name = CoreConst.RESTFUL) | ||
public Publisher<String> sseString() { | ||
return controller.sseString(); | ||
} | ||
|
||
@GetMapping("/sseModel") | ||
@Transport(name = CoreConst.RESTFUL) | ||
public Publisher<Model> sseModel() { | ||
return controller.sseModel(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...o-etcd/consumer/src/main/java/org/apache/servicecomb/samples/EtcdConsumerApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.servicecomb.samples; | ||
|
||
import org.springframework.boot.WebApplicationType; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.builder.SpringApplicationBuilder; | ||
|
||
@SpringBootApplication | ||
public class EtcdConsumerApplication { | ||
public static void main(String[] args) throws Exception { | ||
try { | ||
new SpringApplicationBuilder().web(WebApplicationType.NONE).sources(EtcdConsumerApplication.class).run(args); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
demo/demo-etcd/consumer/src/main/java/org/apache/servicecomb/samples/ProviderService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.servicecomb.samples; | ||
|
||
public interface ProviderService { | ||
String sayHello(String name); | ||
|
||
String getConfig(String key); | ||
} |
Oops, something went wrong.