ServiceComb Java Chassis supports generating provider-service API implicitly. When the service is started, an API is automatically generated and registered to the service center.
When you develop a microservice in transparent RPC mode, the code does not show how you want to define an API, and all generated APIs are POST methods, The input parameters of all the methods will be packaged as a class and transferred as body parameters. Therefore, if you develop providers using implicit APIs, you are advised to choose Spring MVC or JAX-RS mode to obtain complete RESTful statements.
For detail information please refer to Doc
-
Start the ServiceComb/Service Center
- how to start the service center
- make sure service center address is configured correctly in
microservice.yamlfile
cse: service: registry: address: http://127.0.0.1:30100 #service center address
-
Start the codefirst-provider service
-
Start provider service via maven
Compile the source code at root directory of ServiceComb Java Chassis, which is
servicecomb-java-chassis/, and usemvn execto execute the main classCodeFirstProviderMain.cd servicecomb-java-chassis/ mvn clean install -Psamples -DskipTests #only need to install at first time. cd samples/codefirst-sample/codefirst-provider/ mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.codefirst.provider.CodeFirstProviderMain"
-
Start provider service via gradle
Compile the source code at root directory of ServiceComb Java Chassis, which is
servicecomb-java-chassis/, and usemvn execto execute the main classCodeFirstProviderMain.cd servicecomb-java-chassis/ mvn clean install -Psamples -DskipTests #only need to install at first time. cd samples/codefirst-sample/codefirst-provider/ gradle clean run
-
Start provider service via IDE
Import the project by InteliJ IDEA or Eclipse, add sample module to pom.xml file in root module
servicecomb-java-chassis/pom.xml, and add<module>samples</module>to<modules></modules>block, Then findmainfunctionCodeFirstProviderMainof provider service andRUNit like any other Java program.
-
-
Start the codefirst-consumer service
cd samples/codefirst-sample/codefirst-consumer/-
Start consumer service via maven
Just like how to start codefirst-provider service. But the main class of codefirst-consumer service is
CodeFirstConsumerMain.mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.codefirst.consumer.CodeFirstConsumerMain" -
Start consumer service via gradle
gradle clean run
-
-
How to verify On the producer side, the output should contain the following stuffs if the producer starts up successfully:
- 'swagger: 2.0 info: version: 1.0.0 ...' means the producer generated swagger contracts
- 'rest listen success. address=0.0.0.0:8080' means the rest endpoint is listening on port 8080
- 'highway listen success. address=0.0.0.0:7070' means the highway endpoint is listening on port 7070
- 'Register microservice instance success' means the producer has registered successfully to service center
On the consumer side, you can see the following outputs if the consumer can invoke the producer:
- 'Pojo Hello Java Chassis' means the consumer calls sayhi successfully
- 'Jaxrs Hello Java Chassis' means the consumer calls Jaxrs sayhi successfully
- 'Spring mvc Hello Java Chassis' means the consumer calls SpringMvc sayhi successfully
- 'Pojo Hello person ServiceComb/Java Chassis' means the consumer calls sayhello successfully
- 'Jaxrs Hello person ServiceComb/Java Chassis' means the consumer calls Jaxrs sayhello successfully
- 'Spring mvc Hello person ServiceComb/Java Chassis' means the consumer calls SpringMvc sayhello successfully