Skip to main content

JEAP 6 - HornetQ 的設定

在台灣最熟JBoss Messaging 應該就是他了

HornetQ 是一個MOM (Message-oriented Middleware) 幫忙管理messaging的系統平台。
聽起來可能很陌生,但是如果我講到 Queue 與 Topic 可能就會知道拉。

這次先已開發為主的Standalone 方式建立。
(如果你沒有安裝過JEAP 6 Standalone請到這裡參考)

1. 確定你使用的模組是到 $JBOSS_INSTALL_PATH/standalone/configuration/standalone-full.xml
因為我們需要用到messaging 的subsystem

所以,請將$JBOSS_INSTALL_PATH/standalone/configuration/standalone-full.xml rename 成 standalone.xml

2. 啟動Standalone Server

3. 到http://localhost:9990 去,登入後,到Profile 下,的Messaging 下的 Destination. 左邊有個default,按下view 進入

按下ConnectionFactory 裡面內建已經有了2 個 ConnectionFactory,一個是在同一個VM instance 可以取用的,一個是Remote 可以 lookup 到的 ConnectionFactory。
看到裡面使用connector 都是 netty, 但是如果你的message size 都很小的話,建議使用netty-throughput。因為它的可以batch delay (batch 一段時間 這對小的msg 的throughput 會有很好的影響),direct-deliver也設定成false .

4. 建立queue的使用者, 每個queue 要存取,都必須要有id 跟 密碼認證

Lin-Christinateki-MacBook-Air:bin weimeilin$ ./

What type of user do you wish to add? 
 a) Management User ( 
 b) Application User ( 
(a): (告訴系統是AP在用的)

Enter the details of the new user to add.
Realm (ApplicationRealm) : 
Username : christina (使用者名稱)
Password : (輸入密碼)
Re-enter Password : (輸入密碼)
What roles do you want this user to belong to? (Please enter a comma separated list, or leave blank for none)[  ]: remoteJMS (使用者的角色,在這裡我自定為remoteJMS)
About to add user 'christina' for realm 'ApplicationRealm'
Is this correct yes/no? yes
Added user 'christina' to file '/Applications/demo/jboss-eap-6.0/standalone/configuration/'
Added user 'christina' to file '/Applications/demo/jboss-eap-6.0/domain/configuration/'
Added user 'christina' with roles remoteJMS to file '/Applications/demo/jboss-eap-6.0/standalone/configuration/'
Added user 'christina' with roles remoteJMS to file '/Applications/demo/jboss-eap-6.0/domain/configuration/'
Is this new user going to be used for one AS process to connect to another AS process e.g. slave domain controller?
yes/no? no

5. 建立使用的Queue
回到Console 上,一樣到Profile 下的Messaging, 到Destinations, 選擇Queue/Topics  到Queue 的Tab 鍵,按下add 新增Queue

寫上Queue 的名字,
這裡我自己取名叫 SampleQ
加上可以由外部lookup 到的JNDI 名稱。

之後,增加安全性的設定。需要告訴JBoss, queue 要用哪一個帳號進入 (預設是guest/guest, 如果你沒有照上一步設定 User 的話。)

選擇Security Settings 按下 Add 增加。

在Pattern 中正確的定義,只有sampleQ 可以用remoteJMS, 如果你想全部用,那就直接加另一個 # 就好。

Pattern: jms.queue.sampleQ
Role: remoteJMS


現在來寫個JMS Client 與 MDB 確認。

1. 寫一個JMS Client 專門用remote 的去把message 放到queue裡面。
在寫這個Client 的時候有一些步驟要提醒一下。

a. 不要忘記去把 $JBOSS_INSTALL_PATH//bin/client/jboss-client.jar 放到class path.
b. 在lookup 的 環境語法也有修改, INITIAL_CONTEXT_FACTORY 從之前的org.jnp.interfaces.NamingContextFactory 變成 org.jboss.naming.remote.client.InitialContextFactory
而port 的位置從 1099 改到 4447 (如果有改port offset的話,請自行累加)


跑了之後,登入http://localhost:9090 的runtime , JMS Destinations 之下。左邊的Queue 之下,在可以In-Flight Message 看到queue 裡面有產生了1 個message .

2. 建一個 EJB 的專案,裡面寫一只MDB, 去收queue

放上去Deploy 之後,就可以看到 message 被 MDB 收下來了

到Console 上可以看到message 也收走拉!最下面那個1 是累計的message 數量



Ethan Chen said…
Dear 老師,我是之前有上過課的PIC學員,我想請問一個問題,上次課堂使用的jboss,可以用win服務建立起來嗎?而不需要一直開著command視窗
Christina said…
上一堂有用過JBoss EAP 5 跟 7, 你說的是哪個哩?
我晚點寫一篇Window Service 好了。
Black Tang said…
quest/quest 筆誤應該是 guest/guest :-)
Christina Lin said…
彼得 said…
請教一下,Messages Added這個累積的數字只是計數用嗎?是否可以清除呢? 累積太多會不會影響系統呢?(目前累積到666567) 謝謝您

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 …

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 …

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

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 …