WebService Dubbo (definition of service, supplier, consumer)

Source: Internet
Author: User

Prerequisite Preparation:

Before this experiment, you need to prepare a few packages:

    • In spring, AOP, beans, context, core, expression, and commons-logging, javassist in struts are all designed to support configuration and run without error:

For this sentence: classpathxmlapplicationcontext context = new Classpathxmlapplicationcontext ("Provider.xml");

    • Dubbo packages and Netty are mandatory packages for Dubbo services
    • Ssssssss.jar is the API service of its own definition

I. Defining services (API)

  

Define an interface Gservice:

Enter parameter: String

return value: String

 Package Com.dubbo.zz;  Public Interface Gservice {    string SayHello (string name);}
View Code

Second, registered suppliers

The project result diagram is as follows:

  

Gserviceimpl.java:

 Package Com.dubbo.provider; Import Com.dubbo.zz.GService;  Public class Implements Gservice {            public  string SayHello (string name) {                return ' Hello ' + name;}    }
View Code

Provider.java:

 package   Com.dubbo.provider;  import   Org.springframework.context.support.ClassPathXmlApplicationContext;  public  class   Provider { static  void  main (string[] args) throws   Exception {Classpathxmlapplicationcontext context  = new  classpathxmlapplicationcontext ("Provider.xml" );        SYSTEM.OUT.PRINTLN ( "Service has startup" 
View Code

Provider.xml:

<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:dubbo= "Http://code.alibabatech.com/schema/dubbo"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-2.5.xsd Http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd ">     <!--provider app information for calculating dependencies -    <dubbo:applicationname= "SDFSD"/>     <!--exposing a service address using the Multicast Broadcast Registration center -    <Dubbo:registryAddress= "multicast://224.5.6.7:1234" />     <!--exposing services on 20880 ports with the Dubbo protocol -    <Dubbo:protocolname= "Dubbo"Port= "20880" />     <!--declaring a service interface that needs to be exposed -    <Dubbo:serviceInterface= "Com.dubbo.zz.GService"ref= "Demoservice" />     <!--services like local beans -    <BeanID= "Demoservice"class= "Com.dubbo.provider.GServiceImpl"/> </Beans>
View Code

Run results

  

  

Third, the consumer (can be an interface tester, can also be a service caller)

Note: For debugging purposes, an Eclipse application can be used as an alternative.

Project result diagram:

  

  

Consumer.xml:

<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:dubbo= "Http://code.alibabatech.com/schema/dubbo"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-2.5.xsd Http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd ">     <!--provider app information for calculating dependencies -    <dubbo:applicationname= "Consum"/>     <!--exposing a service address using the Multicast Broadcast Registration center -    <Dubbo:registryAddress= "multicast://224.5.6.7:1234" />    <!--generate a remote service proxy that can be used like a local bean demoservice -    <dubbo:referenceID= "Demoservice"Interface= "Com.dubbo.zz.GService" /> </Beans>
View Code

Testservices.java:

 PackageCom.dubbo.consumer;ImportOrg.springframework.context.support.ClassPathXmlApplicationContext;ImportCom.dubbo.zz.GService; Public classtestservices { Public Static voidMain (string[] args) {Classpathxmlapplicationcontext context=NewClasspathxmlapplicationcontext ("Consumer.xml"); System.out.println ("Consumer has a startup"); Gservice Service= (Gservice) context.getbean ("Demoservice"); String Str=service.sayhello ("FJSDFSD");    System.out.println (str); }}
View Code

Run results

  

 

At this point, the demonstration is complete, thank you. Please specify the source when reproduced, thank you: http://www.cnblogs.com/shoubianxingchen/p/4308229.html

This is a Dubbo entry-level presentation, and there's a lot more behind it.

WebService Dubbo (definition of service, supplier, consumer)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.