POJO is also called as Transparent Remote Procedure Call (RPC), POJO development mode based on API and API implementation. The service developer does not need to use the description of Spring MVC and JAX-RS.
The transparent RPC development mode supports two service release mode: Spring XML configuration and annotation configuration.
The Spring XML Configuration Mode:
pojoHello.bean.xml
file in the resources/META-INF/spring
directory and declare the schema in the file.The Develop Method by Configure Remarks:
@RpcSchema
is used to define schema during the API Hello implementation.Detail information please refer to Doc
To call a microservice, you only need to declare a member of a service API type and add the @RpcReference
annotation for the member, the microservice that depends on the declaration, and the schemaID
. The sample code is as follows.
@Component public class CodeFirstConsumerMain { @RpcReference(microserviceName = "codefirst", schemaId = "codeFirstHello") private static Hello hello; public static void main(String[] args) throws Exception { //init first System.out.println(hello.sayHi("World!")); } }
see Precondition
Start the ServiceComb/Service Center
microservice.yaml
fileservicecomb: service: registry: address: http://127.0.0.1:30100 #service center address
Start the pojo-provider service
Start provider service by maven
Compile the source code, and use mvn exec
to execute the main class PojoProviderMain
.
mvn clean install cd pojo-sample/pojo-provider/ mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.pojo.provider.PojoProviderMain"
Start provider service by IDE
Import the project by InteliJ IDEA or Eclipse, then find main
function PojoProviderMain
of provider service and RUN
it like any other Java program.
Start the pojo-consumer service
Just like how to start pojo-provider service. But the main class of pojo-consumer service is PojoConsumerMain
.
cd pojo-sample/pojo-consumer/ mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.pojo.consumer.PojoConsumerMain"
How to verify On the producer side, the output should contain the following stuffs if the producer starts up successfully:
On the consumer side, you can see the following outputs if the consumer can invoke the producer: