基于 Zookeeper、Dubbo 构建互联网分布式基础架构(2)|学习笔记

简介: 快速学习基于 Zookeeper、Dubbo 构建互联网分布式基础架构(2)

开发者学堂课程【基于 Zookeeper、Dubbo 构建互联网分布式基础架构互联网基础架构演进(3)】学习笔记,与课程紧密联系,让用户快速学习知识。

课程地址:https://developer.aliyun.com/learning/course/635/detail/10163


基于 Zookeeper、Dubbo 构建互联网分布式基础架构(2)

 

目录:

一. TestService

二. testweb

三. Testcontroller

四. Testserviceimpl

五. Apllicationcontext.xml

六. web 配置文件

七. 引入 dubbo

 

一.testService

Create by jackiechan on 2018/3/21/下午8:21

Publice interface testservice

此方法在此处没有任何意义,纯粹是为了演示拆分

@param name

@return

String getdata(string name);

注:做 controller 时一定需要 testservice 但在输入时却发现没有,原因是因为没有依赖,依赖要在本地仓库里寻找如果没有则再远程服务包寻找。

将 service 添加为依赖首先要放在本地仓库数据包里,添加成功后进行查看

 

二、testweb 包

xsi:schemaLocat ion="http://maven.apache.org/P0H/4.0.0http:maven,apache.org/maven-v4_0_0

<parent><artifac tId>testduboodemo</artifactId

<groupId>com.qianfeng</groupId>

<version>1.0</version>

</parent>

<modelVersion>4.0.0</modelVersion>

<artifactId>testweb</artifactId>

<name>testweb</name>

<urbhttp://maven.apache.org</url

<packaging>war</packaging>

<dependencies>

<dependency>

<groupId>junit</groupId>

<artifactId>junit</artifactId

<version>4.12</version>

<scope>test</scope>

</dependency>

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>javax.servlet-api</artifactId>

<version>3.1.0</version>

cscope>provided</scope»

</dependency>

</dependencies>

 

三.testcontroller

import com.qianfeng.testduboo.TestService;

import org.springframework,web.bind.annotation.RequestMapping;

import org.springframework,wcb.bind.annotation.Restcontroller;
import javax,annotation,Resource;
Created by jackiechan on 2018/3/21/下午8:16
@RestController
public class TestController
//这里声明一个service,service最终会变成一个 web 项目,也就是无法直接依赖,此处仍然需要声明对象.

//解决方式,我们将 service 的接口声明和实现进行拆分,将 service 创建为一个项目,jar包格式的项目.

//会用到service项目,serviceimpl 实现中也用到了这个接口
@Resource
private TestService service;
@Reques tMapping("/getData")
public string getData(String name)
string data = service.getData(name);
return


四.testserviceimpl

import com.qianfeng.testduboo.TestService;

import org.spring framework.stereotype.Service;

@Service("testServiceImpl")

public class TestServiceImplt implements TestService

@override
public string getData(String name )
return "你传递的数据是"+name ;

 

五.Apllicationcontext.xml

<?xml version-"1.0"encoding="UTF-8"7>

<beansxmlns="http://www,springframework,org/schema/beans"

xmlns:xsi-"http://www.w3,org/2001/XMLSchema-instance"

xmlns:aop="http:(www.springframework.org/schema/aop"

xm Lns:dubbo-"http://code.alibabatech.com/schema/dubbo"

xmlns:context="http://www.springframework.org/schema/context"

xsi:schemaLocation-"

<!扫描注解-->

<context:component-scanbase-package ="com,gianfeng"/>
<!--使用dubbo的另外一个原因,可以和spring无缝整合-->
<!--目的:
找到注册中心,告诉它我是谁,我的端口是多少
<!--配置别名,目的是在后台可以看到这个服务的别名,好区分到底是谁,这个参数可以随便写,但是最好是通俗易懂-->dubbo:application name="test1"/>
<!--2配置注册中心
address 注册中心的地址,protocol 指的是注册中心的协议格式<dubbo:registry.address="192.168.3.224:2181" .protocol="zookeeper"/>

interface 代表的就是类型
ref代表的就是到底具体发布哪个服务 timeout 连接超时时间
<dubbo:service interface="com.gianfeng.testduboo.TestService"ref="* imeoute"6000" />

</beans>


六.web 配置文件

<web-app xmlns-"http://xmlns.jcp.org/xml/ns/javaee"

xmlns:xsi="http:1/www3.org/2001/XMLSchema-instance"

xSi:schemaLocation-"http://xmlns.jcp.org/xml/ns/javaee

http://xmlns.jcp.org/xml/ns/javaee/web-app_31.xsd"

version-"3.1"

metadata-complete-"true",

<context-param>

<param-name>contextConfigLocaton</param-name>

<param-value>claspath:ApplicationContext.xml</param-value>

