搭建我的dubbo项目

       这些年dubbo/springCloud已经成为必备技能了,可是我司的系统架构还是非常传统,为了增加职业技能,花了些时间点了dubbo技能树.

 dubbo源码下载:

        平台:git,地址:https://github.com/apache/incubator-dubbo

           简单说下为什么要使用zookeer作为注册中心,推荐指数5颗星,现在大部分的项目都是依托于zookeeper管理,技术非常成熟,而且一个zookeeper集群可以管理很多不同的中间件集群/应用,当然除了zookeer ,官方还提供了自己的Simple 注册中心和redis注册中心

  • provider 服务提供者配置修改

 

搭建我的dubbo项目

 

<?xml version="1.0" encoding="UTF-8"?>
<!--
  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.
  -->
<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">

    <!-- provider's application name, used for tracing dependency relationship -->
    <dubbo:application name="demo-provider"/>

    <dubbo:registry protocol="zookeeper" address="10.8.202.185:2181" />
    <!--设置 zookeeper 的根节点,不设置将使用无根树-->


    <dubbo:protocol name="dubbo"/>

    <!-- service implementation, as same as regular local bean -->
    <bean id="demoService" class="org.apache.dubbo.demo.provider.DemoServiceImpl"/>

    <!-- declare the service interface to be exported -->
    <dubbo:service interface="org.apache.dubbo.demo.DemoService" ref="demoService"/>

</beans>
  • consumer 服务提供者配置修改

搭建我的dubbo项目

 

 

<?xml version="1.0" encoding="UTF-8"?>
<!--
  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.
  -->
<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="demo-consumer"/>

    <dubbo:registry protocol="zookeeper" address="10.8.202.185:2181" />


    <!-- generate proxy for the remote service, then demoService can be used in the same way as the
    local regular interface -->
    <dubbo:reference id="demoService" check="false" interface="org.apache.dubbo.demo.DemoService"/>

    <!-- 支持 * 号通配符 <dubbo:reference group="*" version="*" />,可订阅服务的所有分组和所有版本的提供者 -->

</beans>

 

 

  1. 运行zookeeper
  2. 运行provider  和springboot一样找到 Application 类运行main方法 
  3. 运行consumer 
  4. 查看控制台
    [28/03/19 16:18:51:749 CST] DubboServerHandler-10.63.194.237:20880-thread-5  INFO provider.DemoServiceImpl: Hello world, request from consumer: /10.63.194.237:49597

    接下来将准备做一个web项目和dubbo的整合,不知道啥时候能写完了...最近需求积压太多了.......