码迷,mamicode.com
首页 > 编程语言 > 详细

SpringBoot和Dubbo+ZooKeeper组合案例

时间:2020-03-30 19:50:24      阅读:82      评论:0      收藏:0      [点我收藏+]

标签:sys   servlet   监控中心   led   targe   registry   mpi   efault   stat   

SpringBoot融合了maven的特点,所以可以和maven完美整合

接下来要做一个分布式项目,首先要有共享的接口

先建一个maven项目

技术图片

 详情:

UserAddress.java

package com.changping.bean;
import java.io.Serializable;
public class UserAddress implements Serializable {
private Integer id;
private String userAddress; //用户地址
private String userId; //用户id
private String consignee; //收货人
private String phoneNum; //电话号码
private String isDefault; //是否为默认地址 Y-是 N-否
public UserAddress() {
super();
}
public UserAddress(Integer id, String userAddress, String userId, String consignee, String phoneNum,
String isDefault) {
super();
this.id = id;
this.userAddress = userAddress;
this.userId = userId;
this.consignee = consignee;
this.phoneNum = phoneNum;
this.isDefault = isDefault;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUserAddress() {
return userAddress;
}
public void setUserAddress(String userAddress) {
this.userAddress = userAddress;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getConsignee() {
return consignee;
}
public void setConsignee(String consignee) {
this.consignee = consignee;
}
public String getPhoneNum() {
return phoneNum;
}
public void setPhoneNum(String phoneNum) {
this.phoneNum = phoneNum;
}
public String getIsDefault() {
return isDefault;
}
public void setIsDefault(String isDefault) {
this.isDefault = isDefault;
}
}

OrderService.java

package com.changping.service;
import java.util.List;
import com.changping.bean.UserAddress;
public interface OrderService {
public List<UserAddress> initOrder(String userId);
}

UserService.java

package com.changping.service;
import java.util.List;
import com.changping.bean.UserAddress;
public interface UserService {
public List<UserAddress> getUserAddressList(String userId);
}

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.changping.mall</groupId>
<artifactId>mall_interface</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<!-- 引入dubbo -->
<!-- https://mvnrepository.com/artifact/com.alibaba/dubbo -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.6.2</version>
</dependency>
<!-- 注册中心使用的是zookeeper,引入操作zookeeper的客户端端 -->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>2.12.0</version>
</dependency>
<!--Dubbo Spring Boot Starter,一定要针对springboot2.6.2版本 -->
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>0.2.0</version>
</dependency>

<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>

<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>4.10.1</version>
</dependency>
<!-- 1.连接池 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.37</version>
</dependency>
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.2</version>
</dependency>

<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>

<!-- 2.Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>

<!-- 3.MyBatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.2.8</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.2</version>
</dependency>

<!-- 4.SpringMVC -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>

<!-- 5.辅助 -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1.3-b06</version>
<scope>provided</scope>

</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.11</version>
</dependency>

<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.1</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>

<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>

<!-- 6.webservice-cxf -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.0.5</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.0.5</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-security</artifactId>
<version>3.0.5</version>
</dependency>
<dependency>
<groupId>org.apache.ws.security</groupId>
<artifactId>wss4j</artifactId>
<version>1.5.2</version>
</dependency>
<!-- 7.事务 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>

<!-- 1 spring容器事务 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.8</version>
</dependency>
<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>

以上项目会作为下面两个项目的依赖

新建springboot项目用来提供服务

技术图片

UserServiceImpl.java

package com.changping.mall.userserviceimpl;
import java.util.Arrays;
import java.util.List;
import org.springframework.stereotype.Component;
import com.alibaba.dubbo.config.annotation.Service;
import com.changping.bean.UserAddress;
import com.changping.service.UserService;
@Service //dubbo注解暴露接口
@Component //spring注解
public class UserServiceImpl implements UserService {
public List<UserAddress> getUserAddressList(String userId) {
System.out.println("UserServiceImpl.....1...");
UserAddress address1 = new UserAddress(1, "花果山福地", "1", "齐天大圣", "123456", "Y");
UserAddress address2 = new UserAddress(2, "水帘洞洞天", "1", "六耳猕猴", "654321", "N");
return Arrays.asList(address1,address2);
}
}

SpringbootUserserviceProviderApplication (启动)

package com.changping.mall;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
@SpringBootApplication
@EnableDubbo //开启基于注解的dubbo功能
public class SpringbootUserserviceProviderApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootUserserviceProviderApplication.class, args);
}
}

application.properties(配置信息)

dubbo.application.name=user-service-provider

dubbo.registry.protocol=zookeeper
dubbo.registry.address=127.0.0.1:2181

dubbo.protocol.name=dubbo
dubbo.protocol.port=-1

dubbo.monitor.protocol=registry

SpringbootUserserviceProviderApplicationTests (单元测试)

 

package com.changping.mall;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)//用于指定junit运行环境,是junit提供给其它框架测试环境接口的扩展
@SpringBootTest
public class SpringbootUserserviceProviderApplicationTests {
@Test
public void contextLoads() {
}
}

pom.xml

 <?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.changping.mall</groupId>
<artifactId>springboot-userservice-provider</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot-userservice-provider</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.changping.mall</groupId>
<artifactId>mall_interface</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

此时可以启动zkServer、zkCli、然后打包发布到web上

zkServer.cmd

技术图片

zkCli.cmd

技术图片

 java -jar dubbo-admin-0.0.1-SNAPSHOT.jar

技术图片

接下来去浏览器访问

http://localhost:7001

首页

技术图片

 接着启动服务提供者

console信息

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/YZ/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/YZ/.m2/repository/org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
log4j:WARN No appenders could be found for logger (com.alibaba.dubbo.common.logger.LoggerFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
2020-03-30 15:26:11.121 INFO 13804 --- [ main] a.b.d.c.e.WelcomeLogoApplicationListener :

:: Dubbo Spring Boot (v0.2.0) : https://github.com/apache/incubator-dubbo-spring-boot-project
:: Dubbo (v2.6.2) : https://github.com/apache/incubator-dubbo
:: Google group : dev@dubbo.incubator.apache.org

2020-03-30 15:26:11.180 INFO 13804 --- [ main] e.OverrideDubboConfigApplicationListener : Dubbo Config was overridden by externalized configuration {dubbo.application.name=order-service-consumer, dubbo.monitor.protocol=registry, dubbo.registry.address=zookeeper://127.0.0.1:2181}

. ____ _ __ _ _
/\\ / ___‘_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | ‘_ | ‘_| | ‘_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
‘ |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.4.RELEASE)

2020-03-30 15:26:11.661 INFO 13804 --- [ main] pringbootOrderserviceConsumerApplication : Starting SpringbootOrderserviceConsumerApplication on DESKTOP-NF046H7 with PID 13804 (D:\workspace\springboot\springboot-orderservice-consumer\target\classes started by YZ in D:\workspace\springboot\springboot-orderservice-consumer)
2020-03-30 15:26:11.663 INFO 13804 --- [ main] pringbootOrderserviceConsumerApplication : No active profile set, falling back to default profiles: default
2020-03-30 15:26:11.865 INFO 13804 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@441772e: startup date [Mon Mar 30 15:26:11 CST 2020]; root of context hierarchy
2020-03-30 15:26:13.248 INFO 13804 --- [ main] .a.d.c.s.c.a.DubboConfigBindingRegistrar : The dubbo config bean definition [name : com.alibaba.dubbo.config.ApplicationConfig#0, class : com.alibaba.dubbo.config.ApplicationConfig] has been registered.
2020-03-30 15:26:13.252 INFO 13804 --- [ main] .a.d.c.s.c.a.DubboConfigBindingRegistrar : The BeanPostProcessor bean definition [com.alibaba.dubbo.config.spring.beans.factory.annotation.DubboConfigBindingBeanPostProcessor] for dubbo config bean [name : com.alibaba.dubbo.config.ApplicationConfig#0] has been registered.
2020-03-30 15:26:13.252 INFO 13804 --- [ main] .a.d.c.s.c.a.DubboConfigBindingRegistrar : The dubbo config bean definition [name : com.alibaba.dubbo.config.RegistryConfig#0, class : com.alibaba.dubbo.config.RegistryConfig] has been registered.
2020-03-30 15:26:13.253 INFO 13804 --- [ main] .a.d.c.s.c.a.DubboConfigBindingRegistrar : The BeanPostProcessor bean definition [com.alibaba.dubbo.config.spring.beans.factory.annotation.DubboConfigBindingBeanPostProcessor] for dubbo config bean [name : com.alibaba.dubbo.config.RegistryConfig#0] has been registered.
2020-03-30 15:26:13.253 INFO 13804 --- [ main] .a.d.c.s.c.a.DubboConfigBindingRegistrar : The dubbo config bean definition [name : com.alibaba.dubbo.config.MonitorConfig#0, class : com.alibaba.dubbo.config.MonitorConfig] has been registered.
2020-03-30 15:26:13.253 INFO 13804 --- [ main] .a.d.c.s.c.a.DubboConfigBindingRegistrar : The BeanPostProcessor bean definition [com.alibaba.dubbo.config.spring.beans.factory.annotation.DubboConfigBindingBeanPostProcessor] for dubbo config bean [name : com.alibaba.dubbo.config.MonitorConfig#0] has been registered.
2020-03-30 15:26:14.202 INFO 13804 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean ‘com.alibaba.boot.dubbo.autoconfigure.DubboAutoConfiguration‘ of type [com.alibaba.boot.dubbo.autoconfigure.DubboAutoConfiguration$$EnhancerBySpringCGLIB$$934a02ee] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-03-30 15:26:14.249 INFO 13804 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean ‘relaxedDubboConfigBinder‘ of type [com.alibaba.boot.dubbo.autoconfigure.RelaxedDubboConfigBinder] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-03-30 15:26:14.257 INFO 13804 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean ‘relaxedDubboConfigBinder‘ of type [com.alibaba.boot.dubbo.autoconfigure.RelaxedDubboConfigBinder] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-03-30 15:26:14.272 INFO 13804 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean ‘relaxedDubboConfigBinder‘ of type [com.alibaba.boot.dubbo.autoconfigure.RelaxedDubboConfigBinder] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-03-30 15:26:14.518 INFO 13804 --- [ main] .f.a.DubboConfigBindingBeanPostProcessor : The properties of bean [name : com.alibaba.dubbo.config.ApplicationConfig#0] have been binding by prefix of configuration properties : dubbo.application
2020-03-30 15:26:14.542 INFO 13804 --- [ main] .f.a.DubboConfigBindingBeanPostProcessor : The properties of bean [name : com.alibaba.dubbo.config.RegistryConfig#0] have been binding by prefix of configuration properties : dubbo.registry
2020-03-30 15:26:14.558 INFO 13804 --- [ main] .f.a.DubboConfigBindingBeanPostProcessor : The properties of bean [name : com.alibaba.dubbo.config.MonitorConfig#0] have been binding by prefix of configuration properties : dubbo.monitor
2020-03-30 15:26:18.345 INFO 13804 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2020-03-30 15:26:18.384 INFO 13804 --- [ main] pringbootOrderserviceConsumerApplication : Started SpringbootOrderserviceConsumerApplication in 9.189 seconds (JVM running for 10.48)
2020-03-30 15:26:18.402 INFO 13804 --- [pool-1-thread-1] .d.c.e.AwaitingNonWebApplicationListener : [Dubbo] Current Spring Boot Application is await...

可以看到浏览器

技术图片

新建springboot项目提供消费者

技术图片

OrderController.java

package com.changping.mall.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.changping.bean.UserAddress;
import com.changping.service.OrderService;
@Controller
public class OrderController {
@Autowired
OrderService orderService;//引入maven项目里的mall_interface里的OrderService接口
@ResponseBody//返回json
@RequestMapping("initOrder")
public List<UserAddress> initOrder(@RequestParam("uid") String userId)//前端传值
{
List<UserAddress> addressList = orderService.initOrder(userId);
return addressList;
}
}

OrderServiceImp.java

package com.changping.mall.orderserviceimp;
import java.util.List;
import org.springframework.stereotype.Service;
import com.alibaba.dubbo.config.annotation.Reference;
import com.changping.bean.UserAddress;
import com.changping.service.OrderService;
import com.changping.service.UserService;
@Service
public class OrderServiceImp implements OrderService{
@Reference //dubbo里引用远程服务的注解
UserService userService;
public List<UserAddress> initOrder(String userId) {
List<UserAddress> userAddress = userService.getUserAddressList(userId);
return userAddress;
}
}

SpringbootOrderserviceConsumerApplication(启动)

package com.changping.mall;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
@EnableDubbo
@SpringBootApplication
//@SpringBootApplication(scanBasePackages = {"com.changping.service.UserService"})
public class SpringbootOrderserviceConsumerApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootOrderserviceConsumerApplication.class, args);
}
}

application.properties(配置文件)

dubbo.application.name=order-service-consumer
dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.monitor.protocol=registry

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.changping.mall</groupId>
<artifactId>springboot-orderservice-consumer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot-orderservice-consumer</name>
<description>Demo project for Spring Boot</description>

<properties>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>com.changping.mall</groupId>
<artifactId>mall_interface</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

需要双击启动start.bat

技术图片

首先看一下配置文件,其中jetty.port之前为8080,需要修改一下为8081,避免与tomecat冲突:

技术图片

双击start.bat后:

技术图片

可以去浏览器访问一下,如图是注册中心

可以看一下services,此时还没有消费者

技术图片

SpringbootOrderserviceConsumerApplication启动消费者应用

console信息

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/YZ/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/YZ/.m2/repository/org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
log4j:WARN No appenders could be found for logger (com.alibaba.dubbo.common.logger.LoggerFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
2020-03-30 17:44:00.506 INFO 12428 --- [ main] a.b.d.c.e.WelcomeLogoApplicationListener :

:: Dubbo Spring Boot (v0.2.0) : https://github.com/apache/incubator-dubbo-spring-boot-project
:: Dubbo (v2.6.2) : https://github.com/apache/incubator-dubbo
:: Google group : dev@dubbo.incubator.apache.org

2020-03-30 17:44:00.517 INFO 12428 --- [ main] e.OverrideDubboConfigApplicationListener : Dubbo Config was overridden by externalized configuration {dubbo.application.name=order-service-consumer, dubbo.monitor.protocol=registry, dubbo.registry.address=zookeeper://127.0.0.1:2181}

. ____ _ __ _ _
/\\ / ___‘_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | ‘_ | ‘_| | ‘_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
‘ |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.4.RELEASE)

2020-03-30 17:44:00.761 INFO 12428 --- [ main] pringbootOrderserviceConsumerApplication : Starting SpringbootOrderserviceConsumerApplication on DESKTOP-NF046H7 with PID 12428 (D:\workspace\springboot\springboot-orderservice-consumer\target\classes started by YZ in D:\workspace\springboot\springboot-orderservice-consumer)
2020-03-30 17:44:00.763 INFO 12428 --- [ main] pringbootOrderserviceConsumerApplication : No active profile set, falling back to default profiles: default
2020-03-30 17:44:00.945 INFO 12428 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@20deea7f: startup date [Mon Mar 30 17:44:00 CST 2020]; root of context hierarchy
2020-03-30 17:44:02.535 INFO 12428 --- [ main] .a.d.c.s.c.a.DubboConfigBindingRegistrar : The dubbo config bean definition [name : com.alibaba.dubbo.config.ApplicationConfig#0, class : com.alibaba.dubbo.config.ApplicationConfig] has been registered.
2020-03-30 17:44:02.562 INFO 12428 --- [ main] .a.d.c.s.c.a.DubboConfigBindingRegistrar : The BeanPostProcessor bean definition [com.alibaba.dubbo.config.spring.beans.factory.annotation.DubboConfigBindingBeanPostProcessor] for dubbo config bean [name : com.alibaba.dubbo.config.ApplicationConfig#0] has been registered.
2020-03-30 17:44:02.563 INFO 12428 --- [ main] .a.d.c.s.c.a.DubboConfigBindingRegistrar : The dubbo config bean definition [name : com.alibaba.dubbo.config.RegistryConfig#0, class : com.alibaba.dubbo.config.RegistryConfig] has been registered.
2020-03-30 17:44:02.563 INFO 12428 --- [ main] .a.d.c.s.c.a.DubboConfigBindingRegistrar : The BeanPostProcessor bean definition [com.alibaba.dubbo.config.spring.beans.factory.annotation.DubboConfigBindingBeanPostProcessor] for dubbo config bean [name : com.alibaba.dubbo.config.RegistryConfig#0] has been registered.
2020-03-30 17:44:02.564 INFO 12428 --- [ main] .a.d.c.s.c.a.DubboConfigBindingRegistrar : The dubbo config bean definition [name : com.alibaba.dubbo.config.MonitorConfig#0, class : com.alibaba.dubbo.config.MonitorConfig] has been registered.
2020-03-30 17:44:02.565 INFO 12428 --- [ main] .a.d.c.s.c.a.DubboConfigBindingRegistrar : The BeanPostProcessor bean definition [com.alibaba.dubbo.config.spring.beans.factory.annotation.DubboConfigBindingBeanPostProcessor] for dubbo config bean [name : com.alibaba.dubbo.config.MonitorConfig#0] has been registered.
2020-03-30 17:44:03.897 INFO 12428 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean ‘com.alibaba.boot.dubbo.autoconfigure.DubboAutoConfiguration‘ of type [com.alibaba.boot.dubbo.autoconfigure.DubboAutoConfiguration$$EnhancerBySpringCGLIB$$7fb44377] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-03-30 17:44:03.932 INFO 12428 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean ‘relaxedDubboConfigBinder‘ of type [com.alibaba.boot.dubbo.autoconfigure.RelaxedDubboConfigBinder] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-03-30 17:44:03.936 INFO 12428 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean ‘relaxedDubboConfigBinder‘ of type [com.alibaba.boot.dubbo.autoconfigure.RelaxedDubboConfigBinder] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-03-30 17:44:03.942 INFO 12428 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean ‘relaxedDubboConfigBinder‘ of type [com.alibaba.boot.dubbo.autoconfigure.RelaxedDubboConfigBinder] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-03-30 17:44:04.558 INFO 12428 --- [ main] .f.a.DubboConfigBindingBeanPostProcessor : The properties of bean [name : com.alibaba.dubbo.config.ApplicationConfig#0] have been binding by prefix of configuration properties : dubbo.application
2020-03-30 17:44:04.581 INFO 12428 --- [ main] .f.a.DubboConfigBindingBeanPostProcessor : The properties of bean [name : com.alibaba.dubbo.config.RegistryConfig#0] have been binding by prefix of configuration properties : dubbo.registry
2020-03-30 17:44:04.598 INFO 12428 --- [ main] .f.a.DubboConfigBindingBeanPostProcessor : The properties of bean [name : com.alibaba.dubbo.config.MonitorConfig#0] have been binding by prefix of configuration properties : dubbo.monitor
2020-03-30 17:44:04.962 INFO 12428 --- [ main] o.a.c.f.imps.CuratorFrameworkImpl : Starting

注册中心

技术图片

这样就也有注册中心了

分别将提供者和消费者再启动一次,仔细观察一下吧(我的电脑有些hold不住了,如果三个生产者,三个消费者,就基本可以和博客说拜拜了):

先从监控中心开始

首页服务治理

 技术图片

  系统管理

技术图片

 服务

技术图片

 应用

 技术图片

机器

技术图片

提供者

技术图片

消费者

技术图片

路由规则

技术图片

动态配置

技术图片

访问控制

技术图片

权重调节

技术图片

负载均衡

技术图片

负责人

技术图片

系统管理

dubbo版本

技术图片

系统快照

技术图片

系统状态

技术图片

系统日志(有130条)

技术图片

系统环境

技术图片

接下来看看注册中心

Home

技术图片

Application

技术图片

Service

技术图片

Hosts

技术图片

Registries

技术图片

Servers

技术图片

Status

技术图片

Log

技术图片

System

技术图片

 好啦,就到这里吧,下节再见。

 

SpringBoot和Dubbo+ZooKeeper组合案例

标签:sys   servlet   监控中心   led   targe   registry   mpi   efault   stat   

原文地址:https://www.cnblogs.com/timingstarts/p/12599237.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!