</context-param>

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener

</web-app>

 

七.引入 dubbo

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.9</version>
<exclusions>
<exclusion>
<groupId>org,springframework</groupId»<artifactId>spring</artifactId>
</exclusion>

相关文章
|
10月前
|
人工智能 Java Nacos
基于 Spring AI Alibaba + Nacos 的分布式 Multi-Agent 构建指南
本文将针对 Spring AI Alibaba + Nacos 的分布式多智能体构建方案展开介绍,同时结合 Demo 说明快速开发方法与实际效果。
5577 112
|
11月前
|
存储 Kubernetes 微服务
Dapr:用于构建分布式应用程序的便携式事件驱动运行时
Dapr 是一个可移植、事件驱动的运行时,简化了分布式应用程序的开发。它支持多语言、多框架,适用于云和边缘计算环境,提供服务调用、状态管理、消息发布/订阅等构建模块。通过 sidecar 模式,Dapr 帮助开发者轻松应对微服务架构的复杂性,实现弹性、可扩展的应用部署。
635 9
Dapr:用于构建分布式应用程序的便携式事件驱动运行时
|
监控 Java API
Spring Boot 3.2 结合 Spring Cloud 微服务架构实操指南 现代分布式应用系统构建实战教程
Spring Boot 3.2 + Spring Cloud 2023.0 微服务架构实践摘要 本文基于Spring Boot 3.2.5和Spring Cloud 2023.0.1最新稳定版本,演示现代微服务架构的构建过程。主要内容包括: 技术栈选择:采用Spring Cloud Netflix Eureka 4.1.0作为服务注册中心,Resilience4j 2.1.0替代Hystrix实现熔断机制,配合OpenFeign和Gateway等组件。 核心实操步骤: 搭建Eureka注册中心服务 构建商品
1542 3
|
10月前
|
负载均衡 Java API
《深入理解Spring》Spring Cloud 构建分布式系统的微服务全家桶
Spring Cloud为微服务架构提供一站式解决方案,涵盖服务注册、配置管理、负载均衡、熔断限流等核心功能,助力开发者构建高可用、易扩展的分布式系统,并持续向云原生演进。
|
11月前
|
消息中间件 缓存 监控
中间件架构设计与实践:构建高性能分布式系统的核心基石
摘要 本文系统探讨了中间件技术及其在分布式系统中的核心价值。作者首先定义了中间件作为连接系统组件的&quot;神经网络&quot;,强调其在数据传输、系统稳定性和扩展性中的关键作用。随后详细分类了中间件体系,包括通信中间件(如RabbitMQ/Kafka)、数据中间件(如Redis/MyCAT)等类型。文章重点剖析了消息中间件的实现机制,通过Spring Boot代码示例展示了消息生产者的完整实现,涵盖消息ID生成、持久化、批量发送及重试机制等关键技术点。最后,作者指出中间件架构设计对系统性能的决定性影响,
|
12月前
|
数据采集 存储 NoSQL
Scrapy 框架实战:构建高效的快看漫画分布式爬虫
Scrapy 框架实战:构建高效的快看漫画分布式爬虫
|
消息中间件 分布式计算 并行计算
Python 高级编程与实战:构建分布式系统
本文深入探讨了 Python 中的分布式系统,介绍了 ZeroMQ、Celery 和 Dask 等工具的使用方法,并通过实战项目帮助读者掌握这些技术。ZeroMQ 是高性能异步消息库,支持多种通信模式;Celery 是分布式任务队列,支持异步任务执行;Dask 是并行计算库,适用于大规模数据处理。文章结合具体代码示例,帮助读者理解如何使用这些工具构建分布式系统。
|
存储 运维 负载均衡
构建高可用性GraphRAG系统:分布式部署与容错机制
【10月更文挑战第28天】作为一名数据科学家和系统架构师,我在构建和维护大规模分布式系统方面有着丰富的经验。最近,我负责了一个基于GraphRAG(Graph Retrieval-Augmented Generation)模型的项目,该模型用于构建一个高可用性的问答系统。在这个过程中,我深刻体会到分布式部署和容错机制的重要性。本文将详细介绍如何在生产环境中构建一个高可用性的GraphRAG系统,包括分布式部署方案、负载均衡、故障检测与恢复机制等方面的内容。
930 4
构建高可用性GraphRAG系统:分布式部署与容错机制
|
人工智能 安全 Java
微服务引擎 MSE:打造通用的企业级微服务架构
微服务引擎MSE致力于打造通用的企业级微服务架构,涵盖四大核心内容:微服务技术趋势与挑战、MSE应对方案、拥抱开源及最佳实践。MSE通过流量入口、内部流量管理、服务治理等模块,提供高可用、跨语言支持和性能优化。此外,MSE坚持开放,推动云原生与AI融合,助力企业实现无缝迁移和高效运维。
845 1