Streams AQ






  • Download the
  • Import the project into the LDS Tech IDE.
  • Start the LDS Tech Oracle XE VM
  • (Optional) Download and install Oracle SQL Developer.

Configure Streams AQ

  • Create a database migration script named 002-streamsaq.fwd.sql in the streams-aq-db module under the path schema-versions/DEFAULT
  • Open the newly created migration script and add the following:
    -- Create the queue table
        comment=>'This is the queue table used for the Streams AQ Training Lab'

    -- Create the queue
        queue_name => 'queue',
        queue_table => 'queue_table',
        comment => 'This is the queue used for the Streams AQ Training Lab.'

    -- Start the queue
    dbms_aqadm.start_queue( queue_name => 'queue' );

Be sure to include the "/" after the "end;" statement!

  • Run the database migration script using the 'stack-db:migrate' Maven target.
    • This can be done by right clicking on the db module and selecting Run As | Migrate Database
    • Alternatively, you can run Maven from the command line using mvn stack-db:migrate

If the database migration runs successfully, you should be ready to start using Streams AQ.

Verify Streams AQ Has Been Configure (Optional)

  • Start Oracle SQL developer
  • Connect to your database
  • Under the "Queues Tables" section, make sure you see your queue table
  • Under the "Queues" section, make sure you see your queue

Configure a Spring JmsTemplate

You will need a a Spring JmsTemplate instance to enqueue messages.

  • Open the "applicationContext.xml" file in the src/main/resources directory in the web module of your application.
  • Add the following to the applicationContext.xml file you just opened:
    <stack-jms:destination destination="queue" />

Use the Spring JmsTemplate in Code

  • Open the class
  • Add the following field to the controller
private JmsTemplate jmsTemplate;
  • In the send method, add the following code:
jmsTemplate.send(new MessageCreator() {
    public Message createMessage(Session session) throws JMSException {
        return session.createTextMessage(text);

Run Your Application and Queue Messages

  • Start your application by right clicking on the web module and TODO Put exact text here for starting Tomcat
  • Navigate your browser to [1]
  • Type some text in the message box and press the Queue button.
  • (Optional) Using SQL Developer, select QUEUE_TABLES under the Queues Tables section under your database in the Connections view.
  • (Optional) After the QUEUE_TABLES tab opens, select the data sub-tab to see your message in the queue.
  • (Optional) Queue more messages using the web interface and make sure they appear your queue table.

Implement and Configure a MessageListener

  • Create the class MessageListenerImpl in the package.
  • Have the MessageListenerImpl class you just created implement the interface javax.jms.MessageListener. This will require you to add an onMessage method to you class.
  • Inside the onMessage method, add the following:
try {
	TextMessage textMessage = (TextMessage) message;
} catch (Exception e) {
	throw new RuntimeException(e);

Note: The message variable in the second line should be the same name as the parameter passed to the onMessage method.

  • To configure the message listener, go back to the applicationContext.xml file and add the following bean definition:
<bean id="messageListener" class="" />
  • Once the message listener bean has been defined, we need to configure a JMS message listener. Place the following inside the <stack-jms:jms> element.
    <stack-jms:listener destination="queue" ref="messageListener" />

Note: We already have an ExecutorService created for you so you don't need to add this to your project.

Test the MessageListener

  • Restart Tomcat
  • Watch your console output, you should see all the queued up messages getting dequeued.
  • (Optional) Go to SQL Developer and make sure your queue table is empty.
This page was last modified on 15 February 2012, at 11:00.

Note: Content found in this wiki may not always reflect official Church information. See Terms of Use.