Mule安装与开发部署一个简单例子

简介:



    本文介绍如何安装Mule,并且开发一个简单的Mule例子。

1.下载Mule
    到Mule官方网站下载Mule的社区版本,注意企业版本需要收费,而社区版本已经满足开发需要,并且开发源代码。下载地址是:[url]http://www.mulesource.org/display/MULE/Download[/url]。笔者下载的Mule版本是mule2.1.1。
2.安装需要的软件
    (1)安装JDK1.6,这里就不详细描述。
    (2)到[url]http://maven.apache.org/[/url] 下载Maven,下载Maven2.0.9版本。如果你只想使用mule,而不想编译mule自带的例子和mule源码,就不需要下载Maven。
    (3)设置Maven的repository directory为c:\.m2\repository。如果是windows系统,在dos命令下创建.m2命令:mkdir .m2。
    (4)设置环境变量,也可以在界面中设置:
    Linux环境:
     export JAVA_HOME=/opt/java/jdk
     export MAVEN_HOME=/opt/apache/maven-2.0.9
     export MAVEN_OPTS=-Xmx512m -XX:MaxPermSize=256
     export MULE_HOME=/opt/mule
     export PATH=$PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin:$MULE_HOME/bin
    Windows环境:
    set JAVA_HOME=C:\Program Files\Java\jdk
     set MAVEN_HOME=C:\Apache\maven-2.0.9
     set MAVEN_OPTS=-Xmx512m -XX:MaxPermSize=256
     set MULE_HOME=C:\Mule
     set PATH=%PATH%;%JAVA_HOME%/bin;%MAVEN_HOME%/bin;MULE_HOME/bin
    
3.测试安装是否成功
    在命令行下输入maven -version查看maven是否安装成功,输入mule查看mule是否安装成功。如果成功,就可以开始第一个Mule应用开发了。

4.开发第一个mule例子——Hello
    (1)新建一个eclipse java工程,工程名称是:MyHello,创建包org.foo,在这个包下新建接口(interface) MyTestInterface,代码如下:
package org.foo;

public  interface MyTestInterface {
   public String hello(String aname);
}
    (2)在这个包下新建类MyTest,代码如下:
package org.foo;

public  class MyTest  implements MyTestInterface
{
   public String hello(String aname)
  {
     return  "you are: " + aname;
  }

}
    (3)在工程下新建文件夹conf用于存放工程配置文件,新建文件myhello-config.xml,内容如下:
<? xml  version ="1.0"  encoding ="UTF-8" ?>
< mule  xmlns ="http://www.mulesource.org/schema/mule/core/2.1"
              xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
              xmlns:spring ="http://www.springframework.org/schema/beans"
              xmlns:stdio ="http://www.mulesource.org/schema/mule/stdio/2.1"
              xmlns:vm ="http://www.mulesource.org/schema/mule/vm/2.1"
        xsi:schemaLocation="
             [url]http://www.springframework.org/schema/beans[/url] [url]http://www.springframework.org/schema/beans/spring-beans-2.5.xsd[/url]
             [url]http://www.mulesource.org/schema/mule/core/2.1[/url] [url]http://www.mulesource.org/schema/mule/core/2.1/mule.xsd[/url]
             [url]http://www.mulesource.org/schema/mule/stdio/2.1[/url] [url]http://www.mulesource.org/schema/mule/stdio/2.1/mule-stdio.xsd[/url]
             [url]http://www.mulesource.org/schema/mule/vm/2.1[/url] [url]http://www.mulesource.org/schema/mule/vm/2.1/mule-vm.xsd[/url]" >

         < de.ion >
                This is a simple component example that demostrates how to expose
                a component over multiple transports.
         </ de.ion >

     <!--
                The stdio connector is used to send and receive information via System.in and System.out.
                Note this connector is .ly really useful for testing purposes.
                        promptMessage - is what is written to the console
                        messageDelayTime - is the time in milliseconds before the user is prompted again.
                These properties are set as bean properties . the connector.
        
-->
         < stdio:connector  name ="SystemStreamConnector"
                 promptMessage ="Please enter yout name: "
                 messageDelayTime ="1000" />

        <!--
                The Mule model initialises and manages your UMO components
        
-->
         < model  name ="MyHelloSample" >
                <!--
                        A Mule service defines all the necessary information about how your components will
                        interact with the framework, other components in the system and external sources.
                        Please refer to the Configuration Guide for a full de.ion of all the parameters.
                
-->
                 < service  name ="MyHelloUMO" >
                        <!--  any number of endpoints can be added to an inbound router -->
                         < inbound >
                                 < stdio:inbound-endpoint  system ="IN" />
                                <!-- vm:inbound-endpoint path="echo"/-->
                         </ inbound >

                         < component  class ="org.foo.MyTest" />

                        <!--
                                An outbound router can have .e or more router configurations that can be
                                invoked depending . business rules, message contents, headers or any other
                                criteria. The pass-through-router is a router that automatically passes
                                on every message it receives
                        
-->
                         < outbound >
                                 < pass-through-router >
                                         < stdio:outbound-endpoint  system ="OUT" />
                                 </ pass-through-router >
                         </ outbound >
                 </ service >
         </ model >
</ mule >
    (4)至此,一个Mule服务就开发完成了,是不是很容易?接下来就部署这个服务。右击该工程,点击“export”,将工程导出到一个目录,命名为MyHello.jar,然后将这个jar包放到C:\Mule\mule-2.1.2\lib\user下(我的Mule安装到
C:\Mule目录下)。这样部署就完成了。
    (5)运行mule服务,有两种方式。第一种比较直接和简单,在命令行中输入:mule -config conf/myhello-config.xml即可。第二种,在MyHello工程文件目录下新建一个文件myHello.bat,内容如下:
