Dubbo的快速使用

Dubbo的基本使用

1、Dubbo概述
2、Dubbo处理流程
3、服务注册中心Zookeeper
4、Dubbo基本使用
4.1、基于注解模式
4.2、基于XML模式

1.Dubbo概述

Apache Dubbo是一款高性能的Java RPC框架。其前身是阿里巴巴公司开源的一个高性能、轻量级的开源Java RPC框架,可以和Spring框架无缝集成。

官网提供了用户文档与开发指南,基本对所有功能有大概的描述与使用方式
官方网址:https://dubbo.apache.org/zh/

2.Dubbo处理流程

以下处理流程图与节点说明均来自官方
在这里插入图片描述

节点说明:

节点角色名称
Provider暴露服务的服务提供方
Consumer调用远程服务的服务消费方
Registry服务注册与发现的注册中心(zookeeper)
Monitor统计服务的调用次数和调用时间的监控中心
Container服务运行容器,负责启动、加载、运行服务提供者

3.服务注册中心Zookeeper

通过前面的Dubbo架构图可以看到,Registry(服务注册中心)在其中起着至关重要的作用。Dubbo官方推荐使用Zookeeper作为服务注册中心。Zookeeper 是 Apache Hadoop 的子项目,作为 Dubbo 服务的注册中心,工业强度较高,可用于生产环境,并推荐使用
Zookeeper安装及使用请参考:**Zookeeper**

4.Dubbo基本使用

快速入门码云克隆地址:https://gitee.com/zhangxushare/duboo.git

启动时:先启动注册中心zookeeper,在启动提供者,其次消费者
在这里插入图片描述

4.1注解版

spring+mvc版

项目结构如下:把公共接口抽取出来,service中写实现,controller中调用
在这里插入图片描述

1.接口协定(公共接口)
若是服务提供者和消费者都自己写一份,就不方便维护,导致不一致。

package com.itheima.service;
public interface UserService {
    public String sayHello();
}

2.创建服务提供者
首先引入与消费者相同的公共依赖,以及zookeeper和dubbo的包

        <!--依赖公共的接口模块-->
        <dependency>
            <groupId>com.itheima</groupId>
            <artifactId>dubbo-interface</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
         
        <!--Dubbo的起步依赖,版本2.7之后统一为rg.apache.dubb -->
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo</artifactId>
            <version>2.7.4.1</version>
        </dependency>
        <!--ZooKeeper客户端实现 -->
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-framework</artifactId>
            <version>4.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-recipes</artifactId>
            <version>4.0.0</version>

在spring的配置文件里配置dubbo (注意包扫描使用的dubbo开头)

<?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://dubbo.apache.org/schema/dubbo" xmlns:context="http://www.springframework.org/schema/context"
	   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
	<!--<context:component-scan base-package="com.itheima.service" />-->
	<!--dubbo的配置-->
	<!--1.配置项目的名称,唯一-->
	<dubbo:application name="dubbo-service">
     <!--加入该配置,启动时警告端口占用就没有了-->
    <dubbo:parameter key="qos.port" value="33333"/>
    </dubbo:application>
	<!--2.配置注册中心的地址-->
	<dubbo:registry address="zookeeper://localhost:2181"/>
	<!--3.配置dubbo包扫描-->
	<dubbo:annotation package="com.itheima.service.impl" />
</beans>

一台机子启动报错端口占用加如上代码<dubbo:parameter key=“qos.port” value=“33333”/>修改端口

java.net.BindException: Address already in use: bind

创建公共接口实现类
注意:此处的@service导包是dubbo中的,不要到错了

import com.itheima.service.UserService;
import org.apache.dubbo.config.annotation.Service;
//@Service spring中,将该类的对象创建出来,放到Spring的IOC容器中  bean定义
//此处的service是dubbo中的,将这个类提供的方法(服务)对外发布,将访问的地址 ip,端口,路径注册到注册中心中
@Service
public class UserServiceImpl implements UserService {
    @Override
    public String sayHello() {
        return "hello dubbo hello!~";
    }
}

3.创建服务消费者

首先引入与服务提供者相同的公共依赖,以及zookeeper和dubbo的包,和上面提供者的pom一样

在springMVC的配置文件里配置dubbo与上相似,但需要配置springMVC注解扫描等

    <mvc:annotation-driven/>
    <context:component-scan base-package="com.itheima.controller"/>

    <!--dubbo的配置-->
    <!--1.配置项目的名称,唯一-->
    <dubbo:application name="dubbo-web" >
    <!--加入该配置,启动时警告端口占用就没有了-->
    <dubbo:parameter key="qos.port" value="22222"/>
    </dubbo:application>
    <!--2.配置注册中心的地址-->
    <dubbo:registry address="zookeeper://localhost:2181"/>
    <!--3.配置dubbo包扫描-->
    <dubbo:annotation package="com.itheima.controller" />

创建userService的消费者,@Reference关键字远程注入,调用服务

package com.itheima.controller;
import com.itheima.service.UserService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/user")
public class UserController {
    //注入Service
    //@Autowired 本地注入

    /*  @Reference 远程注入
        1. 从zookeeper注册中心获取userService的访问url
        2. 进行远程调用RPC
        3. 将结果封装为一个代理对象。给变量赋值 */
    @Reference
    private UserService userService;
    @RequestMapping("/sayHello")
    public String sayHello(){
        return userService.sayHello();
    }
}

小推荐:
小测试项目直接使用maven插件,就不用再配置本地tomcat啦

    <build>
        <plugins>
            <!--tomcat插件-->
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <port>9000</port>
                    <path>/</path>
                </configuration>
            </plugin>
        </plugins>
    </build>

springBoot版

可以也用上面的pom版本,最新版本的注解有所不同,注解有 @DubboService、@DubboReference。
注解版别忘了主启动类@EnableDbubbo开启注解,xml配置不需要开启

4.2 xml版本(springBoot)

提供者
先在资源下创建配置文件,使用xml配置则服务名,注册中心等也必须要在xml中配置,然后加载配置文件,去掉@Service即可 (yml中配置会找不到提供者,无法装配创建bean,自己是这样的)

<?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" xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    <context:property-placeholder/>

    <dubbo:application name="dubbo-springboot-demo-privder"/>
    <dubbo:registry address="zookeeper://localhost:2181"/>
    <dubbo:service interface="com.example.service_api.UserService" ref="userServiceImpl"/>
    <bean id="userServiceImpl" class="com.example.boot_service.imp.UserServiceImpl"/>

</beans>

消费者
同上步骤,去掉@Refance,用@Autowrite即可

<?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" xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    <context:property-placeholder/>

    <dubbo:application name="dubbo-springboot-demo-consumer"/>
    <dubbo:registry address="zookeeper://localhost:2181"/>
    <dubbo:reference interface="com.example.service_api.UserService" id="userServiceImpl"/>
</beans>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
其实爆破服务器很简单的,也是必学的。 3389是一个远程桌面的端口,很多人为了更方便管理服务器,更新服务器上的资源等,经常会开启3389端口,用nastat-an命令可以查看该端口的开启。对于一个账户如果账号密码过于弱很容易被爆破到,一般默认账号为Administrator或admin,而对于过于简单的密码,在3389密码字典中均可找到,下面来讲解爆破3389服务器,获得一台服务器的全过程。 工具:DUbrute爆破工具(或者用frdpb) SYN扫描工具 IP Search 首先用IPseacher搜索一段活跃的IP段,也可以在百度搜索活跃3389IP段,其次就是SYN扫描,最好是在server2003的系统下扫描,实在不行可以用VMware虚拟机做2003系统进行扫描,如果硬要在XP系统下扫描,那么先让XP支持SYN扫描,将支持SYN补丁tcpip复制到C盘的drives下,重启后即可进行SYN扫描,对于刚装好的server2003系统先开启以下服务。 scconfig LmHosts start= auto sc config RpcLocator start= auto sc configNtlmSsp start= auto sc config lanmanserver start= auto sc configSharedAccess start= disabled net start LmHosts 2>nul net startRpcLocator 2>nul net start NtlmSsp 2>nul net start lanmanserver2>nul net stop SharedAccess >nul 2>nul 将IPseach下的IP段复制到SYN扫描器下的ip.txt中,开始扫描一段时间。扫描完毕后生产ips文档,IPS文档中的IP就是开启3389端口的IP。 下面使用DUbrute工具,这款工具是全英文版的工具,下面本人对这款工具进行翻译下。 Source表示“源”。 Bad表示“坏的” Good表示“好的” Error表示“错误的” Check表示:“检测” Thread表示“线程” Start表示“开始” Stop表示“停止” Config表示“配置” Generation表示“生成” About表示“关于” Exit表示“退出” 大概重要的翻译完了,下面导入需要爆破的3389的IP,直接打开Generation,打开后会发现有三列需要添加的东西,第一列中是需要爆破的IP,我们直接点击FileIP导入IPS下的所有IP,第二列Login是登陆账号,我们这里可以直接选择AddLogin添加用户名,两个就可以了吧,就直接Administrator或者Admin,当然你也可以导入Username的字典,不过这样更慢而已。第三列Password,选择Filepass导入我们的3389密码字典。最后点击male,退出该界面。点击Config进行配置,对于2G的服务器可以将Thread线程到2000.我们随便选择1000或者500.。OK,下面有bad.txt和Good.txt里面装载的会是我们之后的服务器IP的正确账号密码和错误的连接IP。 OK,开始点击Start爆破,等待时间,Good后面出现数字表示我们已经爆破成功多少台服务器,Bad表示坏的正在Check中,我们可以在DUbrute下找到Good文档打开,可以看到爆破成功的服务器的IP和登录账号密码。 恭喜爆破成功,开始——运行——mstsc-admin,进入3389登录框,输入IP,连接上去输入爆破到的账号密码,登录服务器中,这一步恭喜你成功得到了一台服务器,赶紧创建一个属于自己的用户吧。亲,不要做坏事哦,如果是游戏服务器不要打扰别人游戏哦。 其实得到服务器后还有一系列留后门的方法,包括对net拒权的方法.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值