Skip to main content

Red Hat Fuse/A-MQ - 小技巧, 開發Fuse 專案時的 Maven pom.xml


Red Hat JBoss A-MQ 是高效能,高彈性的訊息平台
Red Hat JBoss Fuse 是開源的 Enterprise Service Bus (ESB) ,他最大的好處就是可以讓你擁有彈性的安裝大小,讓你可以整合跨越不同資料中心的服務語系統。 在 Fuse裡面, 還有 Apache Camel 提供一個功能齊全,容易使用和可以直接使用的框架,所以可以更快速的開發整合專案。Fuse 6.1所提供的元件在這裡!

在開發A-MQ 的程式或是Camel 的整合系統的時候,我們都會用Maven 來管理程式. 可是常常因為不同版本的關聯,造成程式間的衝突,這種問題超級羅生門,又難抓。介紹幾個小技巧,讓你可以更簡單的管理你的pom.xml, 讓你可以專注在開發上,不要為了設定一個頭兩個大。

不管你是透過archetype 或是乾脆起一個空白的maven專案,可以透過一些微幅的調整讓你管理起來更簡單,所以,第一件要解決得事情就是一堆的Artifact 的關聯版本,要一個一個的查FUSE 6.1 或是 AMQ 6.1 用到哪些實在是有夠麻煩的,所以我們只要在pom.xml 裡面增加 "dependencyManagement" 這個tag 就會自動地去管理,還有抓取我們需要的版本,是不是很棒!!

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.jboss.fuse.bom</groupId>
                <artifactId>jboss-fuse-parent</artifactId>
                <version>${jboss.fuse.bom.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

我們把 FUSE 版本獨立出來,以後你可以隨著版本跟著變更,這次是 6.1, 所以請在properties 的tag裡面標明 6.1.0.redhat-379

    <properties>
        <jboss.fuse.bom.version>6.1.0.redhat-379</jboss.fuse.bom.version>
    </properties>

這樣我們在關聯性上面,就不需要加版本囉!

For example :
    <dependency>
         <groupId>org.apache.camel</groupId>
         <artifactId>camel-core</artifactId>
    </dependency>

第二個部分就是要如何讓你在部署的時候可以更輕鬆,因為Fabric 的部署是可以直接跟maven 聯結的。所以,先設定登入Fabric 的帳號密碼,這個就必須設在你的maven 的 settings.xml 裡面拉!路徑  ~/.m/setting.xml,你可以同時設定多組密碼,預設值是fabric8.upload.repo,但是如果你同時在開發多個專案,可能也會用到多個吧~


    <servers>
      <server>
        <id>fabric8.upload.repo</id>
        <username>Username4Default</username>
        <password>Password4Default</password>
      </server>
      <server>
        <id>fabric8.demo.repo</id>
        <username>Username4DEMO</username>
        <password>Password4DEMO</password>
      </server>
    </servers>

把下面的 Maven Plugin 加上設定放到你的pom.xml 裡面,

    <plugins>
      <plugin>
        <groupId>io.fabric8</groupId>
        <artifactId>fabric8-maven-plugin</artifactId>
        <configuration>
          <profile>${fabric8.profile}</profile>
          <serverId>${fabric8. serverId}</serverId>
        </configuration>
      </plugin>
    </plugins>

把你想要安裝在Frabric 上的profile 名字放在 fabric8.profile 下, 然後把你想要更新的 serverID (對應到你設在 setting.xml 的 ID ) 放在 fabric8.serverId之下.

    <properties>
        <fabric8.profile>blogDemo</fabric8.profile>
        <fabric8.serverId>fabric8.projectA.repo</fabric8.serverId>
    </properties>


因為我們要deploy 上去的是一個Karaf 的 OSGI 執行容器,確定我們的專案是包成一個bundle, 請加入以下的plugin. (因為有些舊的archetype 沒幫你加,有時候要自己加上去。)這個plugin 就會幫你自動產生一個bundle 要用到的 MANIFEST-FILE 檔案。

對了,不要忘記把你取的Bundle 名字放在 Bundle-SymbolicName 之下, 跟把你專案用到定義的java 目錄放到Private-Package tag之下喔.

      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <version>2.3.7</version>
        <extensions>true</extensions>
        <configuration>
          <instructions>
            <Bundle-SymbolicName>YourBundleName</Bundle-SymbolicName>
            <Private-Package>YourJavaSourcePackage</Private-Package>
            <Import-Package></Import-Package>
          </instructions>
        </configuration>

      </plugin>

有一個我沒有特別要說的是maven 的程式庫路徑設定,基本上,有很多個repo 你可以選擇,而且如果是我的話,我會把它放在setting.xml 裡面。但是放在pom.xml 也沒什麼不對。所以你可以自己選你要放哪裡,還有連到哪個你喜歡的程式庫。

下面提供一個範例給大家參考囉!



  4.0.0

  org.blogdemo
  tipdemo
  bundle
  1.0.0-SNAPSHOT

  Christina's Blog Demo
  http://wei-meilin.blogspot.com/2014/06/red-hat-fusea-mq-tips-maven-pomxml-for.html

  
    UTF-8
    UTF-8
    6.1.0.redhat-379
    blogDemo
    fabric8.demo.repo
  

  
    
      release.fusesource.org
      FuseSource Release Repository
      http://repo.fusesource.com/nexus/content/repositories/releases
      
        false
      
      
        true
      
    
    
     ea.fusesource.org
     FuseSource Community Early Access Release Repository
     http://repo.fusesource.com/nexus/content/groups/ea
     
      false
     
     
      true
     
        
    
      snapshot.fusesource.org
      FuseSource Snapshot Repository
      http://repo.fusesource.com/nexus/content/repositories/snapshots
      
        true
      
      
        false
      
    
  

  
    
      release.fusesource.org
      FuseSource Release Repository
      http://repo.fusesource.com/nexus/content/repositories/releases
      
        false
      
      
        true
      
    
    
     ea.fusesource.org
     FuseSource Community Early Access Release Repository
     http://repo.fusesource.com/nexus/content/groups/ea
     
      false
     
     
      true
     
          
    
      snapshot.fusesource.org
      FuseSource Snapshot Repository
      http://repo.fusesource.com/nexus/content/repositories/snapshots
      
        true
      
      
        false
      
    
  
  
        
            
                org.jboss.fuse.bom
                jboss-fuse-parent
                ${jboss.fuse.bom.version}
                pom
                import
            
        
     
  
    
      org.apache.camel
      camel-core
    
    
      org.apache.camel
      camel-spring
    

    
    
      org.slf4j
      slf4j-api
    
    
      org.slf4j
      slf4j-log4j12
    
    
      log4j
      log4j
    

    
    
      org.apache.camel
      camel-test-spring
      test
    
  

  
    install

    
      
        org.apache.maven.plugins
        maven-compiler-plugin
        2.5.1
        
          1.6
          1.6
        
      
      
        org.apache.maven.plugins
        maven-resources-plugin
        2.6
        
          UTF-8
        
      

      
      
        org.apache.camel
        camel-maven-plugin
        2.12.0.redhat-610379
      

      
      
        org.apache.felix
        maven-bundle-plugin
        2.3.7
        true
        
          
            tipdemo
            org.blogdemo.tipdemo.*
            
          
        
      
      
      
      
     io.fabric8
     fabric8-maven-plugin
     
     
       ${fabric8.profile}
       ${fabric8. serverId}
     
   
    
  




現在,都設定好了,那一定要來跑一下確定我沒有唬爛囉~ (如何建立專案,請看我另一篇文章 - 還沒空做)
首先,要講一個廢話,但是很重要,請你先確認你的 Red Hat JBoss Fuse 是啓動的. 到 http://IP:8181/ 然後登入,到wiki 下面,看一下她現在給你的profile.


隨便到一個指令畫面,到你的專案路徑下,對,就是你這次建的pom.xml 的路徑下
先來編譯還有安裝一下,執行

mvn install




然後我們就可以開始部署囉~

mvn fabric8:deploy -Dfabric8.version=1.0




如果沒出什麼差錯的話,你應該就可以看到 BUILD SUCCESS, 回到瀏覽器上, 在同樣的頁面上,你應該要可以看到我們剛剛建立的profile 才對。



建一個執行容器來跑跑看,加入我們剛剛部署的blogDemo, 還有要跑FUSE 的一些profile



到 runtime/container 畫面, 你應該就會看到執行容器成功的啟動了。Log 也看到成功執行的內容。


當然,我們也可以改一改後,上傳不同的版本。
根據你指派給各個執行容器的版本,他們自己就會去對應到對的程式,然後執行。

A. 修改你的專案內容,


B.編譯,安裝跟部署 (這次是2.0 版本)

mvn install

mvn fabric8:deploy -Dfabric8.version=2.0

C. 在建立一個執行容器,這次安裝版本2.0


D. 看一下這個 "anothercontainer" 跑的log 是不是2.0版本的呢~?就醬!簡單吧!





Comments

Popular posts from this blog

Red Hat JBoss Fuse/A-MQ - Fuse and A-MQ Version 6.3 GA is released!

Fuse and A-MQ 6.3 GA has just went out. Maybe, you would think this is just only a minor version release why should I care? Hold your thoughts on that! Because they have done a lot of improvements and also added many new features into this release.

Besides various bug fixes and making sure Fuse Fabric is much more stable. There are two major change in this version update:

New Tooling in JBoss Developer Studio (JBDS) 9.1 GA. Newer Apache Camel version – Camel v2.17. I was really impressed by the work put in to make developing Camel application much simpler. First is the installation of tooling itself. Now it has a all-in-one installer so you don't need to worry about which plugins you need to check. See the videos below to see the new "Getting Started" of Fuse 6.3.



And If you notice from the above video, the presentation of camel route in JBDS has also updated. It fixed some of the miss representation of logic and making it easier to read.

Old Camel Route
New Camel Route
On …

Fuse Integration Service - Setup JBDS and create first quickstart application

Before we go and start creating our first application, I want to show you how to setup your JBoss Developer Studio, create a small application from the quickstart example and then running it on Fuse Integration Service.

I am using JBoss Developer Studio version 9, you can find it here.
After download the

jboss-devstudio-9.0.0.GA-installer-eap.jar
double-click it, and start installing with default values.

After successful installation, we will need install the plugins for Fuse, on JBoss Central view, select software update, select enable early access.


And select JBoss Fuse Development for the plugin,


Click on install, and we are all set to go!

First thing first, we want to create a Fuse project to deploy on the base of Fuse Integration Service, which is OpenShift. If you have not installed it, please go back to my previous post for instructions. So on your JBDS, right click and start creating the project. Select new, maven project, if you have installed the plugin correctly, you should …

Red Hat JBoss Fuse - Getting Started with Fuse Integration Service 2.0 Tech preview

I just realized that I did not do a getting started for Fuse Integration Service 2.0 Tech preview before I did the pipeline demo, thanks for those of you who reminded me! :)

To get started with FIS 2.0, for people who has just getting to know the technology, here is how I interpret it. Basically, it's divide into two aspect,

1. Integration development, FIS uses Apache Camel as the core technology that creates, orchestrate, compose microservices into a super lightweight thin integration layer, and become the API provider and service orchestrator through exposing RESTful or messaging service endpoints. And you can choose to either package and run it with Spring-Boot or Karaf.


2. Application Deployment and Management, FIS takes advantages of OpenShift platform, and allows you to separately deploy the micro-integration service among distributed environment, at the same time takes care of the failover, high availability, load balancing and service lookup problem for you.


So, now we know …