@echo off
setlocal
REM There is no need to call this if you set the MULE_HOME in your environment properties
REM but you must also define MULE_LIB for the example (see below)
REM or specify the config as a file: URI (see README.txt)
if "%MULE_HOME%" == "" SET MULE_HOME=%~dp0..\..
if "%MULE_BASE%" == "" SET MULE_BASE=%MULE_HOME%

REM This extends the classpath to include the configuration directory
REM Any changes to the files in .\conf will take precedence over those deployed to %MULE_HOME%\lib\user
SET MULE_LIB=.\conf

call "%MULE_BASE%\bin\mule.bat" -config myhello-config.xml

    然后双击这个文件就可以运行MyHello服务了,允许结果截图如下:


    至此,一个简单的Mule服务就开发完成了,是不是很简单啊?接下来一篇文章讲解如何编译和导入Mule自带的例子到elicpse工程下。


     本文转自panpan3210 51CTO博客,原文链接:http://blog.51cto.com/panpan/132270,如需转载请自行联系原作者





相关文章
|
SQL 监控 druid
Druid未授权访问 漏洞复现
Druid未授权访问 漏洞复现
22156 1
|
存储 Linux KVM
Proxmox VE (PVE) 主要架构和重要服务介绍
Proxmox VE (PVE) 是一款开源的虚拟化平台,它基于 KVM (Kernel-based Virtual Machine) 和 LXC (Linux Containers) 技术,支持虚拟机和容器的运行。PVE 还提供高可用集群管理、软件定义存储、备份和恢复以及网络管理等企业级功能。
5153 7
|
存储 分布式计算 资源调度
Hadoop运行模式(三)、群起集群、配置workers、启动集群、启动HDFS、拼接、Web端查看HDFS的NameNode、Web端查看YARN的ResourceManager
Hadoop运行模式(三)、群起集群、配置workers、启动集群、启动HDFS、拼接、Web端查看HDFS的NameNode、Web端查看YARN的ResourceManager
Hadoop运行模式(三)、群起集群、配置workers、启动集群、启动HDFS、拼接、Web端查看HDFS的NameNode、Web端查看YARN的ResourceManager
|
安全 Java Android开发
GDA反编译工具全面指南:从入门到高级应用
GDA(Generic Dalvik Analyzer)是一款专为Android逆向工程和安全研究设计的高性能反编译工具,由中国团队开发。它采用C++编写,无需依赖Java虚拟机,具备低资源消耗与高分析效率的优势。GDA支持多种文件格式的反编译,如APK、DEX、JAR等,并集成了恶意行为检测、隐私泄露分析、漏洞扫描等功能。同时提供变量追踪、路径解析、脚本自动化等实用特性,广泛应用于逆向分析、安全审计与漏洞挖掘。作为国产优秀逆向工具,GDA凭借其独立运行能力、丰富的功能和持续更新,在全球范围内受到分析师青睐。
2349 0
|
安全 Cloud Native Shell
云上攻防:云原生篇&Docker容器逃逸
本文介绍了Docker的基本概念及其对渗透测试的影响,重点讲解了容器逃逸的方法。Docker是一种轻量级的容器技术,与虚拟机相比,具有更高的便携性和资源利用率。然而,这也带来了安全风险,特别是容器逃逸问题。文章详细描述了三种常见的容器逃逸方法:不安全的配置、相关程序漏洞和内核漏洞,并提供了具体的检测和利用方法。此外,还介绍了几种特定的漏洞(如CVE-2019-5736和CVE-2020-15257)及其复现步骤,帮助读者更好地理解和应对这些安全威胁。
1831 3
云上攻防:云原生篇&Docker容器逃逸
|
应用服务中间件 Linux 网络安全
nginx安装部署ssl证书,同时支持http与https方式访问
为了使HTTP服务支持HTTPS访问,需生成并安装SSL证书,并确保Nginx支持SSL模块。首先,在`/usr/local/nginx`目录下生成RSA密钥、证书申请文件及自签名证书。接着,确认Nginx已安装SSL模块,若未安装则重新编译Nginx加入该模块。最后,编辑`nginx.conf`配置文件,启用并配置HTTPS服务器部分,指定证书路径和监听端口(如20000),保存后重启Nginx完成部署。
5588 8
|
Java UED Spring
Springboot通过SSE实现实时消息返回
通过Spring Boot实现SSE,可以简单高效地将实时消息推送给客户端。虽然SSE有其限制,但对于许多实时消息推送场景而言,它提供了一种简洁而强大的解决方案。在实际开发中,根据具体需求选择合适的技术,可以提高系统的性能和用户体验。希望本文能帮助你深入理解Spring Boot中SSE的实现和应用。
7790 1
|
分布式计算 大数据 BI
ClickHouse与大数据生态整合:从ETL到BI报表
【10月更文挑战第27天】在这个数据驱动的时代,企业越来越依赖于数据来做出关键决策。而高效的数据处理和分析能力则是支撑这一需求的基础。作为一位数据工程师,我有幸参与到一个项目中,该项目旨在利用ClickHouse与Hadoop、Spark、Flink等大数据处理框架的整合,构建一个从数据提取(Extract)、转换(Transform)、加载(Load)到最终生成商业智能(BI)报表的全流程解决方案。以下是我在这个项目中的经验和思考。
884 1
|
存储 JavaScript Python
word文档转成Markdown文档并在Typora免费版添加图床-----想想都很香
word文档转成Markdown文档并在Typora免费版添加图床-----想想都很香
1339 0
|
存储 监控 Ubuntu
在Linux中,如何进行用户行为监控?
在Linux中,如何进行用户行为监控?

热门文章

最新文章