论坛首页 Java企业应用论坛

Eclipse4.2+Jboss7/Jboss-eap-6.0分布式开发 最终篇

浏览 4098 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2013-05-09  

最终篇(终于可以展示分布式调用了)

     经过我们的努力,现在我们马上就能见到Jboss7下面EJB的分布式开发和调用了。下面,我将讲解使用前对吼的配置。

  1. 打开我们的Client端Jboss Server的standalone.xml文件
  2. 添加security-realms,还记得我们第一篇里面在Server端配置的用户名和密码吗?就是下面这个<secret value="MTIzNDU2" />(base64 encoded),我们要把它配置到客户端里面

     
    <security-realms>
        ......
        <security-realm name="ejb-security-realm">
            <server-identities>
                <secret value="MTIzNDU2"/>
            </server-identities>
        </security-realm>
    </security-realms>
  3. 添加outbound-socket-binding在socket-binding-group下,这里的port就是你的Server端Jboss的Remote端口,默认是4447,还记得我们在第一篇中把它+2了吗,然后就2了。哈哈......
    <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="localhost" port="4449"/>
        </outbound-socket-binding>
    </socket-binding-group>
  4. 下面就是<subsystem xmlns="urn:jboss:domain:remoting:1.1">了,添加我们的outbound-connections进去。
    <subsystem xmlns="urn:jboss:domain:remoting:1.1">
        <connector name="remoting-connector" socket-binding="remoting" security-realm="ApplicationRealm"/>
        <outbound-connections>
            <remote-outbound-connection name="remote-ejb-connection" outbound-socket-binding-ref="remote-ejb" username="ejb" security-realm="ejb-security-realm">
                <properties>
                    <property name="SASL_POLICY_NOANONYMOUS" value="false"/>
                    <property name="SSL_ENABLED" value="false"/>
                </properties>
            </remote-outbound-connection>
        </outbound-connections>
    </subsystem>
  5. 还差一个啦啦啦,jboss-ejb-client.xml,要放在EJBClient项目的WEB-INF文件下面
    <jboss-ejb-client xmlns="urn:jboss:ejb-client:1.0">
    	<client-context>
    		<ejb-receivers>
    			<remoting-ejb-receiver outbound-connection-ref="remote-ejb-connection"/>
    		</ejb-receivers>
    	</client-context>
    </jboss-ejb-client>
     
  6. 下面就是启动Server端的Jboss了,还有两点要注意的啊。-b 0.0.0.0和-Djboss.node.name=nodeone,要加到Jboss的启动参数里。Jboss默认的是-b 127.0.0.1这样他只能监听到Localhost过来的请求,即使你在本机使用本机IP进行请求都不行。-Djboss.node.name=nodeone是因为你在本机启动两台JbossServer,当Client端的Server注册Remote EJB Reciever的时候会因为server端已经用默认的node name注册了一个Local EJB Reciever而导致注册失败。当然你有两台电脑去做这个事情也就不用改node name了。
    -Djboss.node.name=nodeone -b 0.0.0.0
     
  7. 这一步可做可不做,Client端Server的启动参数加上-Djboss.node.name=nodetwo -b 0.0.0.0,因为已经把Server的默认node name改掉了,不会冲突了。如果你尝试电脑1(Server端),电脑2(Client端),电脑3启动浏览器访问EJBClient部署的Servlet,那么 -b 0.0.0.0就不能少了。
  8. 下面我们来试试吧,奥,想起来了。还要把Client端Server的<subsystem xmlns="urn:jboss:domain:logging:1.1">改一下,就是这句<level name="DEBUG"/>,当然这个是在standalone.xml文件下面,这样虽然会蹦出一大堆你看不懂的Log信息,但是这些log里面有一条对我们是有用的,看到这个就证明我们成功了。
    <subsystem xmlns="urn:jboss:domain:logging:1.1">
        ......
        <root-logger>
            <level name="DEBUG"/>
            <handlers>
                <handler name="CONSOLE"/>
                <handler name="FILE"/>
            </handlers>
        </root-logger>
    </subsystem>
     
  9. 先启动Server端的Jboss,然后启动Client端的Server。然后集中精神啊(其实你可以搜一下nodetwo),哈哈,找到下面这一句。如果你的Console设置的太小,可能被新的信息覆盖了,你可以调的大一点,或者去Jboss的log目录去看。
    14:28:37,385 INFO  [org.jboss.ejb.client.remoting] (MSC service thread 1-3) EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@1c8dfe6, receiver=Remoting connection EJB receiver [connection=Remoting connection <163769>,channel=jboss.ejb,nodename=nodeone]} on channel Channel ID ce78e436 (outbound) of Remoting connection 00ea5d87 to 127.0.0.1/127.0.0.1:4449
  10. 好了,下面我们在浏览器中输入http://localhost:8080/EJBClient/TestRemoteEJB
  11. Client端Jboss的Console截图:

     Server端Jboss的Console截图:

     
  12. 好了大功告成。。。
  • 大小: 17.3 KB
  • 大小: 49.1 KB
  • 大小: 14.3 KB
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics