dubbo 初体验

我的原文地址 http://www.inspires.cn/note/27

 上一家公司使用阿里巴巴的DubboSOA的基础框架,并在其上做集成,由于之前环境都是架构师搭建的,所以我还不是很了解,只是会用,前几天心血来潮自己搭建了一个helloworld版,这里记录一下搭建过程。

         第一步,要选择dubbo的中间件,之前用的是zookeeper来做注册中心的,所以我这边也使用它来搭建注册中心,下载地址去apache的官网下载,可以戳我直接去到官网下载稳定版本。而后解压到本地文件夹,解压出来的结构如下

打开conf文件夹,copy zoo_sample.cfg副本,重命名为zoo.cfg,然后可以修改里面的内容,也可以不修改。

打开bin目录下的zkServer.cmd文件,如果报错,请设置好环境变量。

 

 

正常启动如下

注册中心就弄好了,

         第二步,创建service工程与其中的服务,本案例使用maven构建系统,怎么创建maven系统这边就不做赘述了,主要上下其中的代码

pom.xml

        

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
< project  xmlns = "http://maven.apache.org/POM/4.0.0"  xmlns:xsi=" 
  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.inspires</ groupId >
          < artifactId >dubbo-service</ artifactId >
          < version >0.0.1-SNAPSHOT</ version >
          < packaging >jar</ packaging >
  
          < name >dubbo-service</ name >
          < url >http://maven.apache.org</ url >
  
          < properties >
                    < project.build.sourceEncoding >UTF-8</ project.build.sourceEncoding >
          </ properties >
          < dependencies >
         
                    < dependency >
                             < groupId >junit</ groupId >
                             < artifactId >junit</ artifactId >
                             < version >4.12</ version >
                    </ dependency >
  
                    < dependency >
                             < groupId >org.springframework</ groupId >
                             < artifactId >spring-context</ artifactId >
                             < version >3.2.5.RELEASE</ version >
                    </ dependency >
  
                    < dependency >
                             < groupId >com.alibaba</ groupId >
                             < artifactId >dubbo</ artifactId >
                             < version >2.4.9</ version >
                    </ dependency >
  
                    < dependency >
                             < groupId >org.apache.zookeeper</ groupId >
                             < artifactId >zookeeper</ artifactId >
                             < version >3.4.6</ version >
                    </ dependency >
                    < dependency >
                             < groupId >com.101tec</ groupId >
                             < artifactId >zkclient</ artifactId >
                             < version >0.4</ version >
                    </ dependency >
          </ dependencies >
</ project >

然后创建一个spring的配置文件命名为service-dubbo.xml

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<? 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://code.alibabatech.com/schema/dubbo"
          xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans.xsd
         http://code.alibabatech.com/schema/dubbo
         http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
          <!-- 提供方应用信息,用于计算依赖关系 -->
          < dubbo:application  name = "service-test-dubbo" />
          <!-- 使用multicast广播注册中心暴露服务地址 -->
          < dubbo:registry  address = "zookeeper://127.0.0.1:2181"  />
          <!-- 用dubbo协议在20880端口暴露服务 -->
          < dubbo:protocol  name = "dubbo"  port = "20880"  />
          <!-- 声明需要暴露的服务接口 -->
          < dubbo:service  interface = "com.inspires.dubbo.service.IDemoService"  ref = "demoService"  />
          <!-- 和本地bean一样实现服务 -->
          < bean  id = "demoService"  class = "com.inspires.dubbo.service.impl.DemoService"  />
</ beans >

 

接下来创建一个接口与实现类IDemoServiceDemoService,只创建一个sayHello方法以做校验

IDemoService.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
  *
  */
package  com.inspires.dubbo.service;
  
/**
  * @author Jon Chiang
  * @project dubbo-service
  * @create_date 2014-12-30 下午5:06:52
  */
public  interface  IDemoService {
  
          /**
            * @author Jon Chiang
            * @create_date 2014-12-30 下午5:09:27
            * @param name
            * @return
            */
          String sayHello(String name);
}

