(2)Dubbo入门使用案例

x33g5p2x  于2021-12-21 转载在 其他  
字(24.6k)|赞(0)|评价(0)|浏览(482)

本节介绍

这一节会通过一个Dubbo的入门实战案例,来介绍一下Dubbo服务的提供者、消费者分别是如何使用的,项目是如何划分的。Dubbo的新版本的一些特性使用不当,会导致启动的时候报"Fail to start qos server"的异常,这里也会介绍为什么出现这个错误已经是如何解决这个问题的。

准备工作说明

Dubbo系列博客使用的开发环境为:JDK1.8,Maven3.1.0,Eclipse,这里关于JDK、Maven这些环境的安装配置这里就不做过多介绍了。另外,还会使用到我们上一个系列博客介绍的zookeeper来作为Dubbo的注册中心,我所安装的zookeeper版本为3.4.6,关于zookeeper的安装配置问题,如果不是太清楚的话请参考《(2)zookeeper的单节点及集群安装配置》。

这里说一下关于Dubbo不同版本对于JDK的依赖问题:Dubbo2.5.5、Dubbo2.5.3以及之前的版本依赖JDK1.6+,而如果你想用2.5.4以及2.5.5之后的版本的话,则必须依赖于JDK1.8+。

关于Duubo的各个版本的发布时间以及变更内容,请参考 https://github.com/apache/incubator-dubbo/releases

Dubbo对以下依赖,在主动配置使用相应实现策略时用到,需自行加入依赖

  • netty-all 4.0.35.Final
  • mina: 1.1.7
  • grizzly: 2.1.4
  • httpclient: 4.5.3
  • hessian_lite: 3.2.1-fixed
  • fastjson: 1.2.31
  • zookeeper: 3.4.9
  • jedis: 2.9.0
  • xmemcached: 1.3.6
  • hessian: 4.0.38
  • jetty: 6.1.26
  • hibernate-validator: 5.4.1.Final
  • zkclient: 0.2
  • curator: 2.12.0
  • cxf: 3.0.14
  • thrift: 0.8.0
  • servlet: 3.0 [5]
  • validation-api: 1.1.0.GA[5:1]
  • jcache: 1.0.0 [5:2]
  • javax.el: 3.0.1-b08 [5:3]
  • kryo: 4.0.1
  • kryo-serializers: 0.42
  • fst: 2.48-jdk-6
  • resteasy: 3.0.19.Final
  • tomcat-embed-core: 8.0.11
  • slf4j: 1.7.25
  • log4j: 1.2.16

项目搭建说明

实际项目开发当中,都会把需要暴露的服务接口类、接口的请求响应相关的Model和枚举类、自定义的异常等单独放到一个interface工程中,然后我们把这个interface的jar包上传到我们自己公司的maven私服当中,我们的Dubbo服务的提供者跟消费者就可以通过添加对应的pom依赖引用这个公共的jar包。如果不这样做的话,就要在服务提供者、消费者工程当中分别添加相同的接口类,然后如果提供者提供的接口有变化的话,消费者也要跟着改代码很不方便,把那部分公用的代码放到一个公用的jar包中,就可以解决这个问题了。

项目搭建

一,首先创建公共的interface工程

工程名为dubbo-interface,里面包含一个接口SimpleService和一个User对象,工程结构如下

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.wkp</groupId>
  <artifactId>dubbo-interface</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>dubbo-interface</name>

</project>

下面给出User、SimpleService的内容(注意:因为传输的对象需要序列化,所以User对象实现了Serializable接口)

package com.wkp.model;
import java.io.Serializable;
public class User implements Serializable {
	private static final long serialVersionUID = 1L;
	private int age;
	private String name;
	private String sex;

	public User() { 
		super();
	}

	public User(int age, String name, String sex) {
		super();
		this.age = age;
		this.name = name;
		this.sex = sex;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

}
package com.wkp.service.simple;
import java.util.List;

import com.wkp.model.User;

public interface SimpleService {

	String sayHello(String name);

	public List<User> getUsers();

}

二、创建服务提供者dubbo-provider

项目结构如下:其中SimpleServiceImpl是SimpleService接口的实现类,Provider是服务提供者的启动类,log4j.properties为log4j的日志配置文件,simple-provider.xml是服务提供者的配置

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.wkp</groupId>
	<artifactId>dubbo-provider</artifactId>
	<version>0.0.1-SNAPSHOT</version>

	<dependencies>
		<dependency>
			<groupId>com.wkp</groupId>
			<artifactId>dubbo-interface</artifactId>
			<version>0.0.1-SNAPSHOT</version>
		</dependency>
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>dubbo</artifactId>
			<version>2.6.4</version>
		</dependency>
		<dependency>
			<groupId>org.apache.curator</groupId>
			<artifactId>curator-recipes</artifactId>
			<version>2.12.0</version>
		</dependency>
		<dependency>
			<groupId>io.netty</groupId>
			<artifactId>netty-all</artifactId>
			<version>4.0.35.Final</version>
		</dependency>
	</dependencies>
</project>
package com.wkp.service.simple.impl;
import java.util.ArrayList;
import java.util.List;

import com.wkp.model.User;
import com.wkp.service.simple.SimpleService;

public class SimpleServiceImpl implements SimpleService {
	
	public String sayHello(String name) {
		return "Hello " + name;
	}

	public List<User> getUsers() {
		List<User> list = new ArrayList<User>();
		User u1 = new User();
		u1.setName("jack");
		u1.setAge(20);
		u1.setSex("m");

		User u2 = new User();
		u2.setName("tom");
		u2.setAge(21);
		u2.setSex("m");

		User u3 = new User();
		u3.setName("rose");
		u3.setAge(19);
		u3.setSex("w");

		list.add(u1);
		list.add(u2);
		list.add(u3);
		return list;
	}
}

服务启动类如下,直接运行即可

package com.wkp.service.simple.provider;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Provider {

	public static void main(String[] args) throws Exception {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
				new String[] { "simple-provider.xml" });
		context.start(); 
		System.in.read(); // 为保证服务一直开着,利用输入流的阻塞来模拟
	}
}

日志配置如下

log4j.rootLogger = info,stdout,D
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern =  %d %t [%c{2}] %L [%-5p] %m%n
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = ../logs/log.log
log4j.appender.D.Append = true
log4j.appender.D.Threshold = info
log4j.appender.D.DatePattern= '_'yyyy-MM-dd'.log'
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %d %t [%c{2}] %L [%-5p] %m%n

simple-provider.xml内容如下:这里配置比较简单,主要就是对spring的bean,还有Dubbo暴露的服务,使用的协议,注册中心地址、应用名称这些必要的内容做了配置。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
       xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
       http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
	
	<!-- 具体的实现bean -->
	<bean id="simpleService" class="com.wkp.service.simple.impl.SimpleServiceImpl" />

	<!-- 提供方应用信息,用于计算依赖关系 -->
	<dubbo:application name="simple-provider" />

	<!-- 使用zookeeper注册中心暴露服务地址(zookeeper单节点时,address的值例如:zookeeper://192.168.74.4:2181) -->
	<dubbo:registry address="zookeeper://192.168.74.4:2181?backup=192.168.74.5:2181,192.168.74.6:2181" />

	<!-- 用dubbo协议在20880端口暴露服务 -->
	<dubbo:protocol name="dubbo" port="20880"/>

	<!-- 声明需要暴露的服务接口  写操作可以设置retries=0 避免重复调用SOA服务 -->
	<dubbo:service retries="0" interface="com.wkp.service.simple.SimpleService" ref="simpleService" />

</beans>

三、创建服务消费者dubbo-consumer

消费者工程结构如下:log4j.properties为log4j的日志配置文件(跟上面的相同,这里就不再展示了),simple-consumer.xml是服务消费者的配置,Consumer是服务消费者的启动类

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.wkp</groupId>
	<artifactId>dubbo-consumer</artifactId>
	<version>0.0.1-SNAPSHOT</version>

	<dependencies>
		<dependency>
			<groupId>com.wkp</groupId>
			<artifactId>dubbo-interface</artifactId>
			<version>0.0.1-SNAPSHOT</version>
		</dependency>
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>dubbo</artifactId>
			<version>2.6.4</version>
		</dependency>
		<dependency>
			<groupId>org.apache.curator</groupId>
			<artifactId>curator-recipes</artifactId>
			<version>2.12.0</version>
		</dependency>
		<dependency>
			<groupId>io.netty</groupId>
			<artifactId>netty-all</artifactId>
			<version>4.0.35.Final</version>
		</dependency>
	</dependencies>
</project>

simple-consumer.xml配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
       xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
       http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">

	<!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->
	<dubbo:application name="simple-consumer" />

	<!-- 注册中心地址 -->
	<dubbo:registry address="zookeeper://192.168.74.4:2181?backup=192.168.74.5:2181,192.168.74.6:2181" />

	<!-- 生成远程服务代理,可以像使用本地bean一样使用demoService 检查级联依赖关系 默认为true 当有依赖服务的时候,需要根据需求进行设置 -->
	<dubbo:reference id="simpleService" check="false" interface="com.wkp.service.simple.SimpleService" />

</beans>

Consumer代码如下:Consumer是我们的服务消费者的启动类,我们看到可以像调用本地方法一样调用远程的服务提供者的方法。

package com.wkp.service.simple.consumer;

import java.io.IOException;
import java.util.List;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.wkp.model.User;
import com.wkp.service.simple.SimpleService;

public class Consumer {

	public static void main(String[] args) throws IOException {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"simple-consumer.xml"});
		context.start();
		
		SimpleService simpleService = (SimpleService) context.getBean("simpleService");
		String helloResult = simpleService.sayHello("Tom");
		System.out.println("sayHello result:"+helloResult);
		
		System.out.println("===============================");
		
		List<User> list = simpleService.getUsers();
		for (User user : list) {
			System.out.println("name:"+user.getName()+",age:"+user.getAge()+",sex:"+user.getSex());
		}
		
		System.in.read();
	}
}

至此,我们的项目搭建完成了。

项目启动演示

启动服务提供者

项目搭建完成之后,我们就可以启动项目了。先启动服务提供者dubbo-provider,运行该工程的Provider类即可,我们可以看到控制台的输出如下,代表我们的服务启动成功了。

2018-11-21 21:53:54,012 main [support.ClassPathXmlApplicationContext] 583 [INFO ] Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@ea30797: startup date [Wed Nov 21 21:53:54 CST 2018]; root of context hierarchy
2018-11-21 21:53:54,255 main [xml.XmlBeanDefinitionReader] 317 [INFO ] Loading XML bean definitions from class path resource [simple-provider.xml]
2018-11-21 21:53:54,778 main [logger.LoggerFactory] ? [INFO ] using logger: com.alibaba.dubbo.common.logger.log4j.Log4jLoggerAdapter
2018-11-21 21:53:55,424 main [extension.SpringExtensionFactory] 63 [WARN ]  [DUBBO] No spring extension(bean) named:defaultCompiler, try to find an extension(bean) of type java.lang.String, dubbo version: 2.6.4, current host: 169.254.68.252
2018-11-21 21:53:55,425 main [extension.SpringExtensionFactory] 77 [WARN ]  [DUBBO] No spring extension(bean) named:defaultCompiler, type:java.lang.String found, stop get bean., dubbo version: 2.6.4, current host: 169.254.68.252
2018-11-21 21:53:56,333 main [config.AbstractConfig] 121 [INFO ]  [DUBBO] The service ready on spring started. service: com.wkp.service.simple.SimpleService, dubbo version: 2.6.4, current host: 169.254.68.252
2018-11-21 21:53:56,793 main [config.AbstractConfig] 539 [INFO ]  [DUBBO] Export dubbo service com.wkp.service.simple.SimpleService to local registry, dubbo version: 2.6.4, current host: 169.254.68.252
2018-11-21 21:53:56,794 main [config.AbstractConfig] 491 [INFO ]  [DUBBO] Export dubbo service com.wkp.service.simple.SimpleService to url dubbo://169.254.68.252:20880/com.wkp.service.simple.SimpleService?anyhost=true&application=simple-provider&bind.ip=169.254.68.252&bind.port=20880&dubbo=2.0.2&generic=false&interface=com.wkp.service.simple.SimpleService&methods=sayHello,getUsers&pid=152960&retries=0&side=provider&timestamp=1542808436413, dubbo version: 2.6.4, current host: 169.254.68.252
2018-11-21 21:53:56,795 main [config.AbstractConfig] 501 [INFO ]  [DUBBO] Register dubbo service com.wkp.service.simple.SimpleService url dubbo://169.254.68.252:20880/com.wkp.service.simple.SimpleService?anyhost=true&application=simple-provider&bind.ip=169.254.68.252&bind.port=20880&dubbo=2.0.2&generic=false&interface=com.wkp.service.simple.SimpleService&methods=sayHello,getUsers&pid=152960&retries=0&side=provider&timestamp=1542808436413 to registry registry://192.168.74.4:2181/com.alibaba.dubbo.registry.RegistryService?application=simple-provider&backup=192.168.74.5:2181,192.168.74.6:2181&dubbo=2.0.2&pid=152960&registry=zookeeper&timestamp=1542808436381, dubbo version: 2.6.4, current host: 169.254.68.252
2018-11-21 21:53:59,386 main [server.Server] 100 [INFO ]  [DUBBO] qos-server bind localhost:22222, dubbo version: 2.6.4, current host: 169.254.68.252
2018-11-21 21:53:59,945 main [transport.AbstractServer] 65 [INFO ]  [DUBBO] Start NettyServer bind /0.0.0.0:20880, export /169.254.68.252:20880, dubbo version: 2.6.4, current host: 169.254.68.252
2018-11-21 21:54:00,079 main [zookeeper.ZookeeperRegistry] 200 [INFO ]  [DUBBO] Load registry store file C:\Users\Administrator.USER-20150608SC\.dubbo\dubbo-registry-simple-provider-192.168.74.4:2181.cache, data: {com.wkp.service.simple.SimpleService=empty://169.254.68.252:20880/com.wkp.service.simple.SimpleService?anyhost=true&application=simple-provider&category=configurators&check=false&dubbo=2.0.2&generic=false&interface=com.wkp.service.simple.SimpleService&methods=sayHello,getUsers&pid=84700&retries=0&side=provider&timestamp=1542636804614}, dubbo version: 2.6.4, current host: 169.254.68.252
2018-11-21 21:54:00,472 main [zookeeper.ZookeeperRegistry] 273 [INFO ]  [DUBBO] Register: dubbo://169.254.68.252:20880/com.wkp.service.simple.SimpleService?anyhost=true&application=simple-provider&dubbo=2.0.2&generic=false&interface=com.wkp.service.simple.SimpleService&methods=sayHello,getUsers&pid=152960&retries=0&side=provider&timestamp=1542808436413, dubbo version: 2.6.4, current host: 169.254.68.252
2018-11-21 21:54:00,830 main [zookeeper.ZookeeperRegistry] 298 [INFO ]  [DUBBO] Subscribe: provider://169.254.68.252:20880/com.wkp.service.simple.SimpleService?anyhost=true&application=simple-provider&category=configurators&check=false&dubbo=2.0.2&generic=false&interface=com.wkp.service.simple.SimpleService&methods=sayHello,getUsers&pid=152960&retries=0&side=provider&timestamp=1542808436413, dubbo version: 2.6.4, current host: 169.254.68.252
2018-11-21 21:54:00,871 main [zookeeper.ZookeeperRegistry] 387 [INFO ]  [DUBBO] Notify urls for subscribe url provider://169.254.68.252:20880/com.wkp.service.simple.SimpleService?anyhost=true&application=simple-provider&category=configurators&check=false&dubbo=2.0.2&generic=false&interface=com.wkp.service.simple.SimpleService&methods=sayHello,getUsers&pid=152960&retries=0&side=provider&timestamp=1542808436413, urls: [empty://169.254.68.252:20880/com.wkp.service.simple.SimpleService?anyhost=true&application=simple-provider&category=configurators&check=false&dubbo=2.0.2&generic=false&interface=com.wkp.service.simple.SimpleService&methods=sayHello,getUsers&pid=152960&retries=0&side=provider&timestamp=1542808436413], dubbo version: 2.6.4, current host: 169.254.68.252

我们可以看到日志输出了Dubbo的版本,当前机器的ip,还有把我们暴露的服务注册到zookeeper上的日志信息等。。。

启动服务消费者

服务提供者启动之后,我们运行服务消费者的启动类Consumer,然后我们可以看到控制台日志如下

2018-11-21 22:00:23,765 main [support.ClassPathXmlApplicationContext] 583 [INFO ] Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@ea30797: startup date [Wed Nov 21 22:00:23 CST 2018]; root of context hierarchy
2018-11-21 22:00:23,995 main [xml.XmlBeanDefinitionReader] 317 [INFO ] Loading XML bean definitions from class path resource [simple-consumer.xml]
2018-11-21 22:00:24,462 main [logger.LoggerFactory] ? [INFO ] using logger: com.alibaba.dubbo.common.logger.log4j.Log4jLoggerAdapter
2018-11-21 22:00:25,097 main [extension.SpringExtensionFactory] 63 [WARN ]  [DUBBO] No spring extension(bean) named:defaultCompiler, try to find an extension(bean) of type java.lang.String, dubbo version: 2.6.4, current host: 169.254.68.252
2018-11-21 22:00:25,098 main [extension.SpringExtensionFactory] 77 [WARN ]  [DUBBO] No spring extension(bean) named:defaultCompiler, type:java.lang.String found, stop get bean., dubbo version: 2.6.4, current host: 169.254.68.252
2018-11-21 22:00:27,892 main [server.Server] 102 [ERROR]  [DUBBO] qos-server can not bind localhost:22222, dubbo version: 2.6.4, current host: 169.254.68.252
java.net.BindException: Address already in use: bind
	at sun.nio.ch.Net.bind0(Native Method)
	at sun.nio.ch.Net.bind(Net.java:433)
	at sun.nio.ch.Net.bind(Net.java:425)
	at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
	at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
	at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:125)
	at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:498)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1271)
	at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:413)
	at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:399)
	at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:1019)
	at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:198)
	at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:349)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:358)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357)
	at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
	at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
	at java.lang.Thread.run(Thread.java:748)
2018-11-21 22:00:27,898 main [protocol.QosProtocolWrapper] 101 [WARN ]  [DUBBO] Fail to start qos server: , dubbo version: 2.6.4, current host: 169.254.68.252
java.net.BindException: Address already in use: bind
	at sun.nio.ch.Net.bind0(Native Method)
	at sun.nio.ch.Net.bind(Net.java:433)
	at sun.nio.ch.Net.bind(Net.java:425)
	at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
	at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
	at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:125)
	at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:498)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1271)
	at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:413)
	at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:399)
	at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:1019)
	at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:198)
	at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:349)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:358)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357)
	at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
	at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
	at java.lang.Thread.run(Thread.java:748)
2018-11-21 22:00:27,976 main [zookeeper.ZookeeperRegistry] 200 [INFO ]  [DUBBO] Load registry store file C:\Users\Administrator.USER-20150608SC\.dubbo\dubbo-registry-simple-consumer-192.168.74.4:2181.cache, data: {com.wkp.service.simple.SimpleService=dubbo://169.254.68.252:20880/com.wkp.service.simple.SimpleService?anyhost=true&application=simple-provider&dubbo=2.0.2&generic=false&interface=com.wkp.service.simple.SimpleService&methods=sayHello,getUsers&pid=84700&retries=0&side=provider&timestamp=1542636804614 empty://169.254.68.252/com.wkp.service.simple.SimpleService?application=simple-consumer&category=configurators&check=false&dubbo=2.0.2&interface=com.wkp.service.simple.SimpleService&methods=sayHello,getUsers&pid=84340&qos.accept.foreign.ip=false&qos.enable=true&qos.port=33333&side=consumer&timestamp=1542637728743 empty://169.254.68.252/com.wkp.service.simple.SimpleService?application=simple-consumer&category=routers&check=false&dubbo=2.0.2&interface=com.wkp.service.simple.SimpleService&methods=sayHello,getUsers&pid=84340&qos.accept.foreign.ip=false&qos.enable=true&qos.port=33333&side=consumer&timestamp=1542637728743}, dubbo version: 2.6.4, current host: 169.254.68.252
2018-11-21 22:00:28,587 main [zookeeper.ZookeeperRegistry] 273 [INFO ]  [DUBBO] Register: consumer://169.254.68.252/com.wkp.service.simple.SimpleService?application=simple-consumer&category=consumers&check=false&dubbo=2.0.2&interface=com.wkp.service.simple.SimpleService&methods=sayHello,getUsers&pid=52660&side=consumer&timestamp=1542808825812, dubbo version: 2.6.4, current host: 169.254.68.252
2018-11-21 22:00:28,916 main [zookeeper.ZookeeperRegistry] 298 [INFO ]  [DUBBO] Subscribe: consumer://169.254.68.252/com.wkp.service.simple.SimpleService?application=simple-consumer&category=providers,configurators,routers&check=false&dubbo=2.0.2&interface=com.wkp.service.simple.SimpleService&methods=sayHello,getUsers&pid=52660&side=consumer&timestamp=1542808825812, dubbo version: 2.6.4, current host: 169.254.68.252
2018-11-21 22:00:28,972 main [zookeeper.ZookeeperRegistry] 387 [INFO ]  [DUBBO] Notify urls for subscribe url consumer://169.254.68.252/com.wkp.service.simple.SimpleService?application=simple-consumer&category=providers,configurators,routers&check=false&dubbo=2.0.2&interface=com.wkp.service.simple.SimpleService&methods=sayHello,getUsers&pid=52660&side=consumer&timestamp=1542808825812, urls: [dubbo://169.254.68.252:20880/com.wkp.service.simple.SimpleService?anyhost=true&application=simple-provider&dubbo=2.0.2&generic=false&interface=com.wkp.service.simple.SimpleService&methods=sayHello,getUsers&pid=152960&retries=0&side=provider&timestamp=1542808436413, empty://169.254.68.252/com.wkp.service.simple.SimpleService?application=simple-consumer&category=configurators&check=false&dubbo=2.0.2&interface=com.wkp.service.simple.SimpleService&methods=sayHello,getUsers&pid=52660&side=consumer&timestamp=1542808825812, empty://169.254.68.252/com.wkp.service.simple.SimpleService?application=simple-consumer&category=routers&check=false&dubbo=2.0.2&interface=com.wkp.service.simple.SimpleService&methods=sayHello,getUsers&pid=52660&side=consumer&timestamp=1542808825812], dubbo version: 2.6.4, current host: 169.254.68.252
2018-11-21 22:00:29,372 main [transport.AbstractClient] 282 [INFO ]  [DUBBO] Successed connect to server /169.254.68.252:20880 from NettyClient 169.254.68.252 using dubbo version 2.6.4, channel is NettyChannel [channel=[id: 0x3b6d844d, /169.254.68.252:61898 => /169.254.68.252:20880]], dubbo version: 2.6.4, current host: 169.254.68.252
2018-11-21 22:00:29,372 main [transport.AbstractClient] 91 [INFO ]  [DUBBO] Start NettyClient USER-20150608SC/169.254.68.252 connect to the server /169.254.68.252:20880, dubbo version: 2.6.4, current host: 169.254.68.252
2018-11-21 22:00:29,662 main [config.AbstractConfig] 425 [INFO ]  [DUBBO] Refer dubbo service com.wkp.service.simple.SimpleService from url zookeeper://192.168.74.4:2181/com.alibaba.dubbo.registry.RegistryService?anyhost=true&application=simple-consumer&check=false&dubbo=2.0.2&generic=false&interface=com.wkp.service.simple.SimpleService&methods=sayHello,getUsers&pid=52660&register.ip=169.254.68.252&remote.timestamp=1542808436413&retries=0&side=consumer&timestamp=1542808825812, dubbo version: 2.6.4, current host: 169.254.68.252
sayHello result:Hello Tom
===============================
name:jack,age:20,sex:m
name:tom,age:21,sex:m
name:rose,age:19,sex:w

我们可以看到,虽然日志中出现了下面的异常,但是方法还是调用成功了。关于这个报错的问题,我们这里暂时先不理会,欲知后事如何,且听下回分解,哈哈!下一节将会解释为什么会出现这个问题,还有如何去解决它。

2018-11-21 22:00:27,892 main [server.Server] 102 [ERROR]  [DUBBO] qos-server can not bind localhost:22222, dubbo version: 2.6.4, current host: 169.254.68.252
java.net.BindException: Address already in use: bind
........
2018-11-21 22:00:27,898 main [protocol.QosProtocolWrapper] 101 [WARN ]  [DUBBO] Fail to start qos server: , dubbo version: 2.6.4, current host: 169.254.68.252
java.net.BindException: Address already in use: bind

好了,本节的内容就先介绍到这里,相信你对Dubbo的基本用法已经掌握了。下节当中,将会给大家介绍关于我们服务消费启动时 "qos-server can not bind localhost:22222" 的报错问题。

相关文章