Showing posts with label aq. Show all posts
Showing posts with label aq. Show all posts

Thursday, November 3, 2011

Configuring WSO2 ESB with Oracle™AQ as Messaging Media

"OracleAQ provides database integrated messaging functionality. Its' underlying system works with oracle database. OracleJMS (OJMS) is the JMS interface to the Advanced Queuing (AQ) feature in the Oracle database. OJMS has JNDI support, which could be used to get 'ConnectionFactory' at run time and the connections returned from it will be able to transparently connect to the JMS server."

I have written a detail tutorial about the configurations needed to connect AQ , which is published [1] at wso2 site..Thanks Edwin  for the great help on AQ and LDAP configurations..
[1]http://wso2.org/library/tutorials/2011/11/configuring-wso2-esb-with-oracle-as-messaging-media


Monday, October 10, 2011

Java JNDI based client for OJMS

To work with Java Naming and Directory Interface (JNDI) in OJMS , which is the JMS interface for AQ, we need to register the oracle database with LDAP server. JMS administrator can register ConnectionFactory objects in a LDAP server.
Lets check following sample code, which is used to register the connection factory objects @ LDAP server.

void register_Factory_in_LDAP() throws Exception {
        Hashtable env = new Hashtable();
        // ldap settings
        env.put(Context.INITIAL_CONTEXT_FACTORY, AQjmsConstants.INIT_CTX_FACTORY);
        env.put(Context.PROVIDER_URL, "ldap://localhost:10389/");
        env.put(AQjmsConstants.SERVER_DN, "cn=ORCL,cn=OracleContext,ou=Services, o=sgi,c=us");
        env.put(Context.SECURITY_PRINCIPAL, "uid=ratha,ou=Services, o=sgi,c=us");
        env.put(Context.SECURITY_CREDENTIALS, "secret");
        env.put(Context.SECURITY_AUTHENTICATION, "simple");

        String url = "jdbc:oracle:thin:@localhost:1521/orcl";
        Properties properties = new Properties();
        properties.setProperty("user", "ratha");
        properties.setProperty("password", "ratha");
        try {
            AQjmsFactory.registerConnectionFactory(env, "test_queue_factory", url, properties,
                                                   "queue");
            System.out.println("Connection factory craeted ");

        } catch (Exception e) {
            e.printStackTrace();
          }
    }

// DO lookup

 void get_Factory_from_LDAP() throws Exception {

        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY, AQjmsConstants.INIT_CTX_FACTORY);
        // ldapserver is your LDAP host and 389 is your port
        env.put(Context.INITIAL_CONTEXT_FACTORY, AQjmsConstants.INIT_CTX_FACTORY);
        env.put(Context.PROVIDER_URL, "ldap://localhost:10388/");
        env.put(Context.SECURITY_PRINCIPAL, "uid=ratha,ou=Services, o=sgi,c=us");
        env.put(Context.SECURITY_CREDENTIALS, "secret");

        DirContext inictx = new InitialDirContext(env);
        inictx = (DirContext) inictx.lookup("cn=ORCL,cn=OracleContext,ou=Services, o=sgi,c=us");
        // go to the connection factory holder cn=OraclDBConnections
        DirContext connctx = (DirContext) inictx.lookup("cn=oracledbconnections");

        // get connection factory "test_queue_factory"
        QueueConnectionFactory qc_fact = (QueueConnectionFactory) connctx.lookup("cn=ratha");

        System.out.println("Factory look up success " + qc_fact.toString());
        QueueConnection QCon = qc_fact.createQueueConnection();
        System.out.println("Connection created " + QCon.toString());
       DirContext destctxQF = (DirContext) inictx.lookup("cn=OracleDBQueues");
        System.out.println("OracleDBQueues look up success " + destctxQF.toString());
        Queue queue = (Queue) destctxQF.lookup("cn=ratha.test");
        System.out.println("Queue look up success :" + queue.toString());

        Session session = QCon.createQueueSession(true, QueueSession.AUTO_ACKNOWLEDGE);
        QCon.start();
        QueueSender sender = ((QueueSession) session).createSender(queue);
        System.out.println("Sender creation success :" + sender.toString());
    
       String msg = "test";
       TextMessage message = session.createTextMessage(msg);

       sender.send(message);
       // MessageConsumer consumer = session.createConsumer(queue);
       // TextMessage msg2 = (TextMessage) consumer.receive();
       // System.out.println("MESSAGE RECEIVED " + msg2.getText());

}

LDAP: error code 34 - Invalid root DN given : cn=oracledbconnections,null

This issue occurs when we try to connect OracleAQ via  Oracle JMS. To overcome above issue, check whether you have set following property,
    env.put(AQjmsConstants.SERVER_DN, "cn=ORCL,cn=OracleContext,ou=Services, o=sgi,c=us");

The second parameter provides the DN value of "ORCL", which is the third level, labeled cn=orcl, is the database.

 

Thursday, October 6, 2011

Creating a queuetable @ OracleAQ gives "ORA-01017: invalid username/password" error

If you face such issue[1], when you try to create a 'queuetable' at OracleAQ (Even though you provided all authorizations and authentications correctly), check the following global parameter is set to 'false"


connect / as sysdba
# sqlplus sys/admin@orcl as sysdba;
# ALTER SYSTEM SET GLOBAL_TOPIC_ENABLED = FALSE;


[1]Error

oracle.jms.AQjmsException: ORA-01017: invalid username/password;
logon denied ORA-06512: at "SYS.DBMS_AQADM", line 81
at oracle.jms.AQjmsSession.createQueueTable(AQjmsSession.java:4803)
at oracle.jms.AQjmsSession.createQueueTable(AQjmsSession.java:4778)