DemoService.java 不多说

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
  *
  */
package  com.inspires.dubbo.service.impl;
  
import  com.inspires.dubbo.service.IDemoService;
  
/**
  * @author Jon Chiang
  * @project dubbo-service
  * @create_date 2014-12-30 下午5:07:29
  */
public  class  DemoService  implements  IDemoService {
          static  int  sayHelloCount =  0 ;
          @Override
          public  String sayHello(String name) {
                    String hello =  "Hello "  + name;
                    System.out.println(++sayHelloCount);
                    System.out.println(hello);
                    return  hello;
          }
}

还有web.xml里面要做spring配置文件和监听的配置,这里不做赘述(附件里面有,不会的同事可以参考附件)这里service工程基本弄好了

第三步,创建maven的访问者或者客户端工程。

pom.xml 注意要引用service工程,不然没法访问IDemoService

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
< 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/maven-v4_0_0.xsd" >
          < modelVersion >4.0.0</ modelVersion >
          < groupId >com.inspires</ groupId >
          < artifactId >dubbo-client</ artifactId >
          < packaging >war</ packaging >
          < version >0.0.1-SNAPSHOT</ version >
          < name >dubbo-client Maven Webapp</ name >
          < url >http://maven.apache.org</ url >
  
          < build >
                    < finalName >dubbo-client</ finalName >
          </ build >
          < dependencies >
                    < dependency >
                             < groupId >junit</ groupId >
                             < artifactId >junit</ artifactId >
                             < version >4.12</ version >
                    </ dependency >
  
                    < dependency >
                             < groupId >org.springframework</ groupId >
                             < artifactId >spring-context</ artifactId >
                             < version >3.2.5.RELEASE</ version >
                    </ dependency >
  
                    < dependency >
                             < groupId >com.alibaba</ groupId >
                             < artifactId >dubbo</ artifactId >
                             < version >2.4.9</ version >
                    </ dependency >
  
                    < dependency >
                             < groupId >org.apache.zookeeper</ groupId >
                             < artifactId >zookeeper</ artifactId >
                             < version >3.4.6</ version >
                    </ dependency >
                    < dependency >
                             < groupId >com.101tec</ groupId >
                             < artifactId >zkclient</ artifactId >
                             < version >0.4</ version >
                    </ dependency >
                    < dependency >
                             < groupId >com.inspires</ groupId >
                             < artifactId >dubbo-service</ artifactId >
                             < version >0.0.1-SNAPSHOT</ version >
                    </ dependency >
          </ dependencies >
</ project >

然后就是spring文件

client-dubbo.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<? 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://code.alibabatech.com/schema/dubbo"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans.xsd
         http://code.alibabatech.com/schema/dubbo
         http://code.alibabatech.com/schema/dubbo/dubbo.xsd
         ">
     <!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->
     < dubbo:application  name = "client-test-dubbo" />        <!-- 使用zookeeper广播注册中心暴露发现服务地址 -->
     < dubbo:registry  address = "zookeeper://127.0.0.1:2181"  />          <!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
     < dubbo:reference  id = "demoService"  interface = "com.inspires.dubbo.service.IDemoService"  />
</ beans >
client-common.xml
<? 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:context = "http://www.springframework.org/schema/context"
          xmlns:tx = "http://www.springframework.org/schema/tx"  xmlns:util = "http://www.springframework.org/schema/util"
          xsi:schemaLocation="http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
          http://www.springframework.org/schema/util
          http://www.springframework.org/schema/util/spring-util-3.2.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
                    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd"
          default-lazy-init = "false" >
          < context:annotation-config  />
          < context:component-scan  base-package = "com.inspires.dubbo.service"  />   <!-- 自动扫描所有注解该路径 -->
</ beans >

让后我们在service里面写一个测试调用远程接口的方法。因为我这边只是测试接口是否通,所以使用@PostConstruct注解,让工程一启动就调用init方法访问接口,达到我测试的目的。

TestService.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
  *
  */
package  com.inspires.dubbo.service.impl;
  
import  javax.annotation.PostConstruct;
  
import  org.springframework.beans.factory.annotation.Autowired;
import  org.springframework.stereotype.Service;
  
import  com.inspires.dubbo.service.IDemoService;
import  com.inspires.dubbo.service.ITestService;
  
/**
  * @author Jon Chiang
  * @project dubbo-client
  * @create_date 2014-12-30 下午6:54:12
  */
@Service
public  class  TestService  implements  ITestService{
  
          @Autowired
          IDemoService demoService;
         
          @PostConstruct
          @Override
          public  void  init(){
                    for  ( int  i =  0 ; i <  20 ; i++) {
                             demoService.sayHello( "Jon Chiang " );
                    }
                   
          }
}

然后可以开测了

启动service工程控制台无异常,然后启动client工程,系统调用远程方法。控制台答应hello Jon  Chiang 大功告成也!

 

附件为工程文件 戳我 下载

【EI复现】基于深度强化学习的微能源网能量管理与优化策略研究(Python代码实现)内容概要:本文围绕“基于深度强化学习的微能源网能量管理与优化策略”展开研究,重点利用深度Q网络(DQN)等深度强化学习算法对微能源网中的能量调度进行建模与优化,旨在应对可再生能源出力波动、负荷变化及运行成本等问题。文中结合Python代码实现,构建了包含光伏、储能、负荷等元素的微能源网模型,通过强化学习智能体动态决策能量分配策略,实现经济性、稳定性和能效的多重优化目标,并可能与其他优化算法进行对比分析以验证有效性。研究属于电力系统与人工智能交叉领域,具有较强的工程应用背景和学术参考价值。; 适合人群:具备一定Python编程基础和机器学习基础知识,从事电力系统、能源互联网、智能优化等相关方向的研究生、科研人员及工程技术人员。; 使用场景及目标:①学习如何将深度强化学习应用于微能源网的能量管理;②掌握DQN等算法在实际能源系统调度中的建模与实现方法;③为相关课题研究或项目开发提供代码参考和技术思路。; 阅读建议:建议读者结合提供的Python代码进行实践操作,理解环境建模、状态空间、动作空间及奖励函数的设计逻辑,同时可扩展学习其他强化学习算法在能源系统中的应用。
皮肤烧伤识别作为医学与智能技术交叉的前沿课题,近年来在深度学习方法推动下取得了显著进展。该技术体系借助卷积神经网络等先进模型,实现了对烧伤区域特征的高效提取与分类判别,为临床诊疗决策提供了重要参考依据。本研究项目系统整合了算法设计、数据处理及模型部署等关键环节,形成了一套完整的可操作性方案。 在技术实现层面,首先需要构建具有代表性的烧伤图像数据库,涵盖不同损伤程度及愈合阶段的临床样本。通过对原始图像进行标准化校正、对比度增强等预处理操作,有效提升后续特征学习的稳定性。网络架构设计需充分考虑皮肤病变的区域特性,通过多层卷积与池化操作的组合,逐步抽象出具有判别力的烧伤特征表示。 模型优化过程中采用自适应学习率调整策略,结合交叉熵损失函数与梯度下降算法,确保参数收敛的稳定性。为防止过拟合现象,引入数据扩增技术与正则化约束,增强模型的泛化能力。性能验证阶段采用精确率、召回率等多维度指标,在独立测试集上全面评估模型对不同烧伤类型的识别效能。 经过充分验证的识别系统可集成至医疗诊断平台,通过规范化接口实现与现有医疗设备的无缝对接。实际部署前需进行多中心临床验证,确保系统在不同操作环境下的稳定表现。该技术方案的实施将显著缩短烧伤评估时间,为临床医师提供客观量化的辅助诊断依据,进而优化治疗方案制定流程。 本项目的突出特点在于将理论研究与工程实践有机结合,既包含前沿的深度学习算法探索,又提供了完整的产业化实施路径。通过模块化的设计思路,使得医疗专业人员能够快速掌握核心技术方法,推动智能诊断技术在烧伤外科领域的实际应用。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值