chapter 7.
creating a message driven bean 【程序编程相关:hibernate基础_7】
【推荐阅读:关于配置支持JFreeChart的Tom】
【扩展信息:hibernate基础_6】
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 :
create a md bean named requestitems under package au.com.tusc.mdb.
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
implement the onmessage method.
deploy the requestitems bean.
create your test client named requestmdbclient under package au.com.tusc.mdb.
add a method named testmdbbean with the following signature and implement it.
public void testmdbbean
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.
... 下一页