博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
17、SpringBoot------整合dubbo
阅读量:6578 次
发布时间:2019-06-24

本文共 9232 字,大约阅读时间需要 30 分钟。

SpringBoot整合Dubbo+Zookeaper

1.安装运行zookeeper

(1)下载zookeeper

官网:http://zookeeper.apache.org/

(2)解压缩

(3)修改配置文件

  1. 拷贝zoo_sample.cfg重命名为zoo.cfg

  2. 修改配置文档

    # The number of milliseconds of each ticktickTime=2000# The number of ticks that the initial # synchronization phase can takeinitLimit=10# The number of ticks that can pass between # sending a request and getting an acknowledgementsyncLimit=5# the directory where the snapshot is stored.# do not use /tmp for storage, /tmp here is just # example sakes.dataDir=../data# the port at which the clients will connectclientPort=2181# the maximum number of client connections.# increase this if you need to handle more clients#maxClientCnxns=60## Be sure to read the maintenance section of the # administrator guide before turning on autopurge.## http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance## The number of snapshots to retain in dataDir#autopurge.snapRetainCount=3# Purge task interval in hours# Set to "0" to disable auto purge feature#autopurge.purgeInterval=1
  3. 创建data文件夹

(4)cmd启动zkServer.sh

2.安装dubbo web管理客户端

(1)下载Duboo OPS

下载地址:https://github.com/apache/incubator-dubbo-ops/tree/master

(2)修改配置

## Licensed to the Apache Software Foundation (ASF) under one or more# contributor license agreements.  See the NOTICE file distributed with# this work for additional information regarding copyright ownership.# The ASF licenses this file to You under the Apache License, Version 2.0# (the "License"); you may not use this file except in compliance with# the License.  You may obtain a copy of the License at##     http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.#server.port=7001spring.velocity.cache=falsespring.velocity.charset=UTF-8spring.velocity.layout-url=/templates/default.vmspring.messages.fallback-to-system-locale=falsespring.messages.basename=i18n/messagespring.root.password=rootspring.guest.password=guestdubbo.registry.address=zookeeper://127.0.0.1:2181

(3)maven打包dubbo-admin

(4)启动生成jar

(5)访问http://localhost:7001/

3.安装dubbo监控服务中心

(1)maven打包dubbo-monitor-simple

(2)解压dubbo-monitor-simple-2.0.0-assembly.tar.gz

(3)修改配置文件

# Licensed to the Apache Software Foundation (ASF) under one or more# contributor license agreements.  See the NOTICE file distributed with# this work for additional information regarding copyright ownership.# The ASF licenses this file to You under the Apache License, Version 2.0# (the "License"); you may not use this file except in compliance with# the License.  You may obtain a copy of the License at##      http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.dubbo.container=log4j,spring,registry,jetty-monitordubbo.application.name=simple-monitordubbo.application.owner=dubbo#dubbo.registry.address=multicast://224.5.6.7:1234dubbo.registry.address=zookeeper://127.0.0.1:2181#dubbo.registry.address=redis://127.0.0.1:6379#dubbo.registry.address=dubbo://127.0.0.1:9090dubbo.protocol.port=7070dubbo.jetty.port=8080dubbo.jetty.directory=${user.home}/monitordubbo.charts.directory=${user.home}/monitor/chartsdubbo.statistics.directory=${user.home}/monitor/statisticsdubbo.log4j.file=logs/dubbo-monitor-simple.logdubbo.log4j.level=WARN

(4)启动start.bat

(5)访问http://localhost:8080/

4.整合springboot

(1)新建Maven项目:d_api :一个公用service的api

  1. 新建一个接口:HelloService

    package com.xm.dubbo.service;public interface HelloService { String sayHello();}

(2)新建Springboot项目:Hello_Producer

参考链接:https://github.com/apache/incubator-dubbo-spring-boot-project

  1. 添加依赖

    4.0.0
    com.xm.dubbo
    hello_producer
    0.0.1-SNAPSHOT
    jar
    hello_producer
    This is a Web about springcloud
    org.springframework.boot
    spring-boot-starter-parent
    2.0.6.RELEASE
    UTF-8
    UTF-8
    1.8
    com.alibaba.boot
    dubbo-spring-boot-starter
    0.2.0
    org.springframework.boot
    spring-boot-starter
    org.springframework.boot
    spring-boot-starter-test
    test
    com.xm.dubbo
    d_api
    0.0.1-SNAPSHOT
    org.springframework.boot
    spring-boot-maven-plugin
  2. 修改配置文件

    dubbo.application.name=hello_producerdubbo.registry.protocol=zookeeperdubbo.registry.address=127.0.0.1:2181dubbo.scan.base-packages=com.xm.dubbo.servicedubbo.protocol.name=dubbodubbo.protocol.port=20080dubbo.monitor.protocol=registry
  3. 新建HelloServiceImpl

    package com.xm.dubbo.service.impl;import org.springframework.stereotype.Component;import com.alibaba.dubbo.config.annotation.Service;import com.xm.dubbo.service.HelloService;@Service@Componentpublic class HelloServiceImpl implements HelloService { @Override public String sayHello() {     System.out.println("生产者已被调用!");     return "Hello dubbo!"; }}
  4. 项目入口添加@EnableDubbo注解

    package com.xm.dubbo;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;@EnableDubbo@SpringBootApplicationpublic class HelloProducerApplication { public static void main(String[] args) {     SpringApplication.run(HelloProducerApplication.class, args); }}

(3)新建Springboot项目:Hello_Consumer

  1. 添加依赖

    4.0.0
    com.xm.dubbo
    hello_consumer
    0.0.1-SNAPSHOT
    jar
    hello_consumer
    This is a Web about springcloud
    org.springframework.boot
    spring-boot-starter-parent
    2.0.6.RELEASE
    UTF-8
    UTF-8
    1.8
    com.alibaba.boot
    dubbo-spring-boot-starter
    0.2.0
    org.springframework.boot
    spring-boot-starter-web
    org.springframework.boot
    spring-boot-starter-test
    test
    com.xm.dubbo
    d_api
    0.0.1-SNAPSHOT
    org.springframework.boot
    spring-boot-maven-plugin
  2. 修改配置文件

    server.port=8081dubbo.application.name=hello_consumerdubbo.registry.protocol=zookeeperdubbo.registry.address=127.0.0.1:2181dubbo.monitor.protocol=registry
  3. 新建HelloController

    package com.xm.dubbo.controller;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RestController;import com.alibaba.dubbo.config.annotation.Reference;import com.xm.dubbo.service.HelloService;@RestControllerpublic class HelloController { @Reference private HelloService helloService; @GetMapping("/hello") public String sayHello() {     return helloService.sayHello(); }}
  4. 项目入口添加@EnableDubbo注解

    package com.xm.dubbo;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;@EnableDubbo@SpringBootApplicationpublic class HelloConsumerApplication { public static void main(String[] args) {     SpringApplication.run(HelloConsumerApplication.class, args); }}

转载于:https://www.cnblogs.com/TimerHotel/p/springboot17.html

你可能感兴趣的文章
css3 animate 和关键帧 @-webkit-keyframes
查看>>
文字链接颜色设置
查看>>
ChannelHandler揭秘(Netty源码死磕5)
查看>>
图片转流
查看>>
常见幻灯片实现
查看>>
ubunto应用软件
查看>>
wireshark----教你如何抓包
查看>>
从txt中读入数据到数组中(fscanf)
查看>>
jquery中的事件与动画
查看>>
Git初始化仓库
查看>>
poj1006生理周期(中国剩余定理)
查看>>
HTML 标签说明
查看>>
锋利的jQuery-2--判断jQuery获取到的对象是否存在$().length
查看>>
在Pycharm中使用GitHub
查看>>
linux 查询系统版本命令、查询端口号是否被占用命令
查看>>
java笔记八:IO流之字符流与字符缓冲流
查看>>
Docker 命令收集
查看>>
myeclipse注册码生成器
查看>>
BW数据源深入研究
查看>>
怎样快速学好PHP技术之PHP学习方法总结
查看>>