Skip to main content

JEAP 6 - 從Server 上Remote 呼叫其他Server 上的 Clustered EJB


EJB Server 連結需要在兩邊的Server 做一些基本認證的連接點,
我們把EJB 設定為Cluster, 所以需要有HA 的機制,不會設定的,請到前面幾篇去看(連結)。
再啓動另一台JBoss 去呼叫兩個Cluster 的EJB instance.

呼叫的那個WAR (或是EAR) 請放在我們稱作Client端,被呼叫的EJB Server 我們叫接收端。

基本上接收端的機器不需要做特別的設定,僅需要建立一個Application user 即可。 所以,請到JBoss_INSTALL_PATH/bin 下,執行 or add-user.bat 如下
(如果你是Domain 的話,僅需要在Domain controller 下執行,如果你是在Standalone的話,請每個Server 都要執行喔!)

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 : christinaejb (使用者名稱)
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)[  ]: (使用者的角色,在這裡直接空白)
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? yes
To represent the user add the following to the server-identities definition <secret value="Y2hyaXN0aW5hZWpiNzk=" /> (等一下要用到的)



這裡才是需要注意的地方,因為這裡我們要在Server上設定可以對外聯接EJB的Connector, 沒錯,就是在Server上開個洞去連結EJB, 因為是開個連結,所以想當然爾就要一些安全性上的設定拉!請到 standalone-full.xml  or standalone-full-ha.xml 或是 domain.xml 裡面的 full or full-ha 的Profile下設定

1. 設定連接的密碼,在下面紅色的地方,打入你剛剛加密後得到的密碼

            <security-realm name="ejb-security-realm">
                    <secret value="dsHJfKDhhsjdas=="/>

2. 設定對外聯接的IP 與Socket 位置,也就是你的EJB Server 對外的remote IP 與port 通常default 都是 4447

<socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
        <outbound-socket-binding name="remote-ejb">
            <remote-destination host="IP_ADDRESS" port="4447"/>
        <outbound-socket-binding name="remote-ejb1">
            <remote-destination host="IP_ADDRESS" port="4547"/>

3. 到Remote subsystem 下面設定你對外的連結名稱

<subsystem xmlns="urn:jboss:domain:remoting:1.1">
     <remote-outbound-connection name="remote-ejb-connection" outbound-socket-binding-ref="remote-ejb" security-realm="ejb-security-realm" username="christinaejb">
  <property name="SASL_POLICY_NOANONYMOUS" value="false"/>
  <property name="SSL_ENABLED" value="false"/>

      <remote-outbound-connection name="remote-ejb-connection1" outbound-socket-binding-ref="remote-ejb1" security-realm="ejb-security-realm" username="christinaejb">
  <property name="SASL_POLICY_NOANONYMOUS" value="false"/>
  <property name="SSL_ENABLED" value="false"/>

1. remote-ejb-connection 就是你給這個remote connection的名字
2. remote-ejb 剛剛我們設定對外對應的socket名稱
3. ejb-security-realm 剛剛設定安全密碼的名稱
4. christinaejb 建立在ejb Server上的使用者名字
又因為這次是兩個server, 所以分別建立的兩次!

這樣Server上的設定都完成了, 接下來就是要到程式裡面去設定,告訴你的WAR 或是 EAR 你需要用哪幾個remote的 EJB connection

建立一個  jboss-ejb-client.xml , 如果是EAR, 請放在 EAR/META-INF, 如果是WAR 請放在WAR/META-INF


<jboss-ejb-client xmlns="urn:jboss:ejb-client:1.0">
            <remoting-ejb-receiver outbound-connection-ref="remote-ejb-connection"/>
            <remoting-ejb-receiver outbound-connection-ref="remote-ejb-connection1"/>

這裡很容易看出來,他其實就是告訴EAR/WAR 你有哪幾個remote ejb connection 可以用。

以上所有的設定都完成了,寫在JSP or Servlet中的code 也沒什麼大的驚喜,與EJB Client相同。

protected void doInvoke(){
   Context context=null;
      final Hashtable jndiProperties = new Hashtable();
      jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
      context = new InitialContext(jndiProperties);
   }catch (Exception e) {

   MyStatusBeanRemote remote;
   try {
      remote = (MyStatusBeanRemote)context.lookup("ejb:MyEJBProjectEAR/MyEJBProject//MyStatusBean!redhat.remotebeans.MyStatusBeanRemote?stateful");
   } catch (NamingException e) {
之後啓動Server, 可以看到Server 去連結兩個ejb的client. (有個lookup 的小bug,目前我還在找patch中,會出error 但是基本上不會影響工作。AS7-4755  )



Popular posts from this blog

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 …

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

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 …