How do I develop a distributed service based on Dubbo RPC?

Source: Internet
Author: User
Tags zookeeper

    • What is Dubbo?
      • What can Dubbo do?
    • Under the Crystal Framework, how do I develop a Dubbo RPC-based service?
    • Under the Crystal Framework, how do I invoke the Dubbo RPC service?
    • Related articles

What is Dubbo?

dubbo[] 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 contains:

    • Remote communication: provides an abstract encapsulation of various NIO frameworks based on long connections, including multiple threading models, serialization, and "request-response" mode of information exchange.
    • cluster fault tolerance: provides transparent remote procedure calls based on interface methods, including multi-protocol support, as well as soft load balancing, failure tolerance, address routing, dynamic configuration and other cluster support.
    • Autodiscover: based on the Registry directory service, the service consumer can dynamically find the service provider, making the address transparent, allowing the service provider to increase or decrease the machine smoothly.
What can Dubbo do?
    • A transparent remote method call, just like calling a local method, calls a remote method, simply configured without any 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 eliminates the need to write dead service provider addresses, the registry queries the IP address of the service provider based on the interface name, and is able to smoothly add or remove service providers.

For more information about Dubbo, please see: http://alibaba.github.io/dubbo-doc-static/Home-zh.htm

Under the Crystal Framework, how do I develop a Dubbo RPC-based service?

First step: Define the interface

    1. Create an interface jar project, such as: TEST-DUBBO-SERVICE-API;
    2. There is no difference between creating an interface class and an interface method, and the usual interface definition, such as:

       Public Interface testservice {    /**     *     @param  a     @return     */     Public string Test (String a);

Step two: Implement and publish the service

  1. Create a service implementation project, such as: Test-dubbo-service-impl;
  2. Introduction of Interface Project (TEST-DUBBO-SERVICE-API), Crystal Framework Dubbo Service Support Package (CRYSTAL-REMOTE-SERVER-DUBBO), such as:

    <Dependency>    <groupId>Com.gsoft.test</groupId>    <Artifactid>Test-dubbo-service-api</Artifactid></Dependency><Dependency>    <groupId>Com.gsoft.crystal</groupId>    <Artifactid>Crystal-remote-server-dubbo</Artifactid></Dependency>
  3. Implement the service interface, such as:

      @Service  public  class  testserviceimpl  Testservice {@Value ( "${crystal.application.name}"  private   String name;  /*   * (non-javadoc) * * @see com.gsof T.test.dubbo.testservice#test (java.lang.String)  */  @Override  public   string Test (string a) {  return  "Hello," + A + "!" + "I ' m" + name + "" + system.getenv ("LO Gonserver ") +". "    
  4. Add the annotation @service on the implementation class, where the service is the declaration note Com.alibaba.dubbo.config.annotation.Service for the Dubbo service, where the services based on the Dubbo release have been developed and published.

    Icon
    == = zookeeper://127.0.0.1:2181= 20880
Under the Crystal Framework, how do I invoke the Dubbo RPC service?

The first step: the project references the Dubbo Service interface package and the Crystal Framework Dubbo Client Support Package (CRYSTAL-REMOTE-CLIENT-DUBBO), as

<Dependency>    <groupId>Com.gsoft.test</groupId>    <Artifactid>Test-dubbo-service-api</Artifactid></Dependency><Dependency>    <groupId>Com.gsoft.crystal</groupId>    <Artifactid>Crystal-remote-client-dubbo</Artifactid></Dependency>

Step two: In the class that needs to use the Dubbo RPC service, add a reference to the service, and add @reference annotations: (here Reference the declaration annotations for the Dubbo service Com.alibaba.dubbo.config.annotation.Reference

 Public class Testcostumer {    @Reference    private  testservice s;     Private int i = 0;    @Value ("${crystal.application.name}")    private  String name;      Public void Hello () {        + "" + system.getenv ("logonserver") + "-" + + +i));}    }

= == zookeeper://127.0.0.1:2181

How do I develop a distributed service based on Dubbo RPC?

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.