Skip to content
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

update using API first development #140

Merged
merged 1 commit into from
Apr 24, 2024
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
32 changes: 32 additions & 0 deletions basic/apis/consumer-api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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.samples</groupId>
<artifactId>basic-apis</artifactId>
<version>3.0-SNAPSHOT</version>
</parent>

<artifactId>basic-consumer-api</artifactId>
<packaging>jar</packaging>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.api;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@RequestMapping(path = "/")
public interface ConsumerService {
@GetMapping("/sayHello")
String sayHello(@RequestParam("name") String name);

@GetMapping("/exampleConfig")
String exampleConfig();
}
37 changes: 37 additions & 0 deletions basic/apis/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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.samples</groupId>
<artifactId>basic-application</artifactId>
<version>3.0-SNAPSHOT</version>
</parent>

<artifactId>basic-apis</artifactId>
<packaging>pom</packaging>

<modules>
<module>provider-api</module>
<module>consumer-api</module>
</modules>

</project>
32 changes: 32 additions & 0 deletions basic/apis/provider-api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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.samples</groupId>
<artifactId>basic-apis</artifactId>
<version>3.0-SNAPSHOT</version>
</parent>

<artifactId>basic-provider-api</artifactId>
<packaging>jar</packaging>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@
* limitations under the License.
*/

package org.apache.servicecomb.samples;
package org.apache.servicecomb.samples.api;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@RequestMapping(path = "/provider")
public interface ProviderService {
String sayHello(String name);
@GetMapping("/sayHello")
String sayHello(@RequestParam("name") String name);

@GetMapping("/exampleConfig")
String exampleConfig();
}
10 changes: 10 additions & 0 deletions basic/consumer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
<groupId>org.apache.servicecomb</groupId>
<artifactId>java-chassis-spring-boot-starter-standalone</artifactId>
</dependency>
<dependency>
<groupId>org.apache.servicecomb.samples</groupId>
<artifactId>basic-consumer-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.servicecomb.samples</groupId>
<artifactId>basic-provider-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,26 @@

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;
import org.apache.servicecomb.samples.api.ConsumerService;
import org.apache.servicecomb.samples.api.ProviderService;
import org.springframework.beans.factory.annotation.Autowired;

@RestSchema(schemaId = "ConsumerController")
@RequestMapping(path = "/")
public class ConsumerController {
@RpcReference(schemaId = "ProviderController", microserviceName = "provider")
@RestSchema(schemaId = "ConsumerController", schemaInterface = ConsumerService.class)
public class ConsumerController implements ConsumerService {
private ProviderService providerService;

// consumer service which delegate the implementation to provider service.
@GetMapping("/sayHello")
public String sayHello(@RequestParam("name") String name) {
@Autowired
public void setProviderService(ProviderService providerService) {
this.providerService = providerService;
}

@Override
public String sayHello(String name) {
return providerService.sayHello(name);
}

@GetMapping("/exampleConfig")
@Override
public String exampleConfig() {
return providerService.exampleConfig();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.Invoker;
import org.apache.servicecomb.samples.api.ProviderService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ProviderServiceConfiguration {
@Bean
public ProviderService providerService() {
return Invoker.createProxy("provider", "ProviderController", ProviderService.class);
}
}
3 changes: 2 additions & 1 deletion basic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<servicecomb.version>3.0.0</servicecomb.version>
<servicecomb.version>3.1.0</servicecomb.version>
<spring-boot-maven-plugin.version>3.1.3</spring-boot-maven-plugin.version>
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
</properties>
Expand Down Expand Up @@ -102,6 +102,7 @@
</profiles>

<modules>
<module>apis</module>
<module>provider</module>
<module>consumer</module>
<module>gateway</module>
Expand Down
5 changes: 5 additions & 0 deletions basic/provider/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
<groupId>org.apache.servicecomb</groupId>
<artifactId>java-chassis-spring-boot-starter-standalone</artifactId>
</dependency>
<dependency>
<groupId>org.apache.servicecomb.samples</groupId>
<artifactId>basic-provider-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@

import org.apache.servicecomb.config.DynamicProperties;
import org.apache.servicecomb.provider.rest.common.RestSchema;
import org.apache.servicecomb.samples.api.ProviderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@RestSchema(schemaId = "ProviderController")
@RequestMapping(path = "/")
public class ProviderController {
@RestSchema(schemaId = "ProviderController", schemaInterface = ProviderService.class)
public class ProviderController implements ProviderService {
private DynamicProperties dynamicProperties;

private String example;
Expand All @@ -38,13 +35,12 @@ public ProviderController(DynamicProperties dynamicProperties) {
value -> this.example = value, "not set");
}

// a very simple service to echo the request parameter
@GetMapping("/sayHello")
public String sayHello(@RequestParam("name") String name) {
@Override
public String sayHello(String name) {
return "Hello " + name;
}

@GetMapping("/exampleConfig")
@Override
public String exampleConfig() {
return example;
}
Expand Down
Loading