标签:provider activemq ota 工具 机器 ima address control jdb
dubbo的具体使用:
dubbo简介:
随着互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,急需一个治理系统确保架构有条不紊的演进。
1-2、使用dubbo的优点:
使用dubbo。使用rpc协议进行远程调用,直接使用socket通信。传输效率高,并且可以统计出系统之间的调用关系、调用次数。
1-2、Webservice:效率不高基于soap协议。项目中不推荐使用。
Dubbo就是资源调度和治理中心的管理工具。
节点角色说明:
调用关系说明:
使用:
Dubbo采用全Spring配置方式,透明化接入应用,对应用没有任何API侵入,只需用Spring加载Dubbo的配置即可,Dubbo基于Spring的Schema扩展进行加载。
3-1代码实现:
代码下载: https://pan.baidu.com/s/1_WXqOJPT0vuhz7g0HzlvyQ
1:搭建maven结构:
floor-parent -- pom.xml的配置:
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <modelVersion>4.0.0</modelVersion> 6 7 <groupId>com.wfd360.com</groupId> 8 <artifactId>floor-parent</artifactId> 9 <version>1.0-SNAPSHOT</version> 10 <modules> 11 <module>floor-common</module> 12 <module>floor-manager</module> 13 </modules> 14 15 <packaging>pom</packaging> 16 <!-- 集中定义依赖版本号 --> 17 <properties> 18 <junit.version>4.12</junit.version> 19 <spring.version>4.2.4.RELEASE</spring.version> 20 <mybatis.version>3.2.8</mybatis.version> 21 <mybatis.spring.version>1.2.2</mybatis.spring.version> 22 <mybatis.paginator.version>1.2.15</mybatis.paginator.version> 23 <mysql.version>5.1.32</mysql.version> 24 <slf4j.version>1.6.4</slf4j.version> 25 <jackson.version>2.4.2</jackson.version> 26 <druid.version>1.0.9</druid.version> 27 <httpclient.version>4.3.5</httpclient.version> 28 <jstl.version>1.2</jstl.version> 29 <servlet-api.version>2.5</servlet-api.version> 30 <jsp-api.version>2.0</jsp-api.version> 31 <joda-time.version>2.5</joda-time.version> 32 <commons-lang3.version>3.3.2</commons-lang3.version> 33 <commons-io.version>1.3.2</commons-io.version> 34 <commons-net.version>3.3</commons-net.version> 35 <pagehelper.version>3.4.2-fix</pagehelper.version> 36 <jsqlparser.version>0.9.1</jsqlparser.version> 37 <commons-fileupload.version>1.3.1</commons-fileupload.version> 38 <jedis.version>2.7.2</jedis.version> 39 <solrj.version>4.10.3</solrj.version> 40 <dubbo.version>2.5.3</dubbo.version> 41 <zookeeper.version>3.4.7</zookeeper.version> 42 <zkclient.version>0.1</zkclient.version> 43 <activemq.version>5.11.2</activemq.version> 44 <freemarker.version>2.3.23</freemarker.version> 45 <quartz.version>2.2.2</quartz.version> 46 </properties> 47 <dependencyManagement> 48 <dependencies> 49 <!-- 时间操作组件 --> 50 <dependency> 51 <groupId>joda-time</groupId> 52 <artifactId>joda-time</artifactId> 53 <version>${joda-time.version}</version> 54 </dependency> 55 <!-- Apache工具组件 --> 56 <dependency> 57 <groupId>org.apache.commons</groupId> 58 <artifactId>commons-lang3</artifactId> 59 <version>${commons-lang3.version}</version> 60 </dependency> 61 <dependency> 62 <groupId>org.apache.commons</groupId> 63 <artifactId>commons-io</artifactId> 64 <version>${commons-io.version}</version> 65 </dependency> 66 <dependency> 67 <groupId>commons-net</groupId> 68 <artifactId>commons-net</artifactId> 69 <version>${commons-net.version}</version> 70 </dependency> 71 <!-- Jackson Json处理工具包 --> 72 <dependency> 73 <groupId>com.fasterxml.jackson.core</groupId> 74 <artifactId>jackson-databind</artifactId> 75 <version>${jackson.version}</version> 76 </dependency> 77 <!-- httpclient --> 78 <dependency> 79 <groupId>org.apache.httpcomponents</groupId> 80 <artifactId>httpclient</artifactId> 81 <version>${httpclient.version}</version> 82 </dependency> 83 <!-- quartz任务调度框架 --> 84 <dependency> 85 <groupId>org.quartz-scheduler</groupId> 86 <artifactId>quartz</artifactId> 87 <version>${quartz.version}</version> 88 </dependency> 89 <!-- 单元测试 --> 90 <dependency> 91 <groupId>junit</groupId> 92 <artifactId>junit</artifactId> 93 <version>${junit.version}</version> 94 <scope>test</scope> 95 </dependency> 96 <!-- 日志处理 --> 97 <dependency> 98 <groupId>org.slf4j</groupId> 99 <artifactId>slf4j-log4j12</artifactId> 100 <version>${slf4j.version}</version> 101 </dependency> 102 <!-- Mybatis --> 103 <dependency> 104 <groupId>org.mybatis</groupId> 105 <artifactId>mybatis</artifactId> 106 <version>${mybatis.version}</version> 107 </dependency> 108 <dependency> 109 <groupId>org.mybatis</groupId> 110 <artifactId>mybatis-spring</artifactId> 111 <version>${mybatis.spring.version}</version> 112 </dependency> 113 <dependency> 114 <groupId>com.github.miemiedev</groupId> 115 <artifactId>mybatis-paginator</artifactId> 116 <version>${mybatis.paginator.version}</version> 117 </dependency> 118 <dependency> 119 <groupId>com.github.pagehelper</groupId> 120 <artifactId>pagehelper</artifactId> 121 <version>${pagehelper.version}</version> 122 </dependency> 123 <!-- MySql --> 124 <dependency> 125 <groupId>mysql</groupId> 126 <artifactId>mysql-connector-java</artifactId> 127 <version>${mysql.version}</version> 128 </dependency> 129 <!-- 连接池 --> 130 <dependency> 131 <groupId>com.alibaba</groupId> 132 <artifactId>druid</artifactId> 133 <version>${druid.version}</version> 134 </dependency> 135 <!-- Spring --> 136 <dependency> 137 <groupId>org.springframework</groupId> 138 <artifactId>spring-context</artifactId> 139 <version>${spring.version}</version> 140 </dependency> 141 <dependency> 142 <groupId>org.springframework</groupId> 143 <artifactId>spring-beans</artifactId> 144 <version>${spring.version}</version> 145 </dependency> 146 <dependency> 147 <groupId>org.springframework</groupId> 148 <artifactId>spring-webmvc</artifactId> 149 <version>${spring.version}</version> 150 </dependency> 151 <dependency> 152 <groupId>org.springframework</groupId> 153 <artifactId>spring-jdbc</artifactId> 154 <version>${spring.version}</version> 155 </dependency> 156 <dependency> 157 <groupId>org.springframework</groupId> 158 <artifactId>spring-aspects</artifactId> 159 <version>${spring.version}</version> 160 </dependency> 161 <dependency> 162 <groupId>org.springframework</groupId> 163 <artifactId>spring-jms</artifactId> 164 <version>${spring.version}</version> 165 </dependency> 166 <dependency> 167 <groupId>org.springframework</groupId> 168 <artifactId>spring-context-support</artifactId> 169 <version>${spring.version}</version> 170 </dependency> 171 <!-- JSP相关 --> 172 <dependency> 173 <groupId>jstl</groupId> 174 <artifactId>jstl</artifactId> 175 <version>${jstl.version}</version> 176 </dependency> 177 <dependency> 178 <groupId>javax.servlet</groupId> 179 <artifactId>servlet-api</artifactId> 180 <version>${servlet-api.version}</version> 181 <scope>provided</scope> 182 </dependency> 183 <dependency> 184 <groupId>javax.servlet</groupId> 185 <artifactId>jsp-api</artifactId> 186 <version>${jsp-api.version}</version> 187 <scope>provided</scope> 188 </dependency> 189 <!-- 文件上传组件 --> 190 <dependency> 191 <groupId>commons-fileupload</groupId> 192 <artifactId>commons-fileupload</artifactId> 193 <version>${commons-fileupload.version}</version> 194 </dependency> 195 <!-- Redis客户端 --> 196 <dependency> 197 <groupId>redis.clients</groupId> 198 <artifactId>jedis</artifactId> 199 <version>${jedis.version}</version> 200 </dependency> 201 <!-- solr客户端 --> 202 <dependency> 203 <groupId>org.apache.solr</groupId> 204 <artifactId>solr-solrj</artifactId> 205 <version>${solrj.version}</version> 206 </dependency> 207 <!-- dubbo相关 --> 208 <dependency> 209 <groupId>com.alibaba</groupId> 210 <artifactId>dubbo</artifactId> 211 <version>${dubbo.version}</version> 212 </dependency> 213 <dependency> 214 <groupId>org.apache.zookeeper</groupId> 215 <artifactId>zookeeper</artifactId> 216 <version>${zookeeper.version}</version> 217 </dependency> 218 <dependency> 219 <groupId>com.github.sgroschupf</groupId> 220 <artifactId>zkclient</artifactId> 221 <version>${zkclient.version}</version> 222 </dependency> 223 <dependency> 224 <groupId>org.apache.activemq</groupId> 225 <artifactId>activemq-all</artifactId> 226 <version>${activemq.version}</version> 227 </dependency> 228 <dependency> 229 <groupId>org.freemarker</groupId> 230 <artifactId>freemarker</artifactId> 231 <version>${freemarker.version}</version> 232 </dependency> 233 234 </dependencies> 235 </dependencyManagement> 236 237 <build> 238 <finalName>${project.artifactId}</finalName> 239 240 <plugins> 241 <!-- 资源文件拷贝插件 --> 242 <!-- <plugin> 243 <groupId>org.apache.maven.plugins</groupId> 244 <artifactId>maven-resources-plugin</artifactId> 245 <version>2.7</version> 246 <configuration> 247 <encoding>UTF-8</encoding> 248 </configuration> 249 </plugin>--> 250 <!-- java编译插件 --> 251 <plugin> 252 <groupId>org.apache.maven.plugins</groupId> 253 <artifactId>maven-compiler-plugin</artifactId> 254 <version>3.2</version> 255 <configuration> 256 <source>1.7</source> 257 <target>1.7</target> 258 <encoding>UTF-8</encoding> 259 </configuration> 260 </plugin> 261 </plugins> 262 <!-- <pluginManagement> 263 <plugins> 264 <!– 配置Tomcat插件 –> 265 <plugin> 266 <groupId>org.apache.tomcat.maven</groupId> 267 <artifactId>tomcat7-maven-plugin</artifactId> 268 <version>2.2</version> 269 </plugin> 270 </plugins> 271 </pluginManagement>--> 272 </build> 273 274 275 </project>
创建需要发布的接口:
floor-Service :暴露接口:
接口暴露 配置文件:
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:context="http://www.springframework.org/schema/context" 4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 5 xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" 6 xsi:schemaLocation="http://www.springframework.org/schema/beans 7 http://www.springframework.org/schema/beans/spring-beans-4.2.xsd 8 http://www.springframework.org/schema/context 9 http://www.springframework.org/schema/context/spring-context-4.2.xsd 10 http://code.alibabatech.com/schema/dubbo 11 http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> 12 13 <!-- 配置包扫描器 --> 14 <context:component-scan base-package="com.wfd360.service"/> 15 <!-- 使用dubbo发布服务 --> 16 <!-- 提供方应用信息,用于计算依赖关系 --> 17 <dubbo:application name="floor-manager"/> 18 <dubbo:registry protocol="zookeeper" 19 address="127.0.0.1:2181"/> 20 <!-- 用dubbo协议在20880端口暴露服务 --> 21 <dubbo:protocol name="dubbo" port="20880"/> 22 <!-- 声明需要暴露的服务接口 --> 23 <dubbo:service interface="com.wfd360.service.ItemService" ref="itemServiceImpl" timeout="600000"/> 24 <dubbo:service interface="com.wfd360.service.ItemCatService" ref="itemCatServiceImpl" timeout="600000"/> 25 </beans>
floor-web :消费者调用被暴露的接口:
pom。xml配置:
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <parent> 6 <artifactId>floor-parent</artifactId> 7 <groupId>com.wfd360.com</groupId> 8 <version>1.0-SNAPSHOT</version> 9 </parent> 10 <modelVersion>4.0.0</modelVersion> 11 <packaging>war</packaging> 12 <artifactId>floor-web</artifactId> 13 <dependencies> 14 <dependency> 15 <groupId>com.wfd360.com</groupId> 16 <artifactId>floor-interface</artifactId> 17 <version>1.0-SNAPSHOT</version> 18 </dependency> 19 <!-- Spring --> 20 <dependency> 21 <groupId>org.springframework</groupId> 22 <artifactId>spring-context</artifactId> 23 </dependency> 24 <dependency> 25 <groupId>org.springframework</groupId> 26 <artifactId>spring-beans</artifactId> 27 </dependency> 28 <dependency> 29 <groupId>org.springframework</groupId> 30 <artifactId>spring-webmvc</artifactId> 31 </dependency> 32 <dependency> 33 <groupId>org.springframework</groupId> 34 <artifactId>spring-jdbc</artifactId> 35 </dependency> 36 <dependency> 37 <groupId>org.springframework</groupId> 38 <artifactId>spring-aspects</artifactId> 39 </dependency> 40 <dependency> 41 <groupId>org.springframework</groupId> 42 <artifactId>spring-jms</artifactId> 43 </dependency> 44 <dependency> 45 <groupId>org.springframework</groupId> 46 <artifactId>spring-context-support</artifactId> 47 </dependency> 48 <!-- JSP相关 --> 49 <dependency> 50 <groupId>jstl</groupId> 51 <artifactId>jstl</artifactId> 52 </dependency> 53 <dependency> 54 <groupId>javax.servlet</groupId> 55 <artifactId>servlet-api</artifactId> 56 <scope>provided</scope> 57 </dependency> 58 <dependency> 59 <groupId>javax.servlet</groupId> 60 <artifactId>jsp-api</artifactId> 61 <scope>provided</scope> 62 </dependency> 63 64 <!-- dubbo相关 --> 65 <dependency> 66 <groupId>com.alibaba</groupId> 67 <artifactId>dubbo</artifactId> 68 <exclusions> 69 <exclusion> 70 <groupId>org.springframework</groupId> 71 <artifactId>spring</artifactId> 72 </exclusion> 73 <exclusion> 74 <groupId>org.jboss.netty</groupId> 75 <artifactId>netty</artifactId> 76 </exclusion> 77 </exclusions> 78 </dependency> 79 <dependency> 80 <groupId>org.apache.zookeeper</groupId> 81 <artifactId>zookeeper</artifactId> 82 </dependency> 83 <dependency> 84 <groupId>com.github.sgroschupf</groupId> 85 <artifactId>zkclient</artifactId> 86 </dependency> 87 88 </dependencies> 89 90 </project>
spring -mvc 配置:
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" 4 xmlns:context="http://www.springframework.org/schema/context" 5 xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" 6 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd 7 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd 8 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> 9 10 <context:component-scan base-package="com.wfd360.controller" /> 11 <mvc:annotation-driven /> 12 <bean 13 class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 14 <property name="prefix" value="/WEB-INF/jsp/" /> 15 <property name="suffix" value=".jsp" /> 16 </bean> 17 <!--本地静态文件--> 18 <mvc:resources mapping="/css/**" location="/css/"/> 19 <mvc:resources mapping="/js/**" location="/js/"/> 20 21 <!-- 引用dubbo服务 --> 22 <dubbo:application name="floor-web"/> 23 <dubbo:registry protocol="zookeeper" address="192.168.139.128:2181"/> 24 <dubbo:reference interface="com.wfd360.service.ItemService" id="itemService" /> 25 <dubbo:reference interface="com.wfd360.service.ItemCatService" id="itemCatService" /> 26 </beans>
注意:服务的发布和消费都需要保证zookeeper处于开启的状态。
标签:provider activemq ota 工具 机器 ima address control jdb
原文地址:https://www.cnblogs.com/dw3306/p/9539626.html