`
a3mao
  • 浏览: 559275 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Apache Servicemix 学习(3) ------ 创建service unit

阅读更多
ServiceMix提供了几个默认的mavne命令,可以方便的开发出servicemix工程。比如:用servicemix-service-unit来创建一个service unit工程。servicemix提供的几个内置命令列表:
servicemix-binding-component
servicemix-service-assembly 
servicemix-service-engine 
servicemix-service-unit 
servicemix-shared-library
servicemix-bean-service-unit
servicemix-camel-service-unit
servicemix-cxf-bc-consumer-service-unit
servicemix-cxf-bc-provider-service-unit
servicemix-cxf-se-service-unit
servicemix-drools-service-unit
servicemix-eip-service-unit
servicemix-exec-service-unit
servicemix-file-poller-service-unit
servicemix-file-sender-service-unit
servicemix-ftp-poller-service-unit
servicemix-ftp-sender-service-unit
servicemix-http-consumer-service-unit
servicemix-http-soap-consumer-service-unit
servicemix-http-provider-service-unit
servicemix-http-soap-provider-service-unit
servicemix-jms-consumer-service-unit
servicemix-jms-soap-consumer-service-unit
servicemix-jms-jca-consumer-service-unit
servicemix-jms-provider-service-unit	
servicemix-jms-soap-provider-service-unit
servicemix-jsr181-annotated-service-unit
servicemix-jsr181-wsdl-first-service-unit
servicemix-lwcontainer-service-unit
servicemix-mail-poller-service-unit
servicemix-mail-sender-service-unit
servicemix-ode-service-unit
servicemix-osworkflow-service-unit
servicemix-quartz-cron-trigger-service-unit
servicemix-quartz-simple-trigger-service-unit
servicemix-quartz-custom-marshaler-service-unit
servicemix-saxon-xquery-service-unit
servicemix-saxon-xslt-service-unit
servicemix-script-service-unit
servicemix-scripting-service-unit
servicemix-smpp-consumer-service-unit
servicemix-smpp-provider-service-unit
servicemix-snmp-poller-service-unit
servicemix-snmp-trap-consumer-service-unit
servicemix-validation-service-unit
servicemix-vfs-poller-service-unit
servicemix-vfs-sender-service-unit


在工程目录(/opt/ericWorkspace/servicemix )下运行命令:
mvn archetype:create -DarchetypeArtifactId=servicemix-service-unit -DarchetypeGroupId=org.apache.servicemix.tooling -DartifactId=tutorial-file-su


如果出现如下信息:
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Tutorial
[INFO]    task-segment: [archetype:create] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [archetype:create {execution: default-cli}]
[WARNING] This goal is deprecated. Please use mvn archetype:generate instead
[INFO] Defaulting package to group ID: org.apache.servicemix.tutorial
[INFO] artifact org.apache.servicemix.tooling:servicemix-service-unit: checking for updates from central
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating OldArchetype: servicemix-service-unit:RELEASE
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: org.apache.servicemix.tutorial
[INFO] Parameter: packageName, Value: org.apache.servicemix.tutorial
[INFO] Parameter: package, Value: org.apache.servicemix.tutorial
[INFO] Parameter: artifactId, Value: tutorial-file-su
[INFO] Parameter: basedir, Value: /opt/ericWorkspace/servicemix
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] ********************* End of debug info from resources from generated POM ***********************
[INFO] OldArchetype created in dir: /opt/ericWorkspace/servicemix/tutorial-file-su
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Mon Aug 16 20:49:27 CST 2010
[INFO] Final Memory: 11M/130M
[INFO] ------------------------------------------------------------------------
eric@eric-laptop:/opt/ericWorkspace/servicemix$ 



则说明创建service unit成功。
在工程目录(servicemix)下会生成tutorial-file-su子模块。
tutorial-file-su子模块目录结构:

tutorial-file-su
                pom.xml
                src
                   main
                       resources

修改pom.xml文件,将name改为 Tutorial :: File SU

<project>
  ...
  <name>Tutorial :: File SU</name>
  ...
</project>



同时。增加一个依赖类包:
<dependency>
    <groupId>org.apache.servicemix</groupId>
    <artifactId>servicemix-file</artifactId>
    <version>${servicemix-version}</version>
  </dependency>


整个pom文件内容:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <artifactId>parent</artifactId>
    <groupId>org.apache.servicemix.tutorial</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <groupId>org.apache.servicemix.tutorial</groupId>
  <artifactId>tutorial-file-su</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jbi-service-unit</packaging>
  <name>Tutorial :: File SU</name>
  <url>http://www.myorganization.org</url>
  <build>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <includes>
          <include>**/*</include>
        </includes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <groupId>org.apache.servicemix.tooling</groupId>
        <artifactId>jbi-maven-plugin</artifactId>
        <version>${servicemix-version}</version>
        <extensions>true</extensions>
      </plugin>
    </plugins>
  </build>
  <repositories>
    <repository>
      <releases />
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>apache</id>
      <name>Apache Repository</name>
      <url>http://people.apache.org/repo/m2-ibiblio-rsync-repository</url>
    </repository>
    <repository>
      <releases>
        <enabled>false</enabled>
      </releases>
      <snapshots />
      <id>apache.snapshots</id>
      <name>Apache Snapshots Repository</name>
      <url>http://people.apache.org/repo/m2-snapshot-repository</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <releases />
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>apache</id>
      <name>Apache Repository</name>
      <url>http://people.apache.org/repo/m2-ibiblio-rsync-repository</url>
    </pluginRepository>
    <pluginRepository>
      <releases>
        <enabled>false</enabled>
      </releases>
      <snapshots />
      <id>apache.snapshots</id>
      <name>Apache Snapshots Repository</name>
      <url>http://people.apache.org/repo/m2-snapshot-repository</url>
    </pluginRepository>
  </pluginRepositories>
  <dependencies>
  <dependency>
    <groupId>org.apache.servicemix</groupId>
    <artifactId>servicemix-file</artifactId>
    <version>${servicemix-version}</version>
  </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <properties>
    <servicemix-version>3.2.3</servicemix-version>
  </properties>
</project>


这只是一个非常简单的service unit工程,并没有java代码,只是利用了servicemix内置的service unit,如果能够让servicemix支持service unit,那么我就要写xbean.xml配置文件,将其配置到servicemix中。

在tutorial-file-su/src/main/resources目录下新建xbean.xml文件,内容为:
<beans xmlns:file="http://servicemix.apache.org/file/1.0"
	xmlns:tut="urn:servicemix2:tutorial2">
	
	<file:sender service="tut:file" 
             endpoint="sender"
             directory="file:/home/eric/temp/sender" />

	<file:poller service="tut:file" 
             endpoint="poller"
             file="file:/home/eric/temp/poller" 
             targetService="tut:file"
             targetEndpoint="tut:wiretap"/>
</beans>


此外,我们还要创建 service assembly工程,
输入命令:
mvn archetype:create -DarchetypeArtifactId=servicemix-service-assembly -DarchetypeGroupId=org.apache.servicemix.tooling -DartifactId=tutorial-sa


当出现如下信息时
[INFO] ------------------------------------------------------------------------
[INFO] Building Tutorial
[INFO]    task-segment: [archetype:create] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [archetype:create {execution: default-cli}]
[WARNING] This goal is deprecated. Please use mvn archetype:generate instead
[INFO] Defaulting package to group ID: org.apache.servicemix.tutorial
[INFO] artifact org.apache.servicemix.tooling:servicemix-service-assembly: checking for updates from central
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating OldArchetype: servicemix-service-assembly:RELEASE
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: org.apache.servicemix.tutorial
[INFO] Parameter: packageName, Value: org.apache.servicemix.tutorial
[INFO] Parameter: package, Value: org.apache.servicemix.tutorial
[INFO] Parameter: artifactId, Value: tutorial-sa
[INFO] Parameter: basedir, Value: /opt/ericWorkspace/servicemix
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] ********************* End of debug info from resources from generated POM ***********************
[INFO] OldArchetype created in dir: /opt/ericWorkspace/servicemix/tutorial-sa
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6 seconds
[INFO] Finished at: Mon Aug 16 21:16:12 CST 2010
[INFO] Final Memory: 22M/268M
[INFO] ------------------------------------------------------------------------


此时,sa工程创建成功,
sa子模块目录结构为:

tutorial-sa
           pom.xml

修改pom,xml
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <artifactId>parent</artifactId>
    <groupId>org.apache.servicemix.tutorial</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <groupId>org.apache.servicemix.tutorial</groupId>
  <artifactId>tutorial-sa</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jbi-service-assembly</packaging>
  <name>Tutorial :: SA</name>
  <url>http://www.myorganization.org</url>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.servicemix.tooling</groupId>
        <artifactId>jbi-maven-plugin</artifactId>
        <version>${servicemix-version}</version>
        <extensions>true</extensions>
        <configuration>
          <type>service-assembly</type>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <repositories>
    <repository>
      <releases />
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>apache</id>
      <name>Apache Repository</name>
      <url>http://people.apache.org/repo/m2-ibiblio-rsync-repository</url>
    </repository>
    <repository>
      <releases>
        <enabled>false</enabled>
      </releases>
      <snapshots />
      <id>apache.snapshots</id>
      <name>Apache Snapshots Repository</name>
      <url>http://people.apache.org/repo/m2-snapshot-repository</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <releases />
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>apache</id>
      <name>Apache Repository</name>
      <url>http://people.apache.org/repo/m2-ibiblio-rsync-repository</url>
    </pluginRepository>
    <pluginRepository>
      <releases>
        <enabled>false</enabled>
      </releases>
      <snapshots />
      <id>apache.snapshots</id>
      <name>Apache Snapshots Repository</name>
      <url>http://people.apache.org/repo/m2-snapshot-repository</url>
    </pluginRepository>
  </pluginRepositories>
  <dependencies>
    <dependency>
      <groupId>org.apache.servicemix.tutorial</groupId>
      <artifactId>tutorial-file-su</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>

    <dependency>
      <groupId>org.apache.servicemix.tutorial</groupId>
      <artifactId>tutorial-eip-su</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>

    <dependency>
      <groupId>org.apache.servicemix.tutorial</groupId>
      <artifactId>tutorial-jms-su</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <properties>
    <servicemix-version>3.2.3</servicemix-version>
  </properties>
</project>


此时,一个完整的工程创建完成。
在工程目录(servicemix)下运行命令:
mvn install


当编译运行成功后,在目录下 servicemix/tutorial-sa/target 会生成此工程的jar包:tutorial-sa-1.0-SNAPSHOT.jar。

部署:
只要将tutorial-sa-1.0-SNAPSHOT.jar拷贝到 %SERVICEMIX/hotdeploy目录下即可。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics