基於springboot和dubbo搭建SOA服務

2021-08-08 20:24:17 字數 4464 閱讀 2650

詳見zookeeper搭建

配置 修改tomcat的埠8088,修改方法如下,打到conf下的檔案 server.xml,因為zookeeper會用到8080的埠,所以為了不衝突,把tomcat的埠改一下。

/*** 設定dubbo掃瞄包

** @param packagename

* @return

*/@bean

public static annotationbean annotationbean(@value("$") string packagename)

/*** 注入dubbo上下文

** @return

*/@bean

// 當前應用配置

}/**

* 注入dubbo註冊中心配置,基於zookeeper

** @return

*/@bean

public registryconfig registryconfig()

/*** 預設基於dubbo協議提供服務

** @return

*/@bean

public protocolconfig protocolconfig()

@bean(name = "dubboprovider")

providerconfig providerconfig = new providerconfig();

providerconfig.settimeout(timeout);

providerconfig.setretries(retries);

providerconfig.setdelay(delay);

providerconfig.setregistry(registryconfig);

providerconfig.setprotocol(protocolconfig);

return providerconfig;

}/**

* dubbo消費

** @param registryconfig

* @return

*/@bean(name="defaultconsumer")

consumerconfig consumerconfig = new consumerconfig();

consumerconfig.setcheck(check);

return consumerconfig;}}

}public string getprotocol()

public void setprotocol(string protocol)

public string getregistryaddress()

public void setregistryaddress(string registryaddress)

public string getprotocolname()

public void setprotocolname(string protocolname)

public int getprotocolport()

public void setprotocolport(int protocolport)

public int gettimeout()

public void settimeout(int timeout)

public int getretries()

public void setretries(int retries)

public int getdelay()

public void setdelay(int delay)

public boolean ischeck()

public void setcheck(boolean check)

}.name=pay-service

.logger=slf4j

dubbo.annotation

.package=com

.alibaba

.dubbo

.demo

dubbo.protocol

.name=dubbo

dubbo.protocol

.port=20880

dubbo.protocol

.accesslog=true

dubbo.provider

.timeout=3000

dubbo.provider

.retries=1

dubbo.provider

.delay=-1

dubbo.registr

.protocol=zookeeper

dubbo.registry

.address=127.0

.0.1:2181

dubbo.registry

.register=true

dubbo.reference

.check=false

package com.alibaba.dubbo.demo;

public

inte***ce demoservice

package com.alibaba.dubbo.demo.provider;

import com.alibaba.dubbo.demo.demoservice;

import com.alibaba.dubbo.config.annotation.service;

@service(version = "1.0.0", provider = "dubboprovider")

public

class

demoserviceimpl

implements

demoservice

}

package com.alibaba.dubbo.demo.consumer;

import com.alibaba.dubbo.demo.demoservice;

import com.alibaba.dubbo.demo.democonsumerservice;

import com.alibaba.dubbo.config.annotation.reference;

public

class

democonsumerserviceimpl

implements

democonsumerservice

}

基於SpringBoot開發

使用idea配置springboot專案 專案結構 而 configuration 經常與 bean 組合使用,使用這兩個註解就可以建立乙個簡單的spring 配置類,可以用來替代相應的xml 配置檔案。enableautocon figuration 能夠自動配置spring 的上下文,猜測和配置...

SpringBoot2 X註解版本整合Dubbo

最近面試被問到有沒有用過dubbo或者springcloud很遺憾只知道皮毛,沒有實際動手弄過,因為這幾年都是搞的小專案,說來慚愧,好了,不廢話了,進入正題。從昨天早上開始整合springboot 和dubbo 到今天早上算是花了整整一天終於整個成功了,首先來張圖慶祝下 首先要注意的就是spring...

基於 spring boot事件驅動設計

spring的事件預設是同步的,如需非同步需使用非同步註解及執行緒池或訊息佇列 private userbean user public userregisterevent userbean user service public class userservice 實現方式1 component ...