After creating the Derby database instance, you are ready to deploy the OSGi bundles into the container and test the route, as described here.
Perform the following steps to deploy and run the transactional route in the Fuse ESB Enterprise OSGi container:
Create the Derby database instance for the tutorial and create the
accountstable, as follows:Open a command prompt and change directory to the Derby system directory that you specified earlier (that is, the value of the
derby.system.homesystem property).Start the Derby database client utility,
ij, by entering the following command:ij
![[Note]](imagesdb/note.gif)
Note By default,
ijtakes the current working directory to be the Derby system directory.Create the
txXaTutorialdatabase instance, by entering the followingijcommand:ij> CONNECT 'jdbc:derby:txXaTutorial;create=true';
Create the
accountstable and create two sample row entries, by entering the following sequence ofijcommands:ij> CREATE TABLE accounts (name VARCHAR(50), amount INT); ij> INSERT INTO accounts (name,amount) VALUES ('Major Clanger',2000); ij> INSERT INTO accounts (name,amount) VALUES ('Tiny Clanger',100);Exit
ij, by entering the following command (don't forget the semicolon):ij> EXIT;
Open a new command prompt and start the Fuse ESB Enterprise OSGi container by entering the following command:
servicemix
Install the
transactionfeature into the OSGi container. Enter the following console command:karaf@root> features:install transaction
Install the required bundle dependencies into the OSGi container. For this tutorial, you require the
derbybundle and thespring-jdbcbundle. To install them, enter the following console commands:karaf@root> install mvn:org.springframework/spring-jdbc/3.0.5.RELEASE karaf@root> install mvn:org.apache.derby/derby/10.8.2.2
Install and start the
derby-dsbundle (assuming that you have already built the bundle, as described in Define a Derby Datasource) by entering the following console command:karaf@root> install -s mvn:org.fusesource.example/derby-ds/1.0-SNAPSHOT
To check that the datasources have been successfully exported from the
derby-dsbundle, list thederby-dsservices using theosgi:lscommand. For example, given thatBundleIDis the bundle ID for thederby-dsbundle, you would enter the following console command:karaf@root> osgi:ls
BundleIDAmongst the exported services, you should see an entry like the following:
---- aries.xa.aware = true datasource.name = derbyXADB objectClass = javax.sql.DataSource osgi.service.blueprint.compname = derbyXADataSource service.id = 424 ----This is the wrapped XA datasource (recognizable from the
aries.xa.aware = truesetting), which is automatically created by the Aries wrapper feature (see Apache Aries Auto-Enlisting XA Wrapper).Install and start the
tx-xabundle, by entering the following console command:karaf@root> install -s mvn:org.fusesource.example/tx-xa
Create a file called
giro1.xmlin any convenient directory and use a text editor to add the following message contents to it:<transaction> <transfer> <sender>Major Clanger</sender> <receiver>Tiny Clanger</receiver> <amount>90</amount> </transfer> </transaction>Now copy
giro1.xmlinto thePathNameToMsgDirdirectory you created earlier (see Define a Transactional Route). Thegiro1.xmlfile should disappear immediately after it is copied, because thePathNameToMsgDiris being monitored by the feeder route.Use the JMX console to see what has happened to the message in
giro1.xml. Open a new command prompt and enter the following command (provided with the standard JDK):jconsole
In the JConsole: New Connection screen, select the
org.apache.karaf.main.Mainlocal process and click Connect.Click on the MBean tab and use the tree in the left-hand column to navigate to org.apache.activemq | TxXaDemo | Queue | statusLog | Operations, as shown in the following screenshot.
Now in the right hand pane of the JConsole window, click
browseMessages(the version of the method that takes no arguments). The Operation return value dialog pops up as shown , which enables you to browse all of the messages currently pending in thestatusLogqueueue.In the example shown here, there is just one message in the queue. If you scroll down, you can see the Text field, which holds the body of the JMS message. The body contains the most recent result of calling the
AccountService.dumpTable()method (which is called in the last step of the transactional route).You can also force a transaction rollback by sending a message that exceeds the
AccountService.debit()limit (withdrawal limit) of 100. For example, create the filegiro2.xmland add the following message contents to it:<transaction> <transfer> <sender>Major Clanger</sender> <receiver>Tiny Clanger</receiver> <amount>150</amount> </transfer> </transaction>When you copy this file into the
PathNameToMsgDirdirectory, the message never propagates through to thestatusLogqueue, because the transaction gets rolled back.










