计算机由硬件系统和软件系统组成,其中硬件系统是计算机的物理基础,主要包括以下主要部件:
1. 中央处理器(CPU)
- 功能:是计算机的核心部件,负责执行程序指令,进行算术运算和逻辑运算,控制计算机的运行。
- 性能指标
- 主频(GHz):CPU的时钟频率,表示CPU每秒的振荡次数。主频越高,CPU的运算速度越快。例如,3.5GHz的CPU比2.5GHz的CPU在时钟频率上更快。
- 核心数和线程数:核心数表示CPU内部的独立处理器单元数量,线程数表示CPU可以同时处理的任务数量。多核心多线程的CPU可以提高多任务处理能力。例如,一个4核心8线程的CPU可以同时处理8个任务。
- 缓存(Cache):CPU内部的临时存储区域,用于存储最近使用或频繁使用的数据和指令。缓存容量越大,CPU访问数据的速度越快。常见的缓存有L1、L2和L3缓存,L1缓存速度最快,容量最小,L3缓存容量最大,速度相对较慢。
2. 主板(Motherboard)
- 功能:是计算机各个部件的连接平台,提供插槽和接口,用于安装CPU、内存、显卡等硬件设备,并实现它们之间的通信。
- 性能指标
- 芯片组(Chipset):主板的核心部件,决定了主板支持的CPU类型、内存类型、扩展接口等。例如,Intel的B660芯片组支持12代酷睿处理器,而AMD的B550芯片组支持锐龙5000系列处理器。
- 内存插槽类型和数量:常见的内存插槽类型有DDR4和DDR5。内存插槽数量决定了可以安装的内存条数量,从而影响内存容量的扩展性。例如,一个主板有4个DDR4内存插槽,最大支持64GB内存。
- 扩展插槽:如PCIe插槽,用于安装显卡、声卡、网卡等扩展卡。PCIe插槽的版本和数量会影响扩展设备的性能和扩展能力。例如,PCIe 4.0比PCIe 3.0带宽更高,可以支持更高性能的显卡。
3. 内存(Memory)
- 功能:是计算机的临时存储设备,用于存储CPU正在运行的程序和数据,CPU可以直接访问内存中的数据。
- 性能指标
- 容量(GB):内存的存储容量,容量越大,可以同时运行的程序和数据越多。例如,8GB内存可以满足一般办公需求,而16GB或更高容量的内存适合大型软件和多任务处理。
- 频率(MHz):内存的工作频率,表示内存每秒可以进行的读写操作次数。频率越高,内存的读写速度越快。例如,DDR4 3200MHz的内存比DDR4 2666MHz的内存速度更快。
- 时序(CAS Latency):内存的延迟时间,表示内存响应CPU指令的时间。时序越低,内存的响应速度越快。例如,CL16的内存时序比CL18的内存时序更低。
4. 硬盘(Storage)
- 功能:是计算机的长期存储设备,用于存储操作系统、软件、文件等数据。
- 性能指标
- 容量(TB/GB):硬盘的存储容量,容量越大,可以存储的数据越多。常见的硬盘容量有1TB、2TB、4TB等。
- 读写速度(MB/s):硬盘的数据读取和写入速度。固态硬盘(SSD)的读写速度通常比机械硬盘(HDD)快得多。例如,SSD的读写速度可以达到500MB/s以上,而HDD的读写速度一般在100MB/s左右。
- 接口类型:常见的硬盘接口有SATA和NVMe。NVMe接口的SSD速度更快,适合高性能需求的用户,而SATA接口的硬盘速度相对较慢,但兼容性更好。
5. 显卡(Graphics Card)
- 功能:用于处理图形和图像数据,将计算机中的图像信号转换为显示器可以识别的信号,从而显示图像和视频。
- 性能指标
- 显存容量(GB):显卡的专用存储容量,用于存储图形数据。显存容量越大,可以处理的图形数据越复杂。例如,4GB显存的显卡可以满足一般的办公和游戏需求,而8GB或更高容量的显存适合大型3D游戏和专业图形设计。
- 显存类型:常见的显存类型有GDDR5、GDDR6和HBM等。GDDR6比GDDR5速度更快,带宽更高。
- CUDA核心数或流处理器数:CUDA核心或流处理器是显卡内部的计算单元,数量越多,显卡的计算能力越强。例如,NVIDIA的RTX 3080显卡有8704个CUDA核心,性能非常强大。
6. 电源(Power Supply Unit,PSU)
- 功能:为计算机各个部件提供稳定的电力供应。
- 性能指标
- 功率(W):电源的输出功率,常见的功率有300W、500W、850W等。功率越大,可以支持的硬件设备越多。例如,一台高性能的电脑可能需要850W或更高功率的电源。
- 转换效率:电源将交流电转换为直流电的效率。转换效率越高,电源的能耗越低。例如,80 PLUS认证的电源转换效率在80%以上。
- 输出稳定性:电源输出电压的稳定性,稳定的电源可以保证硬件设备的正常运行,避免因电压波动导致硬件损坏。
7. 机箱(Case)
- 功能:用于容纳和保护计算机硬件设备,提供散热和线缆管理等功能。
- 性能指标
- 尺寸:机箱的大小,常见的有ATX、Micro-ATX和Mini-ITX等规格。尺寸越大,可以安装的硬件设备越多,但占用空间也越大。
- 散热性能:机箱的散热设计,包括风扇数量、散热孔位置等。良好的散热性能可以保证硬件设备在高负载下正常运行。
- 线缆管理:机箱内部的线缆管理设计,方便用户整理线缆,保持机箱内部整洁。
这些硬件部件相互协作,共同构成了计算机的硬件系统,而软件系统则运行在硬件系统之上,实现各种功能和应用。
计算机系统由硬件系统和软件系统两大部分组成,两者协同工作实现数据处理、存储和交互等功能。以下是计算机组成、主要部件功能及性能指标的详细解析:
一、硬件系统:计算机的物理实体
硬件系统是计算机的“躯体”,由五大核心部件构成,分别承担运算、控制、存储、输入和输出功能。
1. 中央处理器(CPU)——计算机的“大脑”
- 功能:
- 负责执行指令、处理数据,协调计算机各部件工作。
- 分为控制器(指挥操作流程)和运算器(完成算术/逻辑运算)。
- 性能指标:
- 核心数/线程数:核心数越多,并行处理能力越强(如4核8线程)。
- 主频:单位为GHz,主频越高,运算速度越快(如3.6GHz)。
- 缓存(Cache):高速存储单元,缓存越大,数据调用效率越高(如L3缓存12MB)。
- 制程工艺:纳米数越小,功耗越低、性能越强(如5nm制程)。
- 指令集:决定CPU支持的软件类型(如x86、ARM)。
2. 存储器——计算机的“记忆系统”
分为内存储器(内存)和外存储器(外存)。
- 内存(主存):
- 功能:临时存储正在运行的程序和数据,速度快但断电后数据丢失。
- 性能指标:
- 容量:单位GB,容量越大,可同时运行的程序越多(如16GB DDR4)。
- 频率:单位MHz,频率越高,数据传输速度越快(如3200MHz)。
- 类型:常见DDR4、DDR5(DDR5性能更强)。
- 外存(硬盘/固态硬盘):
- 功能:永久存储数据和程序,包括机械硬盘(HDD)和固态硬盘(SSD)。
- 性能指标:
- 容量:单位TB,常见1TB、2TB。
- 速度:SSD通过闪存颗粒读写,速度远超HDD(SSD读取速度可达3000MB/s)。
- 接口:SATA(HDD/老款SSD)、NVMe(高速SSD,如PCIe 4.0)。
3. 显卡(GPU)——图像处理核心
- 功能:
- 负责图形渲染、视频编码/解码,游戏、设计、深度学习依赖独立显卡。
- 集成显卡(集成于CPU)性能较弱,独立显卡(如NVIDIA RTX系列)性能更强。
- 性能指标:
- 显存容量:单位GB,显存越大,处理高分辨率图像越流畅(如8GB GDDR6)。
- 核心频率:单位MHz,频率越高,图形处理速度越快。
- CUDA核心/流处理器:数量越多,并行计算能力越强(如RTX 4060含3072个CUDA核心)。
4. 输入设备——人机交互的“桥梁”
- 功能:向计算机输入指令、数据或操作信号,如键盘、鼠标、摄像头、麦克风等。
- 性能指标(以键盘为例):
- 按键手感:机械键盘(青轴/红轴)优于薄膜键盘。
- 响应速度:按键延迟越低越好(如游戏键盘支持1ms响应)。
5. 输出设备——信息展示的“窗口”
- 功能:将计算机处理结果反馈给用户,如显示器、打印机、扬声器等。
- 性能指标(以显示器为例):
- 分辨率:如2K(2560×1440)、4K(3840×2160),分辨率越高,画面越细腻。
- 刷新率:单位Hz,高刷新率(如144Hz)使动态画面更流畅(适合游戏)。
- 色域:如sRGB、DCI-P3,色域越广,色彩表现越丰富(适合设计)。
二、软件系统:计算机的“灵魂”
软件系统是运行在硬件上的程序集合,分为系统软件和应用软件。
- 系统软件:
- 功能:管理硬件资源、提供基础服务,如Windows、macOS、Linux操作系统。
- 核心组件:
- 操作系统内核:负责调度资源、处理中断。
- 驱动程序:连接硬件与系统(如显卡驱动、声卡驱动)。
- 应用软件:
- 功能:解决特定问题,如办公软件(Office)、图像处理软件(Photoshop)、游戏等。
三、关键部件协同工作逻辑
- 数据流动路径:
输入设备 → CPU(处理数据)→ 内存(临时存储)→ 硬盘(永久存储)→ 显卡(渲染图像)→ 输出设备。 - 性能瓶颈场景:
- 多任务卡顿:内存容量不足。
- 游戏帧率低:显卡性能不足或CPU核心数不够。
- 文件读写慢:硬盘速度瓶颈(HDD升级为SSD可显著改善)。
四、如何根据需求选择硬件?
- 办公/学习:优先CPU多核性能(如Intel i5或AMD Ryzen 5),8GB~16GB内存,512GB SSD。
- 游戏/设计:高性能独立显卡(如RTX 4060及以上),16GB~32GB内存,高刷新率显示器。
- 视频剪辑/3D建模:多核CPU(如Intel i7/AMD Ryzen 7),32GB+内存,高速SSD(NVMe接口)。
通过了解各部件功能与指标,可针对性优化计算机配置,提升使用体验。
Spring Integration 1.0.3 Samples: just add OSGi 是一个展示如何将 Spring Integration 与 OSGi 结合使用的示例项目。以下是对其的详细解析:
1. 项目背景
Spring Integration 是一个基于 POJO 的轻量级、可嵌入的消息框架,旨在通过企业集成模式简化异构系统的集成,而无需单独的 ESB 引擎或专有开发环境。OSGi 则是一种允许从独立模块(OSGi Bundle)构建松耦合系统的范式。结合使用 Spring Integration 和 OSGi 可以充分利用两者的动态性和松耦合特性,解决现代企业应用的动态需求。
2. 示例项目介绍
示例项目包含两个 OSGi Bundle:
- osgi-inbound:生产者,用于生成消息并将其发送到消息通道。
- osgi-outbound:消费者,从通道中接收消息并将其写入文件。
2.1 环境搭建
- 使用 SpringSource Tool Suite (STS) 和 dm Server 工具来快速集成。
- 需要将项目配置为使用 SpringSource dm Server 作为目标运行时。
- 确保安装了 Spring Integration 和 Spring 的 OSGi 包。
2.2 部署与测试
- 启动 dm Server,然后将
osgi-inbound
和osgi-outbound
项目拖放到 dm Server 实例中。 - 使用 OSGi 控制台或 dm Server 控制台发送消息,例如通过命令
siSend "Hello World" hello.txt
。 - 验证消息是否被写入指定文件。
3. 动态特性与优势
3.1 动态服务注册与发现
osgi-inbound
通过<osgi:service>
将消息通道注册为 OSGi 服务。osgi-outbound
通过<osgi:reference>
动态订阅该服务。- 这种方式允许在运行时动态添加或移除消费者,而无需重新部署整个系统。
3.2 独立生命周期管理
- 如果修改
osgi-outbound
的配置(例如更改文件存储目录),只需重新部署该 Bundle,而不会影响osgi-inbound
。 - 这种动态性使得系统能够灵活应对需求变化,无需停机。
4. 扩展性
- 可以通过添加新的 Bundle 来扩展系统功能,例如添加一个用于发送邮件通知的 Bundle。
- 新的 Bundle 可以作为消费者订阅
osgi-inbound
提供的通道服务,而无需修改现有代码。
5. 总结
通过这个示例,我们可以看到 Spring Integration 和 OSGi 的结合如何实现松耦合、动态可扩展的系统。这种架构特别适合需要频繁更新和扩展的企业级应用。
关于“Spring Integration 1.0.3 Samples: just add OSGi”的解析,需要从Spring Integration 历史版本特性、OSGi 技术背景以及示例代码的设计意图三个维度展开分析。以下是具体解读:
一、背景知识:Spring Integration 与 OSGi
1. Spring Integration 简介
- 定位:Spring 框架的子项目,用于构建企业集成模式(EIP)的应用,支持消息传递、协议转换、数据路由等功能。
- 1.0.3 版本特点:发布于2009年左右,属于早期版本,核心功能聚焦于基础集成场景(如文件传输、HTTP 交互、消息通道等),尚未完全融入 Spring 生态的后续特性(如 Spring Boot)。
2. OSGi 技术背景
- 定义:Open Service Gateway Initiative 的缩写,是 Java 平台的动态模块化规范,用于实现应用程序的组件化部署、动态更新和依赖管理。
- 核心优势:
- 模块化隔离:不同模块(Bundle)可独立部署、升级,避免类冲突。
- 动态性:支持运行时安装、启动、停止模块。
- 服务注册与发现:模块可发布服务供其他模块调用,实现松耦合。
- 与 Spring 的关系:早期 Spring 生态对 OSGi 的支持通过 Spring DM(Dynamic Modules) 实现(后演进为 Spring Boot 的 OSGi 支持),而 Spring Integration 1.0.3 示例可能基于 Spring DM 集成 OSGi。
二、示例标题解析:just add OSGi
1. 标题含义
- 核心意图:演示如何在 Spring Integration 1.0.3 的现有示例中添加 OSGi 支持,使原本基于传统 Java EE 或 Spring 单模块的集成应用具备模块化能力。
- 隐含假设:示例代码原本不支持 OSGi,通过修改配置或代码,“只需添加” OSGi 相关依赖和配置即可实现模块化部署。
2. 可能的改造步骤
- 步骤1:引入 OSGi 依赖
- 添加 Spring DM 或 Equinox(OSGi 实现)的依赖,例如:
<dependency> <groupId>org.springframework.osgi</groupId> <artifactId>spring-osgi-core</artifactId> <version>2.0.0</version> </dependency>
- 添加 Spring DM 或 Equinox(OSGi 实现)的依赖,例如:
- 步骤2:模块化配置(MANIFEST.MF)
- 在项目的
META-INF/MANIFEST.MF
中声明 Bundle 元数据,如:Bundle-Name: Spring Integration OSGi Sample Bundle-SymbolicName: spring-integration-osgi-sample Bundle-Version: 1.0.0 Import-Package: org.springframework.context, org.springframework.integration.core, ... Export-Package: com.example.osgi.integration
- 在项目的
- 步骤3:将 Spring 应用上下文适配为 OSGi Service
- 使用
org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext
加载 Spring 配置文件,使 Integration 的消息通道、处理器等作为 OSGi 服务发布。
- 使用
- 步骤4:动态集成模块
- 不同的 Integration 功能模块(如文件处理、HTTP 服务)可拆分为独立的 Bundle,通过 OSGi 服务注册与发现机制交互。
三、示例代码的可能场景
假设原示例是一个简单的 文件监听 -> 消息处理 -> 数据库存储 流程,添加 OSGi 后可能的架构如下:
1. 模块拆分
模块(Bundle) | 功能描述 |
---|---|
file-listener-bundle | 监听文件目录,通过 OSGi 服务发布新文件事件 |
message-processor-bundle | 订阅文件事件,执行数据转换(如 XML 转 JSON),作为 OSGi 服务消费事件 |
database-sink-bundle | 接收处理后的数据,写入数据库,通过 OSGi 服务暴露存储接口 |
2. OSGi 服务交互示例
- 发布服务:在
file-listener-bundle
的 Spring 配置中,将文件监听器注册为 OSGi 服务:<osgi:service interface="com.example.FileListenerService" ref="fileListener"> <osgi:service-properties> <props> <prop key="service.type">file-listener</prop> </props> </osgi:service-properties> </osgi:service>
- 消费服务:在
message-processor-bundle
中,通过 OSGi 服务引用获取文件监听器服务:<osgi:reference id="fileListenerService" interface="com.example.FileListenerService" />
四、技术意义与局限性
1. 技术意义(2009年背景下)
- 模块化集成:将复杂的集成逻辑拆分为可独立部署的模块,便于团队协作和维护。
- 动态更新:例如,修改文件监听逻辑时,只需重启对应的 Bundle,无需重启整个应用。
- 依赖管理:OSGi 强制声明依赖关系,避免类路径污染(如多个版本的 Spring 库冲突)。
2. 局限性(对比现代技术)
- 配置复杂性:OSGi 的
MANIFEST.MF
和 Spring DM 配置较为繁琐,需手动管理包导入/导出。 - 生态演进:Spring 后续推出 Spring Boot(2013年)和 Spring Cloud(微服务),更倾向于轻量化容器和云原生架构,OSGi 的使用场景逐渐减少。
- 学习成本:OSGi 规范本身较复杂,对开发者要求较高,而现代微服务框架(如 Spring Cloud)通过更简单的方式实现服务治理。
五、延伸思考:OSGi 的现代应用
尽管 Spring Integration 早期尝试集成 OSGi,但当前主流趋势是通过 Spring Boot + 微服务架构 实现模块化。不过,OSGi 在以下场景仍有价值:
- 嵌入式系统:如 Eclipse RCP 应用、物联网网关(需动态加载插件)。
- 大型企业级应用:需严格控制模块隔离和版本管理的传统企业系统。
若需复现类似示例,可参考 Spring DM 官方文档 或使用 Apache ServiceComb 等现代模块化框架替代 OSGi。
通过以上分析可知,“just add OSGi” 示例的核心是展示如何利用 OSGi 技术增强 Spring Integration 应用的模块化和动态性,反映了早期企业级开发对组件化部署的需求,同时也体现了技术演进过程中不同框架的融合尝试。
Last week, Mark Fisher introduced you to the new restructured and simplified Spring Integration samples that came out with the new release of Spring Integration 1.0.3 and so far the feedback was very positive.
Beside restructuring and simplifying existing samples we’ve introduced few new samples with the goal of demonstrating some of the benefits of running Spring Integration on OSGi-based platforms.
In this blog using very trivial, yet powerful example we’re going to look at some of the benefits of Spring Integration and OSGi when used together to address dynamic nature of today’s enterprise.
Spring Integration is a POJO-based light weight, embeddable messaging framework with a loosely coupled programming model aimed to simplify integration of heterogeneous systems based on Enterprise Integration Patterns and without requiring a separate ESB-like engine or proprietary development and deployment environment. On the other hand, OSGi is a paradigm that allows one to compose loosely coupled systems from independent modules called OSGi Bundles. Composing systems from the set of independently developed modules might not be such a new paradigm, we’ve been doing it (hopefully) for a number of years. Having said that, the realization of true benefit of OSGi modularization will come not from its static packaging model, but from understanding its deployment and run-time dynamics and how well it is positioned to address the dynamics of today’s business processes.
So, let’s see on the simple example how integration based on message exchange and dynamics of OSGi can complement each other allowing for realization of very powerful and dynamic system.
Spring Integration samples come with the distribution of Spring Integration. You can also download them independently from here. For simplicity these samples were developed as SpringSource Tool Suite (STS) projects while utilizing dm Server tools for quick integration with SpringSource dm Server - an OSGi and Spring based Enterprise Java Platform. However being OSGi compliant based projects these samples will adequately run on any properly configured OSGi platform.
Environment
First, let’s make sure we have a properly configured development/deployment environement.
To configure STS/dm Server environment follow these steps:
Download and unzip STS from here
Download and unzip SpringSource dm Server from here
Spring Source Tool Suite v2.1.x will come with SpringSource dm Server already pre-configured, however understanding how to configure it manually still helps.
Open STS and Configure dm Server:
Open Server View -> Right Click on white spot in the Server view -> New -> Server
picture-14
Select SpringSource -> SpringSource dm Server v1.0 -> Next
Point to the home the directory where you installed the server
picture-22
Click Finish
picture-3
You now have SpringSource dm Server configured within STS environment.
Start dm Server and make sure it starts successfully and that there are no errors.
It is assumed you already downloaded Spring Integration samples, so let’s import the two sample projects into the workspace using Import Existing Projects into the workspace wizard provided by STS/Eclipse.
File -> Import -> General -> Existing Projects into Workspace -> Next
Browse to the location of the samples directory and select osgi-inbound and osgi-outbound projects
picture-51
Click Finish You should see two projects with errors.
picture-4
These errors are expected simply because our projects are not aware of dm Server Target Runtime and our dm Server Target Runtime is not aware of Spring Integration bundles. Let’s solve one issue at a time. First lets make dm Server aware of the Spring Integration by deploying Spring Integration and dependent bundles into dm Server’s repository. This is a very simple process. Copy org.springframework.integration-1.0.3.RELEASE.jar and org.springframework.integration.file-1.0.3.RELEASE.jar (the two bundles our samples depend on) into dm Server’s repository/bundles/usr directory. Then in the STS’s Server view double click on the instance of the dm Server -> Click on Repository tab and in the right top corner you’ll find a Refresh button. Click on it and you should see the two bundles available in the dm Server’s repository.
picture-6
Now we need to make our bundle projects aware of our new Target Runtime.
Right click on each project -> Properties -> Target Runtimes -> SpringSource dm Server (Runtime) v1.0
picture-7
Now all the errors should disappear.
You are ready to test these samples
Samples
These two samples built on very simple and familiar producer/consumer concept.
The first bundle osgi-inbound is a producer which will allow you to produce a message that will be sent to a message channel. The second bundle osgi-outbound is a consumer and will consume a message placed on the channel by osgi-inbound bundle and will write the message to a file.
Start dm Server by right clicking on the server instance -> Start
Deploy osgi-inbound by simply dragging and dropping osgi-inbound project onto the dm Server instance. In a few seconds you should see successful start message:
[2009-07-27 21:56:49.040] onnection(5)-172.16.12.1 Deployment of ‘org.springframework.integration.samples.osgi.inbound’
version ‘1.0.3’ completed.
Then do the same for osgi-outbound bundle:
[2009-07-27 21:58:45.220] onnection(8)-172.16.12.1 Deployment of ‘org.springframework.integration.samples.osgi.outbound’
version ‘1.0.3’ completed.
Now you are ready to test the functionality provided by these bundles. To make it more interesting we’ve enabled Command Line Interface (CLI) via OSGi console which allows you to interact with osgi-inbound bundle by providing a command, the message and the file name you want the message to be written.
You can connect to OSGi console via:
telnet localhost 2401
or you can use Server Console tab of the Server view and type:
siSend “Hello World” hello.txt
and click Execute
You will see the following:
picture-9
Go and verify that the your message has been written to a file.
This very simple and trivial concept demonstrates the loosely coupled integration between the two systems based on the messaging model provided by Spring Integration.
However in the real world one of the issues that we have to face while trying to integrate the two systems is the independent life-cycle of such systems where change in their behavior, addition of new systems and/or end of life of the old systems is a normal occurrence. Typically such changes require, not only code changes, but redeployment of the entire monolithic (e.g., EAR, WAR ) application following the complete server restart.
Spring integration’s POJO programming model is very well suited to address loosely coupled nature of these system where change to one system rarely affects another one. However what about its life-cycle dynamics?
Lets assume that the requirement (within the scope of our little sample) as to where or how the files have to be written has changed. Both “where” and “how” is the responsibility of the osgi-outbound bundle.
Under normal circumstances, any change to the functionality of the osgi-outbound bundle would require complete refresh of the system (i.e., redeployment of the entire system and server restart). It might not be such a big problem when your system is comprised of only two bundles. But what if its more then two? Are you prepared to rebuild and redeploy the entire system packaged as WAR or EAR simply because the directory where messages have to be written has changed or a new sub-system which should log every incoming message was introduced?
This is where OSGi and its Services layer and most importantly OSGi Service dynamics provide great help. So lets take the sample requirements described above and see how they could be realized based on extending current samples. First, lets review the Application Context configuration of the osgi-inbound bundle:
<osgi:service id=“inboundService” ref=“inboundChannel”
interface=“org.springframework.integration.channel.SubscribableChannel”/>
<integration:publish-subscribe-channel id=“inboundChannel”/>
<integration:gateway id=“inboundGateway”
service-interface=“org.springframework.integration.samples.osgi.inbound.InboundGateway”
default-request-channel=“inboundChannel”/>
As you can see, a very simple configuration which defines a Gateway Proxy allowing for a POJO way of sending a message that will be deposited to an inbound channel configured as publish-subscribe channel. However what makes it even more interesting is that this channel has been exported as a service to the OSGi Service Registry via element, thus allowing for much loosely coupled yet dynamic cooperation model between the current and future bundles.
Let’s also review the Application Context configuration of osgi-outbound bundle.
<osgi:reference id=“filesIn”
interface=“org.springframework.integration.channel.SubscribableChannel”/>
<file:outbound-gateway id=“filesOut”
request-channel=“filesIn”
directory=“${java.io.tmpdir}/spring-integration-samples/output”
delete-source-files=“true”/>
The goal of this bundle is to dynamically subscribe to a channel advertised by the osgi-inbound bundle as soon as this bundle comes up and write a message to a file in the directory configured by the osgi:service/ element, thus accounting for a dynamics provided by OSGi Services layer.
As you can see in this configuration the ‘inboundChannel’ OSGi service exported by the osgi-inbound bundle is now imported via osgi:reference/ element.
Now the inbound channel which is fronted by OSGi service is ready to accept and/or lose subscribers dynamically at runtime. Because of OSGi Service dynamics we can also update configuration or totally re-design/re-implement osgi-outbound bundle without affecting the producing part of the system (osgi-inbound). So lets go ahead and change the directory where the files will be written (Make sure the dm Server is still running… in fact forget about stopping it for the duration of this blog)
Open osgi-outbound project -> src -> META-INF -> spring -> osgi-outbound.xml and add a sub-directory to the ‘directory’ configuration (in this case its ‘foo’)
picture-8
Save the file. In the few seconds you’ll see your osgi-outbound bundle was redeployed
Open up OSGi or Server Console and send another message as you did before and see if the new file was written to the directory you’ve just specified. Hopefully it was 😉
Conclusion
Remember, although in this trivial example we are only dealing with two bundles, these types of producer/consumer bundles could themselves be gateways to other parts of your system and these parts are naturally dynamic. As an example, lets assume you want to receive an email notification about the file being written. With SI and OSGi, the only thing you would need to do is create another bundle to represent that part of your sub-system as a consumer to the channel service advertised by osgi-inbound bundle, and when you don’t need it - unsubscribe, by stopping or undeploying this consumer without affecting the rest of your system. In fact go ahead and try to develop another bundle as a consumer to the osgi-inbound or use your imagination and develop another bundle that will do something with the file that was written by the osgi-outbound bundle.
For more ideas and a more sophisticated example you might also enjoy reading this from Spring Integration team member Iwein Fuld
Mark Fisher向您介绍了随着Spring Integration 1.0.3的新版本而推出的新的经过重组和简化的Spring集成示例,到目前为止,反馈非常积极。
除了重组和简化现有的示例之外,我们还引入了一些新的示例,目的是演示在基于OSGi的平台上运行Spring集成的一些好处。
在这篇博客中,我们将用一个非常琐碎而又强大的例子来说明Spring集成和OSGi在一起解决当今企业动态特性时的一些好处。
Spring集成是一个基于POJO的轻量级、可嵌入的消息传递框架,具有松散耦合的编程模型,旨在简化基于企业集成模式的异构系统的集成,而不需要单独的ESB式引擎或专有的开发和部署环境。另一方面,OSGi是一个允许人们从称为osgibundle的独立模块组成松散耦合系统的范例。从一组独立开发的模块组成系统可能不是一个新的范例,我们(希望)已经做了很多年了。尽管如此,OSGi模块化真正好处的实现并不是来自于它的静态打包模型,而是来自于理解它的部署和运行时动态,以及它在解决当今业务流程动态方面的地位。
因此,让我们看一个简单的例子,基于消息交换和OSGi动态的集成是如何相互补充的,从而实现非常强大和动态的系统。