RPC-Rest samples for Apache Dubbo (incubating)
Git clone and Package this demo project:
git clone https://github.com/dubbo/dubbo-samples cd dubbo-samples/dubbo-samples-rest mvn package
We will find target/dubbo-samples-rest-1.0-SNAPSHOT.war
We can use two steps to export Rest Service in Dubbo: Step 1: Add dependency to the pom file in our project:
<dependency> <groupId>${dubbo.rpc.groupId}</groupId> <artifactId>dubbo-rpc-rest</artifactId> <version>${dubbo.rpc.version}</version> </dependency>
If you are using is [2.6.1~2.6.5] version,then groupId is com.alibaba ,only if dubbo's version is 2.7.0 or above, its groupId is org.apache.dubbo . Step 2: Export Rest Service in our provider spring config file:
<dubbo:protocol name="rest" port="8888" threads="500" contextpath="services" server="tomcat" accepts="500" />
Then we can use the REST web service.
We can use two step to integration with Swagger UI in your webapps:
Step 1: copy dubbo-samples-rest\src\main\webapp\swagger to your webapps ROOT Directory.
Step 2: copy these config to your spring config file:
<!-- SwaggerUI --> <bean id="swaggerService" class="org.apache.dubbo.integration.swagger.DubboSwaggerApiListingResource" /> <bean id="beanConfig" class="io.swagger.jaxrs.config.BeanConfig"> <property name="schemes" value="http" /> <property name="resourcePackage" value="org.apache.dubbo.samples.rest.api"/> <property name="version" value="2.0"/> <property name="host" value="localhost:8888"/> <property name="basePath" value="/services/"/> <property name="title" value="title"/> <property name="description" value="desc"/> <property name="contact" value="abc"/> <property name="license" value="Apache 2.0"/> <property name="licenseUrl" value="http://www.apache.org/licenses/LICENSE-2.0.html"/> <property name="scan" value="true" /> </bean> <dubbo:service interface="org.apache.dubbo.integration.swagger.DubboSwaggerService" ref="swaggerService" protocol="rest" />
Any question could be discuss in Issue Board.