完整微服务化示例:使用 Apache ServiceComb (incubating) 进行微服务开发、容器化、弹性伸缩

深入浅出微服务:40个微服务架构实战案例(Dubbo+Springcloud) 不知道各位大佬在实际开发过程中用的是哪一个工具(可以在评论区讨论),小编在开发时用的多的是Springcloud,并且咱们程序员在开发过程中碰到的许多问题如果没有周围大牛知道的话都是自己网上查资料,自行解决,属实有点苦逼。采用了Spring的配置方式。微服务在近几年来可以说是十分火爆,我们应该知道微服务的发展历程大致分为6个阶段分别是:单体应用阶段提、垂直应用阶段、分布式系统阶段、服务治理阶段、微服务阶段、最后到服务网格阶段。Spring Cloud在现阶段或未来较长时间内是最为稳妥的微服务的框架。 阅读详情
摘要: 最完整的微服务化示例,从业务场景入手,讲述微服务化架构设计、容器化、集群部署、弹性伸缩

本文转载自 微服务 开源项目 Apache ServiceComb (incubating) 官网博客:

http://servicecomb.incubator.apache.org/cn/docs/linuxcon-workshop-demo/

http://servicecomb.incubator.apache.org/cn/docs/company-on-kubernetes/

http://servicecomb.incubator.apache.org/cn/docs/autoscale-on-company/

 

微服务架构作为新兴领域的架构模式,已步入产品化形态,与容器化、集群等一起成为了当下热点。而微服务、Docker、kubernetes 之间的关系,究竟这三者之间是什么样的关系,分别能在微服务领域发挥什么作用,却常给入门的读者和用户带来些许迷茫感。

本文使用一个简单的普适性的 微服务 示例,从 业务场景入手,到微服务架构设计、实现、容器化、集群部署、压测、弹性伸缩、资源控制,端到端以最直白的方式演示了这三者的关系,会给读者带来不一样的真切的理念体验和感受,增强对系列概念的理解。

普适性微服务化示例

为了读者能更容易了解ServiceComb微服务框架的功能以及如何用其快速开发微服务,所以提供大家耳熟能详的例子,降低学习曲线的同时,增加趣味性,加深理解。

本文中假设我们成立了一家科研公司,处理复杂的数学运算,以及尖端生物科技研究,并为用户提供如下服务:

  • 黄金分割数列计算

  • 蜜蜂繁殖规律 (计算每只雄蜂/雌蜂的祖先数量)

但是我们如何将公司的这些强大运算能力提供给我们的消费者呢?

首先我们通过认证服务保障公司的计算资源没有被滥用, 同时我们对外提供Rest服务让用户来进行访问。 下面的视频展示具体的服务验证调用的情况。

 

业务场景

让我们先对业务场景进行总结分析

  1. 为了公司持续发展,我们需要对用户消费的运算能力收费,所以我们聘用了门卫认证用户,避免不法分子混入

  2. 为了提供足够的黄金分割数量运算能力,我们需要雇佣相应的技工

  3. 为了持续研究蜜蜂繁殖规律,公司建立了自己的蜂场,需要相应的养蜂人进行管理研究

  4. 为了平衡技工、养蜂人、和门卫的工作量和时间,我们建立了告示栏机制,让当前有闲暇的人员发布自己的联系方式,以便我们能及时联系技能匹配的人员以服务到来的用户

  5. 因为运算能力成本高昂,我们将运算项目进行了归档,以便未来有相同请求时,我们能直接查询项目归档,节省公司运算成本

  6. 面对上述复杂的场景,我们又聘用了部门经理来管理公司成员和设施

  7. 最后,当公司日益壮大,用户数量暴涨时,我们还需要招聘更多技工、养蜂人、和门卫,所以增加了人力资源部门

公司结构 (系统架构)

到现在业务场景已经比较清晰,我们把上述职务部门和设施画成公司组织结构图。

现在公司组织结构已经完整,让我们着手搭建相应部门。

技工 (Worker)

因为技工最为简单,对其他部门人员依赖最少,我们首先搭建这个部门。

黄金分割运算服务

技工的主要工作时提供黄金分割数列计算服务,当用户需要知道第n个黄金分割数时,技工以最快的速度计算出数值并返回给用户。 我们可以把这个工作简化为如下数学方程:

value = fibo(n)

在暂时不考虑性能的情况下,我们可以迅速实现黄金分割数列的计算。

interface FibonacciService {
  long term(int n);
}

@Service
class FibonacciServiceImpl implements FibonacciService {
  @Override
  public long term(int n) {
    if (n == 0) {
      return 0;
    } else if (n == 1) {
      return 1;
    }

    return term(n - 1) + term(n - 2);
  }
}

 

技工服务端点

黄金分割数量运算已经实现,现在我们需要将服务提供给用户,首先我们定义端点接口:

public interface FibonacciEndpoint {
  long term(int n);
}

 

引入 ServiceComb 依赖:

    <dependency>
      <groupId>org.apache.servicecomb</groupId>
      <artifactId>spring-boot-starter-provider</artifactId>
    </dependency>

 

接下来我们同时暴露黄金分割运算服务的Restful和RPC端点:

@RestSchema(schemaId = "fibonacciRestEndpoint")
@RequestMapping("/fibonacci")
@Controller
public class FibonacciRestEndpoint implements FibonacciEndpoint {

  private final FibonacciService fibonacciService;

  @Autowired
  FibonacciRestEndpoint(FibonacciService fibonacciService) {
    this.fibonacciService = fibonacciService;
  }

  @Override
  @RequestMapping(value = "/term", method = RequestMethod.GET)
  @ResponseBody
  public long term(int n) {
    return fibonacciService.term(n);
  }
}

 

@RpcSchema(schemaId = "fibonacciRpcEndpoint")
public class FibonacciRpcEndpoint implements FibonacciEndpoint {

  private final FibonacciService fibonacciService;

  @Autowired
  public FibonacciRpcEndpoint(FibonacciService fibonacciService) {
    this.fibonacciService = fibonacciService;
  }

  @Override
  public long term(int n) {
    return fibonacciService.term(n);
  }
}

 

这里用 @RestSchema 和 @RpcSchema 注释两个端点后,ServiceComb 会自动生成对应的服务端点契约,根据如下microsevice.yaml 配置端点端口,并将契约和服务一起注册到Service Center:

# all interconnected microservices must belong to an application wth the same ID
APPLICATION_ID: company
service_description:
# name of the declaring microservice
  name: worker
  version: 0.0.1
# service center address
cse:
  service:
    registry:
      address: http://sc.servicecomb.io:30100
  highway:
    address: 0.0.0.0:7070
  rest:
    address: 0.0.0.0:8080

 

最后,提供技工服务应用启动入口

CSE RPC流程分析 编码:RegistrationManager-》ServiceCenterRegistration-》RegistryUtils层层递进,结构清晰,SCBEngine中做统一的管理。在上面第4步中,由于cse core模块中定义了如下microservice.yaml,因此默认不使用filter-chains。1、首先执行hello.sayHi(“Java Chassis”)方法,会进入代理类的invoke方法中。最终rpc调用通过vertx实现的http请求发送给provider执行。 阅读详情

相关推荐

RPC方式开发ServiceComb应用程序

RPC方式开发ServiceComb应用程序 步骤: 框架结构:一个父工程,三个子模块(服务接口,服务提供者,服务消费者) 开发服务接口,安装服务接口到本地仓库 开发服务提供者,导入坐标 <!-- rpc通信模型--> <dependency> <groupId>org.apache.servicecomb</group...

qq_29319189的博客 2088

模型微服务化:构建模型服务的策略

我理解您的要求。让我为您撰写这篇技术博客文章吧。我会尽我所能提供一篇深入、结构清晰、内容丰富的文章,帮助读者全面地了解模型微服务化的核心概念、原理和最佳实践。我会努力用简洁明了的语言解释复杂的技术细节,并以代码示例和数学公式来辅助说明。同时,我也会提供实用的工具和资源推荐,以及对未来发展趋势和挑战的分析和见解。请放心,这篇博客文章一定会给您和读者带来实在的价值。让我们开始吧!

AI天才研究院 802

oracle rac 成本及架构,Oracle Extended RAC 架构实战

Extended-RAC,是RAC技术的一种扩展增强。Extended-RAC是通过专用光纤(或租用裸光纤)加DWDM(波分设备)设备将两个不同楼栋/同城甚至异地机房进行相连,将数据库主机、存储分别放置于不同机房,利用存储复制/ASM Mirror等技术进行数据复制进行搭建的一种远距离集群架构。Extended RAC需要将不同楼栋/同城甚至异地机房通过专用光纤(或租用裸光纤)加DWDM(光纤复用...

weixin_33812391的博客 2454

ContextCapture、EPS、CASS3D房地一体详细操作流程

还是房地一体的作业流程,这次我们整合了ContextCapture操作流程部分以及EPS和CASS3D三维采集绘制房屋及地形。结合房地一体项目全流程来分享新技术带来的便利。 第一步还是前期资料准备,这里不多赘述,可以参考之前的文章→ 房地一体工作浅谈(一)——资料准备 房地一体工作浅谈(二)——外业工作 关于外业及内业处理部分可参考我们之前的文章:无人机航测从外业作业到内业处理,我们有一整套实战教程!(精灵4RTK外业部分) 下面是我们整合的ContextCapture、EPS、CASS3D三个软件的操作.

qq_43173805的博客 1万+

Avellaneda & Stoikov’s market-making strategy 工程化处理

前2篇文章详细介绍了AS存货模型的做市策略,这次对于这些公式里面一些希腊字母的取值是如何计算的,如何做工程化并应用到生产环境中做一些说明。这个里面有一些重要参数:很直观,可以直接取值的有:s = current market mid price (中间价,也就是【最佳卖价+最佳买价】/2)q = quantity of assets in inventory of base asset (也就是买入多少价值的股票数量)

weixin_42480337的博客 7073

从零构建物联网监控系统:STM32+迪文屏+WiFi模组的实战解析

本文详细解析了基于STM32微控制器、迪文串口屏和WiFi模组构建物联网监控系统的完整方案。从硬件选型、系统架构设计到数据交互实现,提供了包括迪文屏GUI开发、STM32通信协议、低功耗优化等实战经验,帮助开发者快速掌握物联网监控系统的核心技术。

docker7nomad的博客 731

【SMPL简介】SMPL: A Skinned Multi-Person Linear Model【源码复现】

SMPL是一种3D人体建模方法.在数字人或者人物角色三维重建领域有着广泛应用支持人体的各种形状及动作可以简单理解为通过训练获取的人物模型SMPL 输入是:姿态shape vectorβ\betaβ+ 影响动作Pose的参数θ\thetaθ输出是: 各种变化后vertex顶点的数据作者:Loper, Matthew and Mahmood, Naureen and Romero, Javier and Pons-Moll, Gerard and Black, Michael J.

zik的博客 3370

dify进阶:使用 FastAPI 的 StreamingResponse 实现高效的数据流传输

在 FastAPI 框架中,是一个非常有用的工具,它允许你以流的方式发送数据给客户端,而不是一次性加载所有内容到内存中再发送。这对于处理大型文件下载、视频流或者任何需要长时间处理的任务特别有用。

xiezhipu的博客 1435

调用魔搭API出现Please bind your Alibaba Cloud account before use的解决方案

本文主要介绍了调用魔搭API出现Please bind your Alibaba Cloud account before use解决方案,希望能对使用大模型的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 3万+

【华为OD技术面试手撕真题】1、长度最小的子数组 | 手撕真题+思路参考+代码解析(C & C++ & Java & Python & JS)(三种解法)

【华为OD面试手撕真题】长度最小的子数组,本专栏更新每年华为OD机试的高频手撕代码题,每个题目都会使用五种语言进行解答(C & C++& Java & Python & JS),思路分析都非常详细, 实现最低的时间复杂度和高通过率,每个解题思路超过百字,内含各个编程语言的八股文面试题,欢迎大家订阅学习, 代码可以直接运行使用,全网限时最低价,持续更新

KJ.JK 1万+

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

下一篇: 如何加入Apache开源社区:Apache ServiceComb (incubating) 微服务开源项目实例讲解
微服务ServiceComb社区
博客等级 码龄9年 97粉丝 28原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值