Ce contenu n'est pas disponible dans la langue sélectionnée.

10.5. Deploy and Run the Transactional Route


Overview

After creating the Derby database instance, you are ready to deploy the OSGi bundles into the container and test the route, as described here.

Steps to deploy and run the transactional route

Perform the following steps to deploy and run the transactional route in the Red Hat JBoss Fuse OSGi container:
  1. Create the Derby database instance for the tutorial and create the accounts table, as follows:
    1. Open a command prompt and change directory to the Derby system directory that you specified earlier (that is, the value of the derby.system.home system property).
    2. Start the Derby database client utility, ij, by entering the following command:
      ij
      Note
      By default, ij takes the current working directory to be the Derby system directory.
    3. Create the txXaTutorial database instance, by entering the following ij command:
      ij> CONNECT 'jdbc:derby:txXaTutorial;create=true';
    4. Create the accounts table and create two sample row entries, by entering the following sequence of ij commands:
      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);
    5. Exit ij, by entering the following command (don't forget the semicolon):
      ij> EXIT;
  2. Open a new command prompt and start the JBoss Fuse OSGi container by entering the following command:
    ./fuse
  3. Install the transaction feature into the OSGi container. Enter the following console command:
    JBossFuse:karaf@root> features:install transaction
  4. Install the connector feature, which provides automatic XA datasource enlisting (Aries datasource wrapper). Enter the following console command:
    JBossFuse:karaf@root> features:install connector
  5. Install the spring-jdbc feature into the OSGi container. Enter the following console command:
    JBossFuse:karaf@root> features:install spring-jdbc
  6. Install the derby bundle into the OSGi container. Enter the following console command, replacing the bundle version with whatever version of Derby you are using:
    JBossFuse:karaf@root> install mvn:org.apache.derby/derby/10.10.1.1
  7. Install and start the derby-ds bundle (assuming that you have already built the bundle, as described in Section 10.3, “Define a Derby Datasource”) by entering the following console command:
    JBossFuse:karaf@root> install -s mvn:org.fusesource.example/derby-ds/1.0-SNAPSHOT
  8. To check that the datasources have been successfully exported from the derby-ds bundle, list the derby-ds services using the osgi:ls command. For example, given that BundleID is the bundle ID for the derby-ds bundle, you would enter the following console command:
    JBossFuse:karaf@root> osgi:ls BundleID
    Amongst the exported services, you should see an entry like the following:
    ----
    aries.managed = true
    aries.xa.aware = true
    aries.xa.name = derbyDS
    datasource.name = derbyXADB
    objectClass = [javax.sql.DataSource]
    osgi.service.blueprint.compname = derbyXADataSource
    service.id = 609
    service.ranking = 1000
    ----
    This is the wrapped XA datasource (recognizable from the aries.xa.aware = true setting), which is automatically created by the Aries wrapper feature (see Apache Aries Auto-Enlisting XA Wrapper).
  9. Install and start the tx-xa bundle, by entering the following console command:
    JBossFuse:karaf@root> install -s mvn:org.fusesource.example/tx-xa
  10. Create a file called giro1.xml in 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.xml into the PathNameToMsgDir directory you created earlier (see Section 10.4, “Define a Transactional Route”). The giro1.xml file should disappear immediately after it is copied, because the PathNameToMsgDir is being monitored by the feeder route.
  11. Use the Fuse Management Console to see what has happened to the message from giro1.xml. User your browser to navigate to the following URL: http://localhost:8181/hawtio. Login to the console using any valid JAAS username/password credentials (which are normally defined in the etc/users.properties file).
  12. On the main menu bar, click on the ActiveMQ tab. In the left-hand pane of this view, drill down to the statusLog queue, as shown.

    Figure 10.1. View of the statusLog Queue in Hawtio

    View of the statusLog Queue in Hawtio
  13. On the menu bar above the right-hand pane, click Browse to browse the messages in the statusLog queue and click on the first message to view its contents. The body contains the most recent result of calling the AccountService.dumpTable() method (which is called in the last step of the transactional route).

    Figure 10.2. Browsing Message Contents in the statusLog Queue

    Browsing Message Contents in the statusLog Queue
  14. 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 file giro2.xml and 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 PathNameToMsgDir directory, the message never propagates through to the statusLog queue, because the transaction gets rolled back.
Red Hat logoGithubRedditYoutubeTwitter

Apprendre

Essayez, achetez et vendez

Communautés

À propos de la documentation Red Hat

Nous aidons les utilisateurs de Red Hat à innover et à atteindre leurs objectifs grâce à nos produits et services avec un contenu auquel ils peuvent faire confiance.

Rendre l’open source plus inclusif

Red Hat s'engage à remplacer le langage problématique dans notre code, notre documentation et nos propriétés Web. Pour plus de détails, consultez leBlog Red Hat.

À propos de Red Hat

Nous proposons des solutions renforcées qui facilitent le travail des entreprises sur plusieurs plates-formes et environnements, du centre de données central à la périphérie du réseau.

© 2024 Red Hat, Inc.