JBoss ESB with Eclipse入门例子

1 : 下载JBOSS ESB

http://www.jboss.org/jbossesb/downloads.html

 

本例使用版本4.7

2:安装Eclipse JBOSS plugin

http://download.jboss.org/jbosstools/updates/nightly/trunk/

help-->install new soft-->新增一个 location输入上面地址

有许多插件,只需选择JBoss AS Tools plugin和JBoss ESB Tools plugin

 

3: 在Eclipse里新建一个ESB项目:

安装好插件后点新建一个ESB项目 "New-->ESB-->ESB Project".

 

 

 

 

服务器可以选择JBOSS 或者ESB Server

 

Step 4:创建ESB project
首先在esbcontent/META-INF 下新建一个配置文件: jboss-esb.xml
输入如下内容

<?xml version = "1.0" encoding = "UTF-8"?>
<jbossesb xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.2.0.xsd"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.2.0.xsd http://anonsvn.jboss.org/repos/labs/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.2.0.xsd"
 parameterReloadSecs="5">
 <providers>  
          <jms-provider name="JBossMQ" connection-factory="ConnectionFactory">  
              <jms-bus busid="quickstartGwChannel">  
                  <jms-message-filter  
                      dest-type="QUEUE"  
                      dest-name="queue/quickstart_helloworld_Request_gw" />  
              </jms-bus>  
              <jms-bus busid="quickstartEsbChannel">  
                  <jms-message-filter  
                      dest-type="QUEUE"  
                      dest-name="queue/quickstart_helloworld_Request_esb"  />  
              </jms-bus>  
  
          </jms-provider>  
      </providers>  
         
      <services>  
        <service    
            category="FirstServiceESB"    
            name="SimpleListener"    
            description="Hello World">  
            <listeners>  
                <jms-listener name="JMS-Gateway"  
                    busidref="quickstartGwChannel"  
                    is-gateway="true"/>  
                <jms-listener name="helloWorld"  
                              busidref="quickstartEsbChannel" />  
            </listeners>  
            <actions mep="OneWay">  
                   <action name="action1"    
                    class="org.jboss.soa.esb.samples.quickstart.helloworld.MyJMSListenerAction"    
                    process="displayMessage"/>  
            </actions>       
        </service>  
      </services>  
 
 </jbossesb>

 <actions mep="OneWay"> 
                   <action name="action1"   
                    class="org.jboss.soa.esb.samples.quickstart.helloworld.MyJMSListenerAction"   
                    process="displayMessage"/> 
这个类根据自己实际路径修改

 

新建MyJMSListenerAction 类

 

package org.jboss.soa.esb.samples.quickstart.helloworld;

import org.jboss.soa.esb.actions.AbstractActionLifecycle;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.message.Message;

public class MyJMSListenerAction extends AbstractActionLifecycle{
	protected ConfigTree  _config;   
    
	  public MyJMSListenerAction(ConfigTree config) {    
	   _config = config;    
	  }    
	  
	  public Message displayMessage(Message message) throws Exception{   
	           
	   System.out.println("Body: " +message.getBody().get());          
	   return message;    
	                   
	  }   

}

 

 

在esbcontent目录下新建: jbm-queue-service.xml .

<?xml version="1.0" encoding="UTF-8"?>
<server>
  <mbean code="org.jboss.jms.server.destination.QueueService"
    name="jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_esb"
    xmbean-dd="xmdesc/Queue-xmbean.xml">
	<depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
	<depends>jboss.messaging:service=PostOffice</depends>
  </mbean>
  <mbean code="org.jboss.jms.server.destination.QueueService"
    name="jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_gw"
    xmbean-dd="xmdesc/Queue-xmbean.xml">
    <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
	<depends>jboss.messaging:service=PostOffice</depends>
  </mbean>
</server>

 

最后新建 esb 部署文件 deployment.xml 在 META-INF 文件夹下:

<jbossesb-deployment>  
<depends>jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_esb</depends>    
  <depends>jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_gw</depends>  
</jbossesb-deployment>

 

 

发布工程到jboss服务器,并启动服务器

建立一个测试Client

package org.jboss.soa.esb.samples.quickstart.helloworld.test;

import java.util.Properties;

import javax.jms.JMSException;
import javax.jms.ObjectMessage;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class SendJMSMessage {
	QueueConnection conn;   
    QueueSession session;   
    Queue que;   
       
       
    public void setupConnection() throws JMSException, NamingException   
    {   
        Properties properties1 = new Properties();   
        properties1.put(Context.INITIAL_CONTEXT_FACTORY,   
                "org.jnp.interfaces.NamingContextFactory");   
        properties1.put(Context.URL_PKG_PREFIXES,   
                "org.jboss.naming:org.jnp.interfaces");   
        properties1.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");   
        InitialContext iniCtx = new InitialContext(properties1);   
  
        Object tmp = iniCtx.lookup("ConnectionFactory");   
        QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;   
        conn = qcf.createQueueConnection();   
        que = (Queue) iniCtx.lookup("queue/quickstart_helloworld_Request_gw");   
        session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);   
        conn.start();   
        System.out.println("Connection Started");   
    }   
       
    public void stop() throws JMSException    
    {    
        conn.stop();   
        session.close();   
        conn.close();   
    }   
       
    public void sendAMessage(String msg) throws JMSException {   
           
        QueueSender send = session.createSender(que);           
        ObjectMessage tm = session.createObjectMessage(msg);   
           
        send.send(tm);           
        send.close();   
    }   
          
       
    public static void main(String args[]) throws Exception   
    {                      
        SendJMSMessage sm = new SendJMSMessage();   
        sm.setupConnection();   
        sm.sendAMessage("Hello World");//这里输入消息文本    
        sm.stop();    
    }   
}

 

运行客户端,会在服务器端看到

14:30:30,046 INFO  [STDOUT] Body: Hello World

 


 

你可能感兴趣的:(eclipse,jboss,jms,SOA,JBossTools)