Java

本类阅读TOP10

·使用MyEclipse开发Struts框架的Hello World!(录像1)
·Tomcat5.5.9的安装配置
·Jsp 连接 mySQL、Oracle 数据库备忘(Windows平台)
·hibernate配置笔记
·构建Linux下IDE环境--Eclipse篇
·linux下Tomcat 5.0.20 与 Apache 2 安装/集成/配置
·AOP编程入门--Java篇
·创建文件夹和文件的java代码范例
·Java常见面试题(含答案)
·Java编写的计算器程序及源代码

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
Tutorial for building J2EE Applications using JBOSS and ECLIPSE (7)

作者:未知 来源:月光软件站 加入时间:2005-6-5 月光软件站

Chapter 7.

Creating a Message Driven Bean

This chapter covers how to create a Message Driven Bean (MDB) EJB component. We will create two MDB beans, DeliverItems and RequestItems as shown below. The DeliverItems bean will replenish the stocks of various items within MyStore, and the RequestItems bean will send requests to various suppliers to deliver items which are out of stock. The MyStore manager will issue/send this request.




Note : Both message-driven beans access the StoreAccess bean through its remote interface, even though the StoreAcessBean is in the same JVM. This is because we have implemented StoreAccessBean as a Remote Bean, so it only exposes its remote interface. However, in accessing the Manager and Item beans, which are also used by these message-driven beans we can use their local interfaces as they are in the same JVM, and we have exposed their local interfaces.

Tasks :

  1. Create a MD bean named RequestItems under package au.com.tusc.mdb.

  2. Create an Immutable Value Object named RequestItem under package au.com.tusc.mdb. Add attributes and implement their accessor and mutator methods. The attributes are:

    private String username

    private String passwd

    private String itemID

    private int quantity

  3. Implement the onMessage method.

  4. Deploy the RequestItems Bean.

  5. Create your test client named RequestMDBClient under package au.com.tusc.mdb.

  6. Add a method named testMDBBean with the following signature and implement it.

    public void testMDBBean

  7. Run your client and test the bean.


Create RequestItems MDB Bean :


Go To Package Explorer > Expand Mystore (project) node > select src, right click and a menu will pop up.

On the pop up menu > New > Lomboz EJB Creation Wizard.

Enter package name au.com.tusc.mdb, bean name RequestItems and select bean type as Message Drive Bean (Queue) as shown below.




Press Finish.

This will create a package named au.com.tusc.mdb under src and RequestItemsBean within that package as shown below.


Note : Message-driven beans listen for messages from a JMS Producer, which gets information from a producer (perhaps another bean) and transfers it to the relevant Consumer bean. Since it is only responsible for processing such messages, it doesn't need any helper classes such as Remote and RemoteHome interfaces, Util classes, DAO class, etc. like our previous types of beans. The only helper classes we have to create are immutable value objects, which will be responsible for holding the information extracted from messages and then transferred to the bean(s).

Let's examine what methods and tags are generated by the EJB creation wizard..

It creates one @ejb.bean tag which assigns the name, transaction type, destination type and some other properties as shown below.




Unlike our previous beans it has a setMessageContext method for setting the context.




It has ejbCreate and ejbRemove methods like the other types of beans, as shown below.




It has a new method named onMessage which is the one of significance to us, where all the business logic will be written (as shown below).




Once a message is received from the JMS producer as a Message object, its data is extracted and filled into the immutable value object and then transferred to the relevant bean. This is covered later on in this chapter.

Now, before we add any functionality, create a class or immutable value object for extracting information from the message.

Create Immutable Value Object RequestItem :

Go to src > under package au.com.tusc.mdb > New >Class


相关文章

相关软件




月光软件程序下载编程文档电脑教程网站设计网址导航网络文学游戏天地幽默笑话生活休闲写作范文安妮宝贝
电脑技术编程开发网络专区谈天说地情感世界游戏元素分类游戏热门游戏体育运动手机专区业余爱好影视沙龙
音乐天地数码广场教育园地科学大观古今纵横谈股论金人文艺术医学保健动漫图酷二手专区地方风情各行各业

月光软件站·版权所有