JBoss ESB学习笔记6――第五个ESB应用Custom Action

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

JBossESB学习笔记6——第五个ESB应用CustomAction续上篇介绍了第四个ESB应用,本文介绍第五个ESB应用——CustomAction。1概述本实例主要演示了action类的不同使用方式。2新建ESB工程操作过程略。3ESB配置3.1创建消息队列如概述中所描述,这里将创建两个消息队列。在esbcontent文件夹下创建文件jbm-queue-service.xml用于配置消息队列,内容如下:Xml代码?xmlversion=1.0encoding=UTF-8?servermbeancode=org.jboss.jms.server.destination.QueueServicename=jboss.esb.customaction.destination:service=Queue,name=customactionGwxmbean-dd=xmdesc/Queue-xmbean.xmldependsoptional-attribute-name=ServerPeerjboss.messaging:service=ServerPeer/dependsdependsjboss.messaging:service=PostOffice/depends/mbeanmbeancode=org.jboss.jms.server.destination.QueueServicename=jboss.esb.customaction.destination:service=Queue,name=customactionEsbxmbean-dd=xmdesc/Queue-xmbean.xmldependsoptional-attribute-name=ServerPeerjboss.messaging:service=ServerPeer/dependsdependsjboss.messaging:service=PostOffice/depends/mbean/server3.2定义Provider这里将定义一个JMSProvider,同时定义两个消息通道,一个用于监听客户端发来的消息,另一个用作ESB消息通道。内容如下:Xml代码jms-providerconnection-factory=ConnectionFactoryname=JBossMQjms-busbusid=customactionGwChaneljms-message-filterdest-name=queue/customactionGwdest-type=QUEUE//jms-busjms-busbusid=customactionEsbChaneljms-message-filterdest-name=queue/customactionEsbdest-type=QUEUE//jms-bus/jms-provider3.3定义ServiceXml代码servicecategory=CustomActiondescription=CustomActionname=CustomActionServicelisteners/actions//service3.4定义Listener这里定义两个listener,分别用于监听客户端消息和ESB内部消息。其中,前者用于监听客户端消息,因此需要将其is-gateway属性设置为true。Xml代码jms-listenerbusidref=customactionGwChanelis-gateway=truename=JMSListener/jms-listenerbusidref=customactionEsbChanelname=EsbListener/3.5定义Action类下面将定义四个action,分别是:MyBasicAction,StatefulAction,CustomConfigAction和CustomBeanConfigAction,其中,CustomBeanConfigAction类在扩展了AbstractActionLifecycle类的基础上同时实现了BeanConfiguredAction接口。下面对各个action一一介绍。3.5.1MyBasicAction这是一个基本的action,与之前的实例中的action功能类似,主要用于打印输出消息内容。类定义如下:Java代码/************************************************************************pProjectName:customaction/p*pFileName:com.thu.afa.esb.jbossesb.action.MyBasicAction.java/p*pCopyright:Copyright(c)2010/p*pCompany:ahref=***********************************************************************/packagecom.thu.afa.esb.jbossesb.action;importorg.jboss.soa.esb.actions.AbstractActionLifecycle;importorg.jboss.soa.esb.helpers.ConfigTree;importorg.jboss.soa.esb.message.Message;/***pClassName:MyBasicAction/p*pDescription:/p*@authorAfa*@date2010-9-10*@version1.0*/publicclassMyBasicActionextendsAbstractActionLifecycle{protectedConfigTreeconfigTree;publicMyBasicAction(ConfigTreeconfigTree){this.configTree=configTree;}publicMessagenoOperation(Messagemessage){returnmessage;}publicMessageprocess(Messagemessage){System.out.println(Thedefaultprocessmethodcalled);returnmessage;}publicMessageprintMessage(Messagemessage)throwsException{System.out.println(MessageBody:+message.getBody().get().toString());returnmessage;}publicvoidexceptionHandler(Messagemessage,Throwableexception){System.out.println(!ERROR!);System.out.println(exception.getMessage());System.out.println(ForMessage:);System.out.println(message.getBody().get());}}3.5.2StatefulAction该类主要用于演示在一个action配置中同时调用多个方法时,action的实例个数。简单的说,在一个action配置中,不论调用多少个方法,都只会有一个action类的实例。Java代码/************************************************************************pProjectName:customaction/p*pFileName:com.thu.afa.esb.jbossesb.action.StatefulAction.java/p*pCopyright:Copyright(c)2010/p*pCompany:ahref=***********************************************************************/packagecom.thu.afa.esb.jbossesb.action;importorg.jboss.soa.esb.actions.AbstractActionLifecycle;importorg.jboss.soa.esb.helpers.ConfigTree;importorg.jboss.soa.esb.message.Message;/***pClassName:StatefulAction/p*pDescription:/p**@authorAfa*@date2010-9-10*@version1.0*/publicclassStatefulActionextendsAbstractActionLifecycle{protectedConfigTreeconfigTree;privateintcount=0;publicStatefulAction(ConfigTreeconfigTree){System.out.println(\n\nConstructor-+this.getClass().getName()+\n);count++;this.configTree=configTree;}publicMessagenoOperation(Messagemessage){returnmessage;}publicMessagemethodOne(Messagemessage)throwsException{count++;System.out.println(methodOneCalled:+count);returnmessage;}publicMessagemethodTwo(Messagemessage)throwsException{count++;System.out.println(methodOneCalled:+count);returnmessage;}publicMessagedisplayCount(Messagemessage)throwsException{System.out.println(DisplayCountcount=+count+\n);returnmessage;}publicvoidexceptionHandler(Messagemessage,Throwableexception){System.out.println(!ERROR!);System.out

1 / 23
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功