Introduction to Dubbo Distributed Service Framework __dubbo

Source: Internet
Author: User
Overview

Dubbo is the core framework of the Alibaba SOA Service governance program, providing 3,000,000,000+ access to 2,000+ services every day, and is widely used by the Alibaba Group's member sites:

Since the open source, there have been many non-Ali companies in the use of Dubbo, see known users
So, what is Dubbo.

Dubbo |ˈdʌbəʊ| is a distributed service framework dedicated to providing high-performance and transparent RPC remote service invocation scenarios, as well as SOA service governance scenarios. The core part includes: Remote communications: Provides an abstraction package of various long connected NIO frameworks, including multiple threading models, serialization, and "request-response" mode of information interchange. Cluster fault tolerance: Provides transparent remote process calls based on interface methods, including multi-protocol support, and cluster support automatic discovery of soft load balancing, failure fault tolerance, address routing, dynamic configuration, etc., based on registry directory services, enabling service consumers to dynamically locate service providers and make addresses transparent. Enables the service provider to smooth increase or decrease the machine.


what Dubbo can do. a transparent remote method call, called a remote method just like a local method, requires a simple configuration with no API intrusion. Soft load balancing and fault-tolerant mechanism can replace hardware load balancer such as F5 in intranet, reduce cost and reduce single point. Service autoenrollment and discovery no longer requires a write-dead service provider address, the registry queries the service provider's IP address based on the interface name, and can smooth add or remove service providers. Sample Demo

A simple demo from the code level describes how to use Dubbo to develop a remote communication service. Quick Start & source download, see GitHub.
Through this example, you will learn:
Define a remote service interface provider publish remote service to registry consumer automatically discover remote services and complete service calls

Before you begin, note that the example uses the spring configuration method recommended by Dubbo. To use API configuration please refer to API configuration example using multicast mode to implement service autoenrollment and discovery, in a production environment, you typically have to deploy a separate registration center
Defining Interfaces

Define the Service interface: (this interface needs to be packaged separately, shared between the service provider and the consumer)
Demoservice.java

Package Com.alibaba.dubbo.demo;

Public interface Demoservice {
string SayHello (string name);
}
            

Provider Implementation

The service provider implements the interface (hides the implementation of the consumer side of the service):
Demoserviceimpl.java

Package com.alibaba.dubbo.demo.provider;
Import Com.alibaba.dubbo.demo.DemoService;

public class Demoserviceimpl implements Demoservice {public
    string SayHello (string name) {return
        "Hello" + Name ;
    }
}
            

To declare an exposed service with a spring configuration:
Dubbo-demo-provider.xml

<?xml version= "1.0" encoding= "UTF-8"?> <beans "xmlns=" 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.xsd Http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd " > <!--provider application information for computing dependencies--> <dubbo:application name= "Demo-provider"/> <!--use multicast broadcast Registry Exposure Service address--> <dubbo:registry address= "multicast://224.5.6.7:1234"/> <!--exposure service on port 20880 with Dubbo protocol--&G
    T <dubbo:protocol name= "Dubbo" port= "20880"/> <!--declares the service interface that needs to be exposed--> <dubbo:service interface= "com.al Ibaba.dubbo.demo.DemoService "ref=" Demoservice/> <!--and local beans implement services--> <bean id= "Demoservice" Clas s= "Com.alibaba.dubbo.demo.provider.DemoServiceImpl"/> &Lt;/beans>
             

To load the spring configuration:
Provider.java

Import Org.springframework.context.support.ClassPathXmlApplicationContext;

public class Provider {public
    static void Main (string[] args) throws Exception {
        Classpathxmlapplicationcontext context = new Classpathxmlapplicationcontext (new string[] {"Meta-inf/spring/dubbo-demo-provider.xml"});
        Context.start ();

        System.in.read (); Press any key to exit
    }
}
            

Consumer Implementation

To reference a remote service through the spring configuration:
Dubbo-demo-consumer.xml

<?xml version= "1.0" encoding= "UTF-8"?> <beans "xmlns=" 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.xsd Http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd " > <!--consumer application name, used to compute dependencies, not match criteria, do not--> <dubbo:application name= "Demo-consumer"/> <!- -Use the multicast broadcast registry to expose discovery service addresses--> <dubbo:registry address= "multicast://224.5.6.7:1234"/> <!--generate remote service proxies , you can use Demoservice--> <dubbo:reference id= "demoservice" like local beans Com.alibaba.dubbo.demo.DemoService "/> </beans>

Load the spring configuration and invoke the remote service: (You can also use IOC injection)
Consumer.java

import Org.springframework.context.support.ClassPathXmlApplicationContext;

Import Com.alibaba.dubbo.demo.DemoService; public class Consumer {public static void main (string[] args) throws Exception {Classpathxmlapplicationconte
        XT context = new Classpathxmlapplicationcontext (new string[] {"Meta-inf/spring/dubbo-demo-consumer.xml"});

        Context.start (); Demoservice Demoservice = (demoservice) context.getbean ("Demoservice"); Get remote service proxy String hello = Demoservice.sayhello ("World"); Execute remote Method System.out.println (hello); Show call Result}} 
from:http://dubbo.io/

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.