0
votes

Somebody helps me with code example of proper using oracle.tip.adapter.jms.JmsConnectionFactory. This is connection factory for using JMS through JMSAdapter in Weblogic 12C. Weblogic 12С connected to standalone ActiveMQ server through JMSAdapter. In JMSAdapter I created new outbound connection with jndi eis/ext/open under oracle.tip.adapter.jms.IJmsConnectionFactory (interface) with properties:

AcknowledgeMode = AUTO_ACKNOWLEDGE
ConnectionFactoryLocation = org.apache.activemq.ActiveMQConnectionFactory
FactoryProperties = BrockerURL=tcp://host:port;ThirdPartyJMSProvider=true
public class CustomJMSSelector {

    private final static String JNDI_FACTORY="weblogic.jndi.WLInitialContextFactory";
    private final static String JMS_FACTORY="eis/ext/open";
    private static JmsConnectionFactory jmsConnectionFactory;


    public static byte[] customSelectorConsumer(String correlationId) throws NamingException, ResourceException {

        Hashtable env = new Hashtable();

        env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
        Context ctx = new InitialContext(env);

        jmsConnectionFactory = (JmsConnectionFactory) ctx.lookup(JMS_FACTORY);

I need to create session, consumer and consume message from queue using oracle.tip.adapter.jms.JmsConnectionFactory.

Unfortunately, oracle.tip.adapter.jms.JmsConnectionFactory doesn't implement javax.jms.ConnectionFactory. It implements oracle.tip.adapter.jms.IJmsConnectionFactory that extends oracle.tip.adapter.api.OracleConnectionFactory. I tried cast to javax.jms.Connection or to org.apache.activemq.ActiveMQConnectionFactory but got class cast exception. This connection is using by osb (proxy service, business service)

1
There is no feasible casting between those two factories, as you know, you should change the factory to weblogic.jms.XAConnectionFactory or weblogic.jms.ConnectionFactory (or any that extends javax.jms.Connection, ora-soa.blogspot.com/2011/06/… - devwebcl
Hello. Under Deployments-> JMS Adapter in Weblogic Console -> Under Configuration -> OutboundConnectionPool : I have ConnectionFactoryLocation = org.apache.activemq.ActiveMQConnectionFactory If i change it to weblogic.jms.XAConnectionFactory or weblogic.jms.ConnectionFactory my connection doen't work at all - DanilVanDovgal

1 Answers

0
votes

Assuming oracle.tip.adapter.jms.JmsConnectionFactory implements javax.jms.ConnectionFactory you can simply create a connection, session, and consumer like so:

import javax.jms.Connection;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.Session;
...

public class CustomJMSSelector {

    private final static String JNDI_FACTORY="weblogic.jndi.WLInitialContextFactory";
    private final static String JMS_FACTORY="eis/ext/open";
    private final static String QUEUE_JNDI_NAME="queue/jndi/name";  // the JNDI name of the queue
    private static ConnectionFactory jmsConnectionFactory;


    public static byte[] customSelectorConsumer(String correlationId) throws NamingException, ResourceException {
        Hashtable env = new Hashtable();

        env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
        Context ctx = new InitialContext(env);

        jmsConnectionFactory = (JmsConnectionFactory) ctx.lookup(JMS_FACTORY);
        Queue queue = (Queue) ctx.lookup(QUEUE_JNDI_NAME);

        Connection connection = jmsConnectionFactory.createConnection();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = session.createConsumer(queue);
        Message message = consumer.receive();
        // do something with the message
        connection.close();
    }
}

This is a very simple bit of code with no real resource management. In a production use-case you'd want to use a pooled connection factory so that you aren't actually creating and closing a physical connection for every message you receive.