欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Dubbo+zookeeper搭配分布式服務的過程詳解

 更新時間:2022年04月03日 11:17:44   作者:我也不會敲代碼呀  
Dubbo作為分布式架構比較后的框架,同時也是比較容易入手的框架,適合作為分布式的入手框架,下面是簡單的搭建過程,對Dubbo+zookeeper分布式服務搭建過程感興趣的朋友一起看看吧

分布式架構: 

1.當垂直應用越來越多,應用之間交互不可避免,將核心業(yè)務抽取出來,作為獨立的服務,逐漸形成穩(wěn)定的服務中心,前端應用能更快速的響應多變的市場需求。 
2.此時,用于提高業(yè)務復用及整合的 分布式服務框架(RPC) 是關鍵。

Dubbo 是什么

  • 一款分布式服務框架
  • 高性能和透明化的RPC遠程服務調用方案
  • SOA服務治理方案

Dubbo:

作為分布式架構比較后的框架,同時也是比較容易入手的框架,適合作為分布式的入手框架,下面是簡單的搭建過程

工具:idea+tomact+zookeeper (知識點:jsp,spring,springmvc,maven)

思想:

 

依賴:

<dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.2.5.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.2.5.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
            <version>2.6.2</version>
        </dependency>
        <!--zookeeper依賴-->
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-framework</artifactId>
            <version>4.1.0</version>
        </dependency>
        <dependency>
            <groupId>com.atchengdu</groupId>
            <artifactId>001-interface</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

工程分布:

  

provider實現(xiàn)interface提供服務,constomer消費provider提供的服務

interface:

package com.atchengdu.serviceinterface;
 
import com.atchengdu.pojo.User;
public interface Userservice {
    //獲取user的信息
    User getuserByid(Integer ie);
}
package com.atchengdu.pojo;
import java.io.Serializable;
public class User implements Serializable {
    private Integer id ;
    private String name;
    public User(Integer id, String name) {
        this.id = id;
        this.name = name;
    }
    public User() {
    public Integer getId() {
        return id;
    public void setId(Integer id) {
    public String getName() {
        return name;
    public void setName(String name) {
    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';

 provider:

package com.atchengdu.Modulserviceimpl;
 
import com.atchengdu.pojo.User;
import com.atchengdu.serviceinterface.Userservice;
public class Userserviceimpl implements Userservice {
    @Override
    public User getuserByid(Integer ie) {
        User user=new User(1,"張三");
        return user;
    }
}
<?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">
    <!--聲明名稱-->
    <dubbo:application name="002-provider"></dubbo:application>
    <!--設置協(xié)議和端口號-->
    <dubbo:protocol name="dubbo" port="20880"></dubbo:protocol>
    <!--使用注冊中心-->
    <dubbo:registry address="zookeeper://localhost:2181"></dubbo:registry>
    <!--暴露服務接口-->
    <dubbo:service interface="com.atchengdu.serviceinterface.Userservice" ref="userserviceimpl"></dubbo:service>
    <!--加載業(yè)務實實現(xiàn)了-->
    <bean id="userserviceimpl" class="com.atchengdu.Modulserviceimpl.Userserviceimpl"></bean>
</beans>

constomer:

package com.atchengdu.webcontroller;
 
import com.atchengdu.pojo.User;
import com.atchengdu.serviceinterface.Userservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
 
@Controller
public class Usercontroller {
    @Autowired
    private Userservice userservice;
    @RequestMapping("/user")
    public  String user(Model model,Integer id ){
        User user = userservice.getuserByid(id);
        model.addAttribute("user",user);
        return "user";
    }
}
<?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:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:tx="http://www.springframework.org/schema/task"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
                            http://www.springframework.org/schema/task https://www.springframework.org/schema/task/spring-task.xsd
                           http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd
                           http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.atchengdu.webcontroller">
</context:component-scan>
<mvc:annotation-driven></mvc:annotation-driven>
    <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="suffix" value=".jsp"></property>
        <property name="prefix" value="/"></property>
     </bean>
</beans>
<?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">
      <dubbo:application name="003-constomer"></dubbo:application>
    <dubbo:registry address="zookeeper://localhost:2181"></dubbo:registry>
    <dubbo:reference id="userservice" interface="com.atchengdu.serviceinterface.Userservice"></dubbo:reference>
</beans>

到此這篇關于Dubbo+zookeeper搭配分布式服務的過程詳解的文章就介紹到這了,更多相關Dubbo+zookeeper分布式服務內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • Springmvc和ajax如何實現(xiàn)前后端交互

    Springmvc和ajax如何實現(xiàn)前后端交互

    這篇文章主要介紹了Springmvc和ajax如何實現(xiàn)前后端交互,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-05-05
  • SpringBoot大學心理服務系統(tǒng)實現(xiàn)流程分步講解

    SpringBoot大學心理服務系統(tǒng)實現(xiàn)流程分步講解

    本系統(tǒng)主要論述了如何使用JAVA語言開發(fā)一個大學生心理服務系統(tǒng) ,本系統(tǒng)將嚴格按照軟件開發(fā)流程進行各個階段的工作,采用B/S架構,面向對象編程思想進行項目開發(fā)
    2022-09-09
  • 通過實例解析spring bean之間的關系

    通過實例解析spring bean之間的關系

    這篇文章主要介紹了通過實例解析spring bean之間的關系,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-01-01
  • Java獲取字符串編碼格式實現(xiàn)思路

    Java獲取字符串編碼格式實現(xiàn)思路

    文件編碼的格式決定了文件可存儲的字符類型,所以得到文件的類型至關重要,下文筆者講述獲取一個文本文件的格式信息的方法分享及java字符串編碼格式實現(xiàn),感興趣的朋友一起看看吧
    2022-09-09
  • Java中的static--靜態(tài)變量你了解嗎

    Java中的static--靜態(tài)變量你了解嗎

    Java 中被 static 修飾的成員稱為靜態(tài)成員或類成員。它屬于整個類所有,而不是某個對象所有,即被類的所有對象所共享。靜態(tài)成員可以使用類名直接訪問,也可以使用對象名進行訪問,.下面我們來詳細了解一下吧
    2021-09-09
  • SSM 整合的配合文件(分享)

    SSM 整合的配合文件(分享)

    下面小編就為大家分享一篇SSM 整合的配合文件,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2017-12-12
  • Java垃圾回收之分代收集算法詳解

    Java垃圾回收之分代收集算法詳解

    今天小編就為大家分享一篇關于Java垃圾回收之分代收集算法詳解,小編覺得內容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2018-10-10
  • JAVA中Object的常用方法

    JAVA中Object的常用方法

    JAVA中Object是所有對象的頂級父類,存在于java.lang包中,這個包不需要我們手動導包,本文通過實例代碼介紹JAVA中Object的常用方法,感興趣的朋友一起看看吧
    2023-11-11
  • Java中匿名類的兩種實現(xiàn)方式

    Java中匿名類的兩種實現(xiàn)方式

    本文主要介紹了Java中匿名類的兩種實現(xiàn)方式。具有很好的參考價值,下面跟著小編一起來看下吧
    2017-02-02
  • Java語法基礎之運算符學習筆記分享

    Java語法基礎之運算符學習筆記分享

    這篇文章主要為大家分享了Java語法基礎之運算符學習筆記,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09

最新評論