liubao68 closed pull request #791: [SCB-716] Implementation of Local Service 
Registry Demo
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/791
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/demo/demo-local-service-registry/local-registry-client/pom.xml 
b/demo/demo-local-service-registry/local-registry-client/pom.xml
new file mode 100644
index 000000000..45396fa39
--- /dev/null
+++ b/demo/demo-local-service-registry/local-registry-client/pom.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0"?>
+<!--
+  ~ 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
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";
+  xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.servicecomb.demo</groupId>
+    <artifactId>demo-local-service-registry</artifactId>
+    <version>1.0.0-m2-SNAPSHOT</version>
+  </parent>
+  <artifactId>local-registry-client</artifactId>
+  <name>Java Chassis::Demo::LocalServiceRegistry::Client</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.servicecomb.demo</groupId>
+      <artifactId>demo-schema</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.servicecomb</groupId>
+      <artifactId>provider-springmvc</artifactId>
+    </dependency>
+  </dependencies>
+
+  <properties>
+    
<demo.main>org.apache.servicecomb.demo.localregistry.LocalRegistryClient</demo.main>
+  </properties>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-dependency-plugin</artifactId>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git 
a/demo/demo-local-service-registry/local-registry-client/src/main/java/org/apache/servicecomb/demo/localregistry/localregistryclient/LocalRegistryClient.java
 
b/demo/demo-local-service-registry/local-registry-client/src/main/java/org/apache/servicecomb/demo/localregistry/localregistryclient/LocalRegistryClient.java
new file mode 100644
index 000000000..176336165
--- /dev/null
+++ 
b/demo/demo-local-service-registry/local-registry-client/src/main/java/org/apache/servicecomb/demo/localregistry/localregistryclient/LocalRegistryClient.java
@@ -0,0 +1,76 @@
+/*
+ * 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.demo.localregistry.localregistryclient;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.servicecomb.core.CseContext;
+import org.apache.servicecomb.demo.DemoConst;
+import org.apache.servicecomb.demo.TestMgr;
+import org.apache.servicecomb.demo.validator.Student;
+import org.apache.servicecomb.foundation.common.utils.BeanUtils;
+import org.apache.servicecomb.foundation.common.utils.Log4jUtils;
+import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
+import org.springframework.web.client.RestTemplate;
+
+public class LocalRegistryClient {
+  private static RestTemplate templateNew = RestTemplateBuilder.create();
+
+  public static void main(String[] args) throws Exception {
+    System.setProperty("local.registry.file", 
"src/main/resources/registry.yaml");
+    init();
+
+    run();
+
+    TestMgr.summary();
+    System.clearProperty("local.registry.file");
+  }
+
+  public static void init() throws Exception {
+    Log4jUtils.init();
+    BeanUtils.init();
+  }
+
+  public static void run() throws Exception {
+    testLocalRegistry(templateNew);
+  }
+
+  private static void testLocalRegistry(RestTemplate template) throws 
Exception {
+    String microserviceName = "localserv";
+    for (String transport : DemoConst.transports) {
+      
CseContext.getInstance().getConsumerProviderManager().setTransport(microserviceName,
 transport);
+      TestMgr.setMsg(microserviceName, transport);
+
+      String cseUrlPrefix = "cse://" + microserviceName + 
"/localservregistry/";
+
+      Map<String, String> params = new HashMap<>();
+      params.put("a", "5");
+      params.put("b", "20");
+      int result = template.postForObject(cseUrlPrefix + "add", params, 
Integer.class);
+      TestMgr.check(25, result);
+
+      Student student = new Student();
+      student.setName("king");
+      student.setAge(30);
+      Student res = template.postForObject(cseUrlPrefix + "sayhi", student, 
Student.class);
+      TestMgr.check("hello king", res.getName());
+      TestMgr.check(30, res.getAge());
+    }
+  }
+}
diff --git 
a/demo/demo-local-service-registry/local-registry-client/src/main/resources/microservice.yaml
 
b/demo/demo-local-service-registry/local-registry-client/src/main/resources/microservice.yaml
new file mode 100644
index 000000000..4a4da5a2d
--- /dev/null
+++ 
b/demo/demo-local-service-registry/local-registry-client/src/main/resources/microservice.yaml
@@ -0,0 +1,26 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+APPLICATION_ID: localservreg
+service_description:
+  name: localclient
+  version: 0.0.1
+servicecomb:
+  handler:
+    chain:
+      Consumer:
+        default: bizkeeper-consumer,loadbalance
diff --git 
a/demo/demo-local-service-registry/local-registry-client/src/main/resources/microservices/localserv/localservregistry.yaml
 
b/demo/demo-local-service-registry/local-registry-client/src/main/resources/microservices/localserv/localservregistry.yaml
new file mode 100644
index 000000000..4848d69b6
--- /dev/null
+++ 
b/demo/demo-local-service-registry/local-registry-client/src/main/resources/microservices/localserv/localservregistry.yaml
@@ -0,0 +1,75 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+swagger: "2.0"
+info:
+  version: "1.0.0"
+  title: "swagger definition for 
org.apache.servicecomb.demo.localregistry.localregistryserver.LocalServerApi"
+  x-java-interface: 
"cse.gen.localservreg.localserv.localservregistry.LocalServerApiIntf"
+basePath: "/localservregistry"
+consumes:
+- "application/json"
+produces:
+- "application/json"
+paths:
+  /add:
+    post:
+      operationId: "add"
+      parameters:
+      - name: "a"
+        in: "formData"
+        required: false
+        type: "integer"
+        format: "int32"
+      - name: "b"
+        in: "formData"
+        required: false
+        type: "integer"
+        format: "int32"
+      responses:
+        200:
+          description: "response of 200"
+          schema:
+            type: "integer"
+            format: "int32"
+  /sayhi:
+    post:
+      operationId: "sayHi"
+      parameters:
+      - in: "body"
+        name: "student"
+        required: false
+        schema:
+          $ref: "#/definitions/Student"
+      responses:
+        200:
+          description: "response of 200"
+          schema:
+            $ref: "#/definitions/Student"
+definitions:
+  Student:
+    type: "object"
+    required:
+    - "name"
+    properties:
+      name:
+        type: "string"
+      age:
+        type: "integer"
+        format: "int32"
+        maximum: 20
+    x-java-class: "org.apache.servicecomb.demo.validator.Student"
diff --git 
a/demo/demo-local-service-registry/local-registry-client/src/main/resources/registry.yaml
 
b/demo/demo-local-service-registry/local-registry-client/src/main/resources/registry.yaml
new file mode 100644
index 000000000..19d68a4af
--- /dev/null
+++ 
b/demo/demo-local-service-registry/local-registry-client/src/main/resources/registry.yaml
@@ -0,0 +1,27 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+localserv:
+  - id: "100"
+    version: "0.0.1"
+    appid: localservreg
+    schemaIds:
+      - localservregistry
+    instances:
+      - endpoints:
+        - rest://localhost:8080
+        - highway://localhost:7070
\ No newline at end of file
diff --git a/demo/demo-local-service-registry/local-registry-server/pom.xml 
b/demo/demo-local-service-registry/local-registry-server/pom.xml
new file mode 100644
index 000000000..8b35ed441
--- /dev/null
+++ b/demo/demo-local-service-registry/local-registry-server/pom.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0"?>
+<!--
+  ~ 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
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";
+  xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.servicecomb.demo</groupId>
+    <artifactId>demo-local-service-registry</artifactId>
+    <version>1.0.0-m2-SNAPSHOT</version>
+  </parent>
+  <artifactId>local-registry-server</artifactId>
+  <name>Java Chassis::Demo::LocalRegistry::Server</name>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.servicecomb.demo</groupId>
+      <artifactId>demo-schema</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.servicecomb</groupId>
+      <artifactId>provider-jaxrs</artifactId>
+    </dependency>
+  </dependencies>
+  <properties>
+    
<demo.main>org.apache.servicecomb.demo.localregistry.localregistryserver.LocalRegistryServer</demo.main>
+  </properties>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-dependency-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>1.0.0-m2-SNAPSHOT</version>
+            </mixin>
+          </mixins>
+        </configuration>
+      </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>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
+</project>
diff --git 
a/demo/demo-local-service-registry/local-registry-server/src/main/java/org/apache/servicecomb/demo/localregistry/localregistryserver/LocalRegistryServer.java
 
b/demo/demo-local-service-registry/local-registry-server/src/main/java/org/apache/servicecomb/demo/localregistry/localregistryserver/LocalRegistryServer.java
new file mode 100644
index 000000000..7a1c0483b
--- /dev/null
+++ 
b/demo/demo-local-service-registry/local-registry-server/src/main/java/org/apache/servicecomb/demo/localregistry/localregistryserver/LocalRegistryServer.java
@@ -0,0 +1,28 @@
+/*
+ * 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.demo.localregistry.localregistryserver;
+
+import org.apache.servicecomb.foundation.common.utils.BeanUtils;
+import org.apache.servicecomb.foundation.common.utils.Log4jUtils;
+
+public class LocalRegistryServer {
+  public static void main(String[] args) throws Exception {
+    Log4jUtils.init();
+    BeanUtils.init();
+  }
+}
diff --git 
a/demo/demo-local-service-registry/local-registry-server/src/main/java/org/apache/servicecomb/demo/localregistry/localregistryserver/LocalServerApi.java
 
b/demo/demo-local-service-registry/local-registry-server/src/main/java/org/apache/servicecomb/demo/localregistry/localregistryserver/LocalServerApi.java
new file mode 100644
index 000000000..514ba9173
--- /dev/null
+++ 
b/demo/demo-local-service-registry/local-registry-server/src/main/java/org/apache/servicecomb/demo/localregistry/localregistryserver/LocalServerApi.java
@@ -0,0 +1,47 @@
+/*
+ * 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.demo.localregistry.localregistryserver;
+
+import javax.ws.rs.FormParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.servicecomb.demo.validator.Student;
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+
+@RestSchema(schemaId = "localservregistry")
+@Path("/localservregistry")
+@Produces(MediaType.APPLICATION_JSON)
+public class LocalServerApi {
+
+  @Path("/add")
+  @POST
+  public int add(@FormParam("a") int a, @FormParam("b") int b) {
+    return a + b;
+  }
+
+  @Path("/sayhi")
+  @POST
+  public Student sayHi(Student student) {
+    student.setName("hello " + student.getName());
+    student.setAge(student.getAge());
+    return student;
+  }
+}
diff --git 
a/demo/demo-local-service-registry/local-registry-server/src/main/resources/microservice.yaml
 
b/demo/demo-local-service-registry/local-registry-server/src/main/resources/microservice.yaml
new file mode 100644
index 000000000..ed2b8fc38
--- /dev/null
+++ 
b/demo/demo-local-service-registry/local-registry-server/src/main/resources/microservice.yaml
@@ -0,0 +1,30 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+APPLICATION_ID: localservreg
+service_description:
+  name: localserv
+  version: 0.0.1
+servicecomb:
+  rest:
+    address: 0.0.0.0:8080
+  highway:
+    address: 0.0.0.0:7070
+  handler:
+    chain:
+      Provider:
+        default: bizkeeper-provider
diff --git a/demo/demo-local-service-registry/pom.xml 
b/demo/demo-local-service-registry/pom.xml
new file mode 100644
index 000000000..9be8590de
--- /dev/null
+++ b/demo/demo-local-service-registry/pom.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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-parent</artifactId>
+    <version>1.0.0-m2-SNAPSHOT</version>
+  </parent>
+  <artifactId>demo-local-service-registry</artifactId>
+  <name>Java Chassis::Demo::Local service registry</name>
+  <packaging>pom</packaging>
+  <modules>
+    <module>local-registry-server</module>
+    <module>local-registry-client</module>
+  </modules>
+
+</project>
diff --git a/demo/pom.xml b/demo/pom.xml
index 72c89e010..822a394b5 100644
--- a/demo/pom.xml
+++ b/demo/pom.xml
@@ -37,6 +37,7 @@
     <module>demo-server-servlet</module>
     <module>demo-pojo</module>
     <module>demo-jaxrs</module>
+    <module>demo-local-service-registry</module>
 
     <module>demo-springmvc</module>
     <module>demo-schema</module>


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to