-
Notifications
You must be signed in to change notification settings - Fork 821
[SCB-716] Implementation of Local Service Registry Demo #791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
005596e
[SCB-716] Implementation of Local service registry demo
maheshrajus f6694de
[SCB-716] Java Chassis- Implementation of Local service registry demo…
maheshrajus 07b1448
[SCB-716] Implementation of Local service registry sample: readme mod…
maheshrajus fbd6abf
[SCB-716] Implementation of Local service registry sample: changing t…
maheshrajus 9b084cc
[SCB-716] Implementation of Local service registry samples: Review co…
maheshrajus 93a15bf
Merge branch 'master' into master
maheshrajus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,49 @@ | ||
| ## Local registry | ||
|
|
||
| User can use local registry mechanisam and can connect server endpoints without using service center. | ||
| For local registry mechanism user should provide the local registry file at consumer side. | ||
| User can start provider service and get the provider schema file and put at the consumer side. | ||
| Consumer will use local registry function and it will connect the server end points. | ||
|
|
||
| Please find the details as follows. | ||
|
|
||
| ## Provider Side | ||
|
|
||
| * run the provider with/without service center and get the schema file. | ||
|
|
||
| ## Consumer Side changes | ||
|
|
||
| * Add local registry file registry.yaml : | ||
|
|
||
| ```yaml | ||
| localserv: | ||
| - id: "100" | ||
| version: "0.0.1" | ||
| appid: localservreg | ||
| schemaIds: | ||
| - localservregistry | ||
| instances: | ||
| - endpoints: | ||
| - rest://localhost:8080 | ||
| - highway://localhost:7070 | ||
| ``` | ||
|
|
||
| * Add the following code at the beginning and end of the service consumer Main function | ||
|
|
||
| ```java | ||
| public class xxxClient { | ||
| public static void main(String[] args) { | ||
| System.setProperty("local.registry.file", "/yourpath/registry.yaml"); | ||
| //your code | ||
| System.clearProperty("local.registry.file"); | ||
| } | ||
| } | ||
| ``` | ||
| If file present in this path "local.registry.file" then registry mode is Local registry mode. It will not connect to service center. | ||
|
|
||
| * Add provider's schema file at below location of consumer side | ||
|
|
||
| src/main/resources/microservices/{microserviceName}/{schemaId.yaml} | ||
| -here microserviceName is servers's microservice name. Like this multiple schemaId files we can put in same location. | ||
|
|
||
| * Run the consumer and verify the API's output. | ||
71 changes: 71 additions & 0 deletions
71
samples/local-service-registry/local-registry-client/pom.xml
This file contains hidden or 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,71 @@ | ||
| <?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.samples</groupId> | ||
| <artifactId>local-service-registry</artifactId> | ||
| <version>1.0.0-SNAPSHOT</version> | ||
| </parent> | ||
| <artifactId>local-registry-client</artifactId> | ||
| <name>Java Chassis::Demo::LocalServiceRegistry::Client</name> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.apache.servicecomb.samples</groupId> | ||
| <artifactId>common-schema</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.servicecomb</groupId> | ||
| <artifactId>provider-springmvc</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.servicecomb</groupId> | ||
| <artifactId>transport-highway</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.servicecomb</groupId> | ||
| <artifactId>transport-rest-vertx</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.servicecomb</groupId> | ||
| <artifactId>handler-bizkeeper</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.slf4j</groupId> | ||
| <artifactId>slf4j-log4j12</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.servicecomb</groupId> | ||
| <artifactId>handler-loadbalance</artifactId> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-dependency-plugin</artifactId> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
|
|
||
| </project> |
68 changes: 68 additions & 0 deletions
68
...org/apache/servicecomb/samples/localregistry/localregistryclient/LocalRegistryClient.java
This file contains hidden or 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,68 @@ | ||
| /* | ||
| * 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.localregistry.localregistryclient; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| 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.apache.servicecomb.samples.common.schema.models.Person; | ||
| 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(); | ||
| } | ||
|
|
||
| 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"; | ||
| 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); | ||
| System.out.println(result); | ||
|
|
||
| Person person = new Person(); | ||
| person.setName("local registry test"); | ||
| Person sayHiResult = template | ||
| .postForObject( | ||
| cseUrlPrefix + "sayhi", | ||
| person, | ||
| Person.class); | ||
|
|
||
| System.out.println(sayHiResult.getName()); | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
samples/local-service-registry/local-registry-client/src/main/resources/microservice.yaml
This file contains hidden or 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,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 |
69 changes: 69 additions & 0 deletions
69
...vice-registry/local-registry-client/src/main/resources/microservices/localserv/hello.yaml
This file contains hidden or 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,69 @@ | ||
| ## --------------------------------------------------------------------------- | ||
| ## 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.samples.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/Person" | ||
| responses: | ||
| 200: | ||
| description: "response of 200" | ||
| schema: | ||
| $ref: "#/definitions/Person" | ||
| definitions: | ||
| Person: | ||
| type: "object" | ||
| properties: | ||
| name: | ||
| type: "string" | ||
| x-java-class: "org.apache.servicecomb.samples.common.schema.models.Person" |
27 changes: 27 additions & 0 deletions
27
samples/local-service-registry/local-registry-client/src/main/resources/registry.yaml
This file contains hidden or 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,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: | ||
| - hello | ||
| instances: | ||
| - endpoints: | ||
| - rest://localhost:8080 | ||
| - highway://localhost:7070 |
78 changes: 78 additions & 0 deletions
78
samples/local-service-registry/local-registry-server/pom.xml
This file contains hidden or 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,78 @@ | ||
| <?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.samples</groupId> | ||
| <artifactId>local-service-registry</artifactId> | ||
| <version>1.0.0-SNAPSHOT</version> | ||
| </parent> | ||
| <artifactId>local-registry-server</artifactId> | ||
| <name>Java Chassis::Demo::LocalRegistry::Server</name> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.apache.servicecomb.samples</groupId> | ||
| <artifactId>common-schema</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.servicecomb</groupId> | ||
| <artifactId>provider-jaxrs</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.servicecomb</groupId> | ||
| <artifactId>transport-highway</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.servicecomb</groupId> | ||
| <artifactId>transport-rest-vertx</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.servicecomb</groupId> | ||
| <artifactId>handler-bizkeeper</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.slf4j</groupId> | ||
| <artifactId>slf4j-log4j12</artifactId> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <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-SNAPSHOT</version> | ||
| </mixin> | ||
| </mixins> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why we need a clear action?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is System property, better to clear after our work.