Dubbo [a distributed service framework

Source: Internet
Author: User

Http://alibaba.github.io/dubbo-doc-static/User+Guide-zh.htm#UserGuide-zh-API%E9%85%8D%E7%BD% AE

Http://alibaba.github.io/dubbo-doc-static/Home-zh.htm

 

What is Dubbo?

Dubbo [] is a distributed service framework designed to provide high-performance and transparent RPC remote service calling solutions and SOA service governance solutions.

Its core components include:

  • Remote Communication:Provides abstract encapsulation of a variety of NiO frameworks based on persistent connections, including multiple thread models, serialization, and information exchange in the "request-response" mode.
  • Cluster Fault Tolerance:Provides transparent remote process calling Based on interface methods, including multi-protocol support, soft load balancing, failure tolerance, address routing, dynamic configuration, and other cluster support.
  • Automatic Discovery:Based on the registry directory service, service consumers can dynamically find service providers and make addresses transparent so that service providers can smoothly increase or decrease machines.
What can Dubbo do?
  • Transparent remote method calling, just like calling a local method, requires simple configuration without any API intrusion.
  • Soft load balancing and fault tolerance mechanisms can replace Hardware load balancers such as F5 on the Intranet, reducing costs and reducing single points of failure.
  • Automatic Service Registration and discovery, no need to write the address of the service provider, the Registration Center queries the IP address of the service provider based on the Interface Name, and can smoothly add or delete the service provider.
Quick Start

(+ )(#)

Dubbo uses the full spring configuration method to transparently access the application without any API intrusion to the application. You only need to use spring to load Dubbo configurations. Dubbo is loaded Based on Spring schema extension.
If you do not want to use spring configuration and want to call it through APIS (not recommended), see API configuration (+)
Service Provider

(#)

For the complete installation steps, see: Sample provider installation (+)

Define a service interface: (this interface must be packaged separately and shared with the service provider and consumer)

Demoservice. Java
package com.alibaba.dubbo.demo; public interface DemoService {     String sayHello(String name); }

Implement interfaces on the service provider: (hide implementations on the service consumer)

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;    } }

Declare the exposure service with spring Configuration:

Provider. xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="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.xsd        http://code.alibabatech.com/schema/dubbo        http://code.alibabatech.com/schema/dubbo/dubbo.xsd">     <! -- Provider application information for dependency calculation -->    <dubbo:application name="hello-world-app"/>     <! -- Use the multicast broadcast registration center to expose the service address -->    <dubbo:registry address="multicast://224.5.6.7:1234" />     <! -- Expose services on port 20880 using Dubbo protocol -->    <dubbo:protocol name="dubbo" port="20880" />     <! -- Declare the service interface to be exposed -->    <dubbo:service interface="com.alibaba.dubbo.demo.DemoService" ref="demoService" />     <! -- Implement services like local beans -->    <bean id="demoService" class="com.alibaba.dubbo.demo.provider.DemoServiceImpl" /> </beans>

Load 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[] {"http://10.20.160.198/wiki/display/dubbo/provider.xml"});        context.start();         System.in.read(); // Press any key to exit    } }
Service consumer

(#)

For the complete installation steps, see: Sample Consumer Installation (+)

Use spring configuration to reference remote services:

Consumer. xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="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.xsd        http://code.alibabatech.com/schema/dubbo        http://code.alibabatech.com/schema/dubbo/dubbo.xsd">     <! -- Consumer Application name, used to calculate dependencies. It is not a matching condition. Do not use the same name as the provider. -->    <dubbo:application name="consumer-of-helloworld-app"/>     <! -- Use the multicast broadcast registration center to expose the Discovery Service address -->    <dubbo:registry address="multicast://224.5.6.7:1234" />     <! -- Generate a remote service proxy and use demoservice like a local Bean -->    <dubbo:reference id="demoService" interface="com.alibaba.dubbo.demo.DemoService" /> </beans>

Load spring configurations and call remote services: (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 {        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"http://10.20.160.198/wiki/display/dubbo/consumer.xml"});        context.start();         DemoService demoService = (DemoService)context.getBean("demoService"); // Obtain the remote service proxy        String hello = demoService.sayHello("world"); // Execute the Remote Method         System.out.println( hello ); // Display the call result    } }

Want to know more? Read 《User Guide~~

Dubbo [a distributed service framework

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.