How to connect and send a message to an Oracle Advanced Queue (AQ) ?

Most of us are quite familiar with simple JDBC connection that has to do with reading and writing from a table. Most of us usually don’t have a need to send or read from an Advanced Queue that is solely from Oracle but when needed this seems to be such a hassle when not equipped with correct resource.
Here I have shown the simplest and easiest way to connect to an AQ (Oracle Advanced Queue) just using ConnectionFactory and JmsTemplate using Spring Boot App.

import oracle.jms.AQjmsFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.core.JmsTemplate;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
@Configuration
@EnableJms
public class OracleAdvancedQueueConfig {
public void testOracleAdvancedQueueConnection() throws SQLException, JMSException {
//Same concept applies if using Oracle Exadata
String dbURL = "jdbc:oracle:thin:username/[email protected]:1521:w23";
Connection conn = DriverManager.getConnection(dbURL);
ConnectionFactory connectionFactory = AQjmsFactory.getQueueConnectionFactory(dbURL,
conn.getClientInfo());
JmsTemplate jmsTemplate = new JmsTemplate();
jmsTemplate.setSessionTransacted(true);
jmsTemplate.setConnectionFactory(connectionFactory);
//Your Oracle Advanced Queue name.
jmsTemplate.setDefaultDestinationName("MY_SCHEMA.TO_MY_QUEUE_NAME");
jmsTemplate.convertAndSend("Learn Java");
}
}


Now if you go into that schema and into that queue table you should see the message sent.
Note: Make sure to use this dependency as this also seems to be a common miss from developers.
com.oracle.jdbc ojdbc8 12.2.0.1
com.oracle aqapi 12.1.0.2.0
Other dependencies should be pretty straight forward.
Hope this will helps you and save some time.


Posted

in

by

Comments

3 responses to “How to connect and send a message to an Oracle Advanced Queue (AQ) ?”

  1. Matt Bacak Avatar
    Matt Bacak

    The crypto bull market is heating up, and now’s the perfect time to grab your free Bitcoin.
    Just yesterday, hundreds of members jumped at the chance to claim theirs. Have you claimed yours yet?
    Here’s the deal: You can get $10 in Bitcoin (BTC), completely free – no catch, no purchase necessary.
    Just attend one of this week’s exclusive workshops, immerse yourself in the knowledge, and complete a short quiz.
    $10 in BTC will be sent straight to your crypto wallet.

    Click Here For More Info : https://bit.ly/4g2FMj4

  2. Matt Bacak Avatar
    Matt Bacak

    The First AI Website Creation Suite Is Here: Full Cloud Hosting With Cpanel Access And 99 AIs Including Just-Released Sora AI!

    Say „GoodBye!“ To Wasting 100s Of Dollars On Expensive, Limiting

    Subscriptions To Hosting Companies… Now With Built-In AI Website Creation Suite,

    99-in-1 Premium AIs And Hacker-Proof Server Infrastructure

    Click Here For More Info : https://warriorplus.com/o2/a/qdl074w/0

  3. Hadley Beasley Avatar
    Hadley Beasley

    Business Loan & Easy Funding.

    Discover powerful financial solutions to accelerate your business in 2025!

    Discover how you can:
    – Find the right funding option that aligns with your growth plan.
    – Accelerate your growth with flexible funding options that fuel expansion.
    – Simplify the application process with our streamlined approach.
    – Benefit from expert guidance to master the complexities of business financing.

    ++ Don’t wait—secure your funding today: https://bit.ly/bestfundingnow now

    This is the must-have opportunity for SMBs to flourish.

    The race has started – and your competition is moving fast. Are you in?

    P.S. Don’t miss out—once this funding is gone, it’s gone for good!

Leave a Reply

Your email address will not be published. Required fields are marked *