Tải bản đầy đủ - 0 (trang)
Chapter 29. Exercises for Chapter 12

Chapter 29. Exercises for Chapter 12

Tải bản đầy đủ - 0trang

29.1Exercise12.1:JMSasaResource

Thisexerciseisentirelybasedonthebeansimplementedin

Exercise11.2.You'llmodifytheTravelAgentEJBsoitpublishes

atextmessagetoaJMStopicwhenitcompletesareservation.

You'lllearnhowtocreateanewJMStopicinJBoss,and

configureyourbeantouseJMSasaresource.You'llalsobuilda

clientapplicationthatwillsubscribetothistopicanddisplayany

publishedmessage.Tocompletenewreservations,you'lluse

oneoftheclientapplicationscreatedfortheprecedingexample.



29.1.1StartUpJBoss

IfJBossisalreadyrunningthereisnoreasontorestartit.



29.1.2InitializetheDatabase

BecausetheexerciseusestheProcessPaymentEJBusedin

recentexercises,thedatabasemustcontainthePAYMENTtable.

ThecreatedbanddropdbAnttargets,Javacode,andclients

herehavebeenborrowedfromExercise11.1.

Ifyouhaven'talreadydroppedthePAYMENTtableafterrunning

theexamplesinExercise11.2,dosonowbyrunningthe

dropdbAnttarget.

C:\workbook\ex12_1>antdropdb

Buildfile:build.xml



prepare:



compile:



dropdb:

[java]Lookinguphomeinterfaces..

[java]Droppingdatabasetable...



BUILDSUCCESSFUL



Thenre-createthePAYMENTdatabasetablebyrunningthe

createdbAnttarget

C:\workbook\ex12_1>antcreatedb

Buildfile:build.xml



prepare:



compile:



ejbjar:



createdb:

[java]Lookinguphomeinterfaces..

[java]Creatingdatabasetable...



OntheJBossconsole,thefollowinglinesaredisplayed:

INFO[STDOUT]CreatingtablePAYMENT...

INFO[STDOUT]...done!



Ifyou'rehavingtroublecreatingthedatabase,shutdownJBoss.Then

runtheAntbuildtargetclean.db.Thiswillremovealldatabasefiles

andallowyoutostartfresh.



Thepersistenceofallotherentitybeansusedinthisexerciseis

managedbythecontainer(CMP),soJBosswillcreatethe

neededtablesforthemautomatically.



29.1.3CreateaNewJMSTopic

BecausetheTravelAgentEJBwillpublishmessagesinaJMS

topic,you'llhavetocreatethisnewtopicinJBoss.Thisexercise



walksyouthroughtwodifferentwaystocreateanewJMS

topic:throughanXMLconfigurationfileandthroughtheJBoss

JMXHTTPconnector.



29.1.3.1AddingaJMSTopicthrougha

configurationfile

ThemostcommonwaytosetupaJMStopicistouseanXML

configurationfile.Asyoulearnedintheinstallationchapter,

everycomponentinJBossisaJMXMBeanthatcanbehotdeployed.Thispartoftheexerciseshowsyouhowtowritea

JMXMBeandefinitionforanewJMStopic.

YoucanfindtheJMXconfigurationfileinthe

ex12_1/src/resources/servicesdirectory.



29.1.3.2jbossmq-titantopic-service.xml




name="jboss.mq.destination:service=Topic,

name=titan-TicketTopic">


>jboss.mq:service=DestinationManager







EachsetofMBeansinaJMXconfigurationfilemustbedefined

withinatag.AnMBeanitselfisdeclaredinan

tag.TheonlyMBeandeclarationinthisfiledefinesthe

actualJMStopicyou'llusefortheexamplecodeinthischapter.

EachMBeanisuniquelyidentifiedbyitsname,calledan

ObjectName.JMXObjectNamescanincludeanynumberofkeyvalueparameterstodescribetheMBeanfurther.Inourcase,

theMBeanclassrepresentingtheJMStopicisdeclaredfirst

(org.jboss.mq.server.jmx.Topic),alongwithitsJMX

ObjectName(jboss.mq.destination:service=Topic,

name=titan-TicketTopic).ForJMStopicMBeans,asingle

parameterisuseful:name.ThisiswherethenameoftheJMS

topicisdefined(titan-TicketTopic).

Onethingtonoteisthattheapplicationservermustdeploythe

DestinationManagerMBeanbeforeanyqueueortopicis

deployed.Thisdependencyisdeclaredinjbossmq-titantopicservice.xml'sdependstag.JBosswilltakecareofsatisfyingthis

dependencyandmakesurethetitan-TicketTopicisn't

starteduntiltheDestinationManagerMBeanhasfinished

initializingandisreadytoprovideservicestonewqueuesand

topics.CopyingthisfileintotheJBossdeploydirectorywillhotdeploytheJMStopicandmakeitreadyforuse.

We'vedefinedamake-topicAnttargetfordeployingthetopic

bean.Runthistargettocopyjbossmq-titantopic-service.xml

intoJBoss'sdeploydirectory:

C:\workbook\ex12_1>antmake-topic

Buildfile:build.xml



make-topic:



[copy]Copying1filetoC:\jboss-4.0\server\default\deplo



Ontheserverside,thefollowinglineisdisplayed:



[titan-TicketTopic]BoundtoJNDIname:topic/titan-TicketTopic



29.1.3.3AddingaJMSTopicthroughtheJMX

HTTPconnector

AnXMLconfigurationfileisthepreferredmeanstodeploya

JMStopicpermanently,butforquicktestsandsuchan

alternativeapproachthatusesJBoss'sJMXHTTPconnectorand

theDestinationManagerissometimesbetter,becausethe

topiclivesinJBossonlyuntiltheapplicationserverisshut

down.Firstopenyourbrowserandgoto

http://localhost:8080/jmx-console/,whereyoucanbrowse

throughalldeployedJBossJMXMBeans.Scrolldowntothe

jboss.mqsectionandfindinittheMBeanservice

DestinationManager(Figure29-1).



Figure29-1.FindingtheDestinationManager



Clickontheservice=DestinationManagerlinkandyougeta

listoftheMBean'sattributesandoperations.Oneofthe

operations,createTopic(),allowsyoutocreateanewJMS

topic(Figure29-2).



Figure29-2.NaminganewJMStopic



TypethenameofthenewJMStopicinthetextarea,andclick

ontheInvokebuttonassociatedwiththecreateTopic()

operation.TheDestinationManagerwillcreatetheJMStopic

anddisplayastatusmessage(Figure29-3).



Figure29-3.Confirmingtopiccreation



ToseeyournewJMStopicMBean,gobacktothehomepageof

theJMXHTTPconnectorandsearchforthe

jboss.mq.destinationdomain.Youshouldbeabletoseeyour

newtopicMBean(Figure29-4).



Figure29-4.Findingthenewtopic



NotethatyoucanusetheJMXHTTPconnectortoseethestatus

ofyourtopicsandqueuesevenifyoucreatetheninanXML

configurationfile.



29.1.4ExaminetheEJBStandardFiles

Theejb-jar.xmldeploymentdescriptorisequivalenttotheone

forExercise11.2exceptfortheTravelAgentEJB.Thedefinition

forthisbeanhasbeenextendedtoreferencetheJMStopicsyou

justcreated.



29.1.4.1ejb-jar.xml



TravelAgentEJB

com.titan.travelagent.TravelAgentHomeRemote



com.titan.travelagent.TravelAgentRemote

com.titan.travelagent.TravelAgentBean

Stateful

Container

...



jdbc/titanDB

javax.sql.DataSource

Container





jms/TopicFactory

javax.jms.TopicConnectionFactory

Container







jms/TicketTopic


javax.jms.Topic








AreferencetoaTopicConnectionFactoryisdeclaredinthe

samewayasareferencetoaDataSource.Thedefinition

containsthenameoftheresource(jms/TopicFactory),the

classoftheresource(javax.jms.TopicConnectionFactory),

andwhetherthecontainerorthebeanperformsthe

authentication.



29.1.5ExaminetheJBoss-SpecificFiles

TheTravelAgentEJBdefinitioninjboss.xmlmustbemodifiedas

well,todescribetheJMStopicreferencesdeclaredinejbjar.xml.



29.1.5.1jboss.xml

...



TravelAgentEJB

TravelAgentHomeRemote



jdbc/titanDB

java:/DefaultDS



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 29. Exercises for Chapter 12

Tải bản đầy đủ ngay(0 tr)

×