springcloud(九) 消息总线(Spring Cloud Bus)

SpringCloud之Bus消息总线 目录`bus` 简介`bus` 工作架构 bus 简介 从 上一篇 文章可以得知 config client 服务从 config server 端获取自己对应的配置文件,但是目前的问题是:当远程 git 仓库配置文件发生改变时,每次都是需要重启 config client 服务,如果有上百上千个微服务呢? 我想我们不会一个个去重启每个微服务,也就是说如何让 config server 端通知到 config client 端? 即 config client 端如何感知到配置发生更新? 这时候就该 bus 阅读详情

转载请标明出处: 
http://blog.youkuaiyun.com/forezp/article/details/70148235 
本文出自方志朋的博客

转载请标明出处:

Spring Cloud Bus 将分布式的节点用轻量的消息代理连接起来。它可以用于广播配置文件的更改或者服务之间的通讯,也可以用于监控。本文要讲述的是用Spring Cloud Bus实现通知微服务架构的配置文件的更改。

一、准备工作

本文还是基于上一篇文章来实现。按照官方文档,我们只需要在配置文件中配置 spring-cloud-starter-bus-amqp ;这就是说我们需要装rabbitMq,点击rabbitmq下载。至于怎么使用 rabbitmq,搜索引擎下。

二、改造config-client

在pom文件加上起步依赖spring-cloud-starter-bus-amqp,完整的配置文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.forezp</groupId>
    <artifactId>config-client</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>config-client</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.retry</groupId>
            <artifactId>spring-retry</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>


        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bus-amqp</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Dalston.RC1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>


</project>

  • 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
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103

在配置文件application.properties中加上RabbitMq的配置,包括RabbitMq的地址、端口,用户名、密码,代码如下:


spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
# spring.rabbitmq.username=
# spring.rabbitmq.password=
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

如果rabbitmq有用户名密码,输入即可。

依次启动eureka-server、confg-cserver,启动两个config-client,端口为:8881、8882。

访问http://localhost:8881/hi 或者http://localhost:8882/hi 浏览器显示:

foo version 3

这时我们去代码仓库将foo的值改为“foo version 4”,即改变配置文件foo的值。如果是传统的做法,需要重启服务,才能达到配置文件的更新。此时,我们只需要发送post请求:http://localhost:8881/bus/refresh,你会发现config-client会重新读取配置文件

Paste_Image.png

重新读取配置文件:

Paste_Image.png

这时我们再访问http://localhost:8881/hi 或者http://localhost:8882/hi 浏览器显示:

foo version 4

另外,/bus/refresh接口可以指定服务,即使用”destination”参数,比如 “/bus/refresh?destination=customers:**” 即刷新服务名为customers的所有服务,不管ip。

三、分析

此时的架构图: 
Paste_Image.png

当git文件更改的时候,通过pc端用post 向端口为8882的config-client发送请求/bus/refresh/;此时8882端口会发送一个消息,由消息总线向其他服务传递,从而使整个微服务集群都达到更新配置文件。

四、其他扩展(可忽视)

可以用作自定义的Message Broker,只需要spring-cloud-starter-bus-amqp, 然后再配置文件写上配置即可,同上。

Tracing Bus Events: 
需要设置:spring.cloud.bus.trace.enabled=true,如果那样做的话,那么Spring Boot TraceRepository(如果存在)将显示每个服务实例发送的所有事件和所有的ack,比如:(来自官网)

{
  "timestamp": "2015-11-26T10:24:44.411+0000",
  "info": {
    "signal": "spring.cloud.bus.ack",
    "type": "RefreshRemoteApplicationEvent",
    "id": "c4d374b7-58ea-4928-a312-31984def293b",
    "origin": "stores:8081",
    "destination": "*:**"
  }
  },
  {
  "timestamp": "2015-11-26T10:24:41.864+0000",
  "info": {
    "signal": "spring.cloud.bus.sent",
    "type": "RefreshRemoteApplicationEvent",
    "id": "c4d374b7-58ea-4928-a312-31984def293b",
    "origin": "customers:9000",
    "destination": "*:**"
  }
  },
  {
  "timestamp": "2015-11-26T10:24:41.862+0000",
  "info": {
    "signal": "spring.cloud.bus.ack",
    "type": "RefreshRemoteApplicationEvent",
    "id": "c4d374b7-58ea-4928-a312-31984def293b",
    "origin": "customers:9000",
    "destination": "*:**"
  }
}
  • 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

本文源码下载: 
https://github.com/forezp/SpringCloudLearning/tree/master/chapter8

Spring Cloud中的 Bus 消息总线知识点全面解析 在微服务架构中,配置动态刷新、服务状态监控等功能的实现往往需要在多个服务实例间进行通信。Spring Cloud Bus 应运而生,它通过轻量级消息代理链接各个微服务实例,实现配置信息的广播、服务状态变更通知等功能。本文将详细梳理 Spring Cloud Bus 的核心知识点,助力开发者更好地掌握和运用这一利器。 阅读详情

相关推荐

史上最简单的SpringCloud教程 | 第八篇: 消息总线(Spring Cloud Bus)

版权声明:本文为博主原创文章,欢迎转载,转载请注明作者、原文超链接 ,博主地址:http://blog.csdn.net/forezp。目录(?)[+]转载请标明出处: http://blog.csdn.net/forezp/article/details/70148235 本文出自方志朋的博客转载请标明出处:spring Cloud Bus 将分布式的节点用轻量的消息代理连接起来。它可以用于广播

霍力强的专栏 1016

spring cloud bus的使用及使用bus发布自定义事件

1. spring cloud bus介绍 Spring cloud bus使用轻量级消息代理将分布式系统的节点连接起来,可以使用此代理,广播状态更改(例如配置更改)或其他管理指令。它可以用作应用程序之间的通信通道。该项目提供了两种消息传输处理:AMQP broker和Kafka 2. 如果你想使用activemq或其他的消息中间件作为消息传输,那么需要实现spring cloud strea...

weixin_38312502的博客 3745

文华财经公式编程:麦语言简介及基础语法

文华财经公式语言(麦语言)是一种专门用于金融领域的编程语言,它是由文华财经公司开发的。提供了丰富的金融计算函数和数据处理功能,可以用于金融市场的数据分析、模型建立和交易策略的开发。例1:A:CLOSE;// 定义变量A为收盘价(盘中k线没有走完的时候A为最新价)。例2:MA5:=MA(C,5);// 定义收盘价的5周期均线(C为CLOSE简写)。例3:A:=REF(C,1);// 取得前一根k线的收盘价。

超哥量化的博客 1万+

SpringCloud-Alibaba消息总线Bus(过时)

此文章主要讲解springcloud中的消息总线Bus(不推荐)的相关知识。 Spring Cloud Bus Spring Cloud Bus是什么? Spring Cloud Bus配置Spring Cloud Config使用可以实现配置的动态刷新。 Spring Cloud Bus是用来分布式系统的节点和轻量级消息系统连接起来的框架,它整合了Java事件处理机制和消息中间件的功能。 Spring Cloud Bus目前支持RabbitMQ和Kafka。 Spring Cloud B

qq_43144261的博客 1345

智能检查点优化:动态频率与差异化存储的断点续训实践(模型训练丨容错机制丨人工智能)

本文深入探讨了大规模模型训练中智能检查点优化的核心实践。针对传统固定频率保存导致的存储浪费与恢复缓慢问题,提出了基于损失变化率的动态频率算法与分层差异化存储策略。通过PyTorch代码示例,详细展示了如何实现动态调度与增量保存,有效降低存储成本,并确保训练中断后能快速、可靠地恢复,显著提升训练任务的容错能力与经济效益。

weixin_29072299的博客 333

《QGIS快速入门与应用基础》161:面要素顶点编辑与形状调整

本文系统讲解了QGIS中面要素顶点编辑与形状调整的核心操作。首先明确了顶点编辑的适用场景与核心概念,强调需满足图层类型、编辑模式、要素选择等六大前提。详细介绍了编辑顶点工具(F2键)的激活路径及配套辅助工具,通过耕地地块修正案例,分步骤演示顶点移动、添加(双击/工具栏)、删除(Delete键)三大基础操作。同时提供捕捉工具开启、画布缩放等实用技巧,帮助用户高效完成面要素的精细化调整,解决实际工作中的形状偏差问题。全文图文结合,步骤清晰,适合GIS新手快速掌握面要素编辑的核心技能。

LuckyHanMo的博客 480

SpringCloud09—消息总线:Spring Cloud Bus

9.消息总线:Spring Cloud Bus 在微服务架构的系统中,我们通常会使用轻量级的消息代理来构建一个共用的消息主题让系统中所有微服务实例都连接上来,由于该主题中产生的消息会被所有实例监听和消费,所以我们称它为消息总线。在总线上的各个实例都可以方便地广播一些需要让其他连接在该主题上的实例都知道的消息,例如配置信息的变更或者其他一些管理操作等。 由于消息总线在微服务架构系统中被广泛使用,所以它同配置中心一样,几乎是微服务架构中的必备组件。Spring Cloud作为微服务架构综合性的解决方案,对此自然

zhiyikeji的博客 1195

零基础实战:云开发家政维修小程序搭建指南

欢迎来到这本关于构建家政维修小程序的电子书!在当今数字化的浪潮中,线上服务已成为我们生活中不可或缺的一部分。从点餐购物到居家维修,人们越来越习惯通过指尖轻点来解决各种需求。正是基于这样的背景,我们希望通过这个系列,手把手地带领大家从零开始,搭建一个功能完备、体验流畅的家政维修平台。这不仅仅是一本技术教程,更是一次将想法变为现实的探索之旅。我们将深入浅出地讲解如何运用云开发等现代技术,实现从用户下单、支付,到客服派单、工人接单,再到订单完成和权限管理等一系列核心业务流程。

低代码布道师的博客 3431

2024年Spring Cloud入门-Bus消息总线(Hoxton版本)(1),阿里大牛把「服务雪崩」玩到了极致

互联网大厂比较喜欢的人才特点:对技术有热情,强硬的技术基础实力;主动,善于团队协作,善于总结思考。无论是哪家公司,都很重视高并发高可用技术,重视基础,所以千万别小看任何知识。面试是一个双向选择的过程,不要抱着畏惧的心态去面试,不利于自己的发挥。同时看中的应该不止薪资,还要看你是不是真的喜欢这家公司,是不是能真的得到锻炼。其实我写了这么多,只是我自己的总结,并不一定适用于所有人,相信经过一些面试,大家都会有这些感触。下面有部分截图希望能对大家有所帮助。本文已被。

2401_84103216的博客 906

YOLOv9改进策略【损失函数篇】| Slide Loss,解决简单样本和困难样本之间的不平衡问题

本文记录的是改进YOLOv9的损失函数,将其替换成Slide Loss,并详细说明了优化原因,注意事项等。Slide Loss函数可以有效地解决样本不平衡问题,为困难样本赋予更高的权重,使模型在训练过程中更加关注困难样本。若是在自己的数据集中发现容易样本的数量非常大,而困难样本相对稀疏,可尝试使用Slide Loss来提高模型在处理复杂样本时的性能。

Limiiiing的博客 2596

【VMware】win 10:VMware 15 虚拟机安装 win 7 系统

目录 一、准备虚拟机 二、win7 ghost ISO镜像文件下载 三、VMware新建虚拟机 四、VMware安装win7 五、解决vmware虚拟机屏幕没有适应窗口全屏问题 一、准备虚拟机 查看我的另一博文:【VMware】VMware Workstation Pro15 虚拟机永久激活破解安装教程 二、win7 ghost ISO镜像文件下载 百度网盘下载地址:点击前往下载...

顾三殇 —— 博客空间(软件测试) 11万+

从零学SpringCloud系列(九):利用kafka实现消息总线Spring Cloud Bus

一、什么是消息总线 相信大多数读者之前都使用过各种各样的消息队列,例如RabbitMQ、kafka等等,消息总线和他的概念差不多,在微服务系统的架构中,我们通常会使用轻量级的消息代理来 构建一个共用的消息主题让系统中所有的微服务都连接上来,由于该主题中产生的消息会被所有实例监听和消费,所以 我们称他们为消息总线。在总线上的各个实例都可以方便的广播一些需要让其他连接到该主题上的实例都知道的消息,例如配置的变更或者其他一些管理操作等。 二、 ...

Jack 架构师之路 1万+

Windows 11 安装 JDK 11:下载、安装、配置环境变量、验证

本文详细介绍了在 Windows 11 系统中安装 JDK 11 的完整流程,包括从 Oracle 官网下载压缩包、解压到自定义目录、配置 JAVA_HOME 与 Path 环境变量,并验证安装是否成功。文章还包含一个专为 JDK 11 新特性设计的测试程序,涵盖 Lambda 表达式 var 语法、HTTP 客户端 API、字符串增强方法等,帮助读者确认安装版本正确无误,适合初学者和需要多版本 JDK 共存的开发者参考。

寒水馨 · 轻量级技术文档 · hanshuixin.org 2779

SpringCloud微服务知识整理九:消息总线:Spring Cloud Bus

什么是Spring Cloud Bus 在微服务架构的系统中, 我们通常会使用轻量级的消息代理来构建一个共用的消息主题让系统中所有微服务实例都连接上来, 由于该主题中产生的消息会被所有实例监听和消费, 所以我们称它为消息总线。 在总线上的各个实例都可以方便地广播一些需要让其他连接在该主题上的实例都知道的消息, 例如配置信息的变更或者其他一些管理操作等。 通过使用 Spring Cloud Bus ...

sueven0104的博客 701

SAP RAP学习系列合集介绍

《SAP RAP学习系列合集:从入门到部署的完整指南》摘要: 本文介绍了作者创建的SAP RAP学习系列合集,涵盖RAP开发从基础概念到实战部署的全流程。系列目前包含17篇文章,系统讲解了RAP核心开发技术:从数据建模、UI构建到行为定义(包括并发控制、草稿功能、授权验证等),最后详细演示了应用部署到Fiori Launchpad的两种方案(OP版和ES版)。

DeveloperMrMeng的博客 1490

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

Spring Cloud 2-Bus 消息总线(九)

Spring Cloud Bus 1.服务端配置 pom.xml application.yml 2.客户端配置 pom.xml application.yml Controller.java 3.自动刷新配置 服务架构 在分布式配置中,客户端获取远程最...

dgush2000的博客 156

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

spring cloud 入门系列九:Spring Cloud Bus刷新配置中心配置——消息总线RabbitMQ

在http://blog.csdn.net/a60782885/article/details/69415527的最后,我们提到了配置的刷新,但是这显然是麻烦的,如果多个服务使用了这个配置,当我们修改配置信息的时候,如果我们希望服务的配置也跟着修改,我们就不得不一个一个服务的发送POST请求,或者关闭服务重新打开。这是一件多麻烦的事情。 所以我们在这里使用消息中间件来完成配置的更新问题。   ...

CNZYYH的博客 573

深度学习工具包 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")

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

SpringCloud教程 | 第八篇: 消息总线(Spring Cloud Bus)(Finchley版本)

转载请标明出处: http://blog.csdn.net/forezp/article/details/81041062  本文出自方志朋的博客 转载请标明出处: Spring Cloud Bus 将分布式的节点用轻量的消息代理连接起来。它可以用于广播配置文件的更改或者服务之间的通讯,也可以用于监控。本文要讲述的是用Spring Cloud Bus实现通知微服务架构的配置文件的更改。 ...

移动互联网改变生活,高效配对交易创造财富 258

【spring cloud】(六)消息总线——springcloud Bus

各位小伙伴们大家好,欢迎来到这个小扎扎的spring cloud专栏,在这个系列专栏中我对B站尚硅谷阳哥的spring cloud教程进行一个总结,鉴于 看到就是学到、学到就是赚到 精神,这波依然是血赚 ┗|`O′|┛

扎哇太枣糕的笔记博客 2315

SpringCloud(九)配置中心和消息总线

Spring cloud bus通过轻量消息代理连接各个分布的节点。这会用在广播状态的变化(例如配置变化)或者其他的消息指令。Spring bus的一个核心思想是通过分布式的启动器对spring boot应用进行扩展,也可以用来建立一个多个应用之间的通信频道。目前唯一实现的方式是用AMQP消息代理作为通道,同样特性的设置(有些取决于通道的设置)在更多通道的文档中。Spring cloud bus被国内很多都翻译为消息总线,也挺形象的。

L08130421的博客 3113

干货|Spring Cloud Bus 消息总线介绍

继上一篇干货|Spring Cloud Stream 体系及原理介绍之后,本期我们来了解下 Spring Cloud 体系中的另外一个组件 Spring Cloud Bus (建议先熟悉 Spring Cloud Stream,不然无法理解 Spring Cloud Bus 内部的代码)。 Spring Cloud Bus对自己的定位是 Spring Cloud 体系内的消息总线,使用 m...

阿里云云栖号 2万+

SpringCloud Bus消息总线

在微服务架构的系统中,通常会使用轻量级的消息代理来构建一个共用的消息主题,并让系统中所有微服务实例都连接上来。由于该主题中产生的消息会被所有实例监听和消费,所以称它为消息总线。在总线上的各个实例,都可以方便地广播一些需要让其他连接在该主题上的实例都知道的消息。

我要记录学习博客 1747

Spring Cloud Bus消息总线

Spring Cloud Bus是用来将`分布式系统的节点 与 轻量级消息系统 链接起来的框架`。 注意:它不属于消息中间件,他是通过和消息中间件整合,来完成服务之间消息通讯,类似于消息代理。Spring Clud Bus目前支持RabbitMQ和Kafka。

怪咖@的博客 4161

消息总线(Spring Cloud Bus)

前言 Spring Cloud Bus是什么? Spring Cloud Bus 配合 Spring Cloud Config 使用可以实现配置的动态刷新。 Spring Cloud Bus是用来将分布式系统的节点与轻量级消息系统链接起来的框架, 它整合了Java的事件处理机制和消息中间件的功能。 Spring Clud Bus目前支持RabbitMQ和Kafka。 Spring Cloud Bus能干吗? Spring Cloud Bus能管理和传播分布式系统间的消息,就像一个分布式执行器,

Lifelong learning 7644

【SpringCloud】【Hoxton】Bus消息总线

1 Spring Cloud Bus 简介 Spring cloud bus通过轻量消息代理连接各个分布的节点。这会用在广播状态的变化(例如配置变化)或者其他的消息指令。Spring bus的一个核心思想是通过分布式的启动器对spring boot应用进行扩展,也可以用来建立一个多个应用之间的通信频道。目前唯一实现的方式是用AMQP消息代理作为通道,同样特性的设置(有些取决于通道的设置)在更多通道...

qq_34125999的博客 5573
上一篇: springcloud(八) 高可用的分布式配置中心(Spring Cloud Config)
下一篇: springcloud(十) 服务链路追踪(Spring Cloud Sleuth)
it_monkey_ali
博客等级 码龄10年 32粉丝 35原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值