Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions samples/local-service-registry/README.md
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");
Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

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.

}
}
```
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 samples/local-service-registry/local-registry-client/pom.xml
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>
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());
}
}
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
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"
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 samples/local-service-registry/local-registry-server/pom.xml
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>
Loading