I configured connection factory and queues in tomee.xml. Now I need to use
these from standalone app as well as ear file. 

tomee.xml:
<?xml version="1.0" encoding="UTF-8"?>
<tomee>
 
<Resource id="MyJmsResourceAdapter" type="ActiveMQResourceAdapter">
        BrokerXmlConfig =  broker:(tcp://10.1.0.56:61616)
        ServerUrl       = tcp://10.1.0.56:61616
    </Resource>

    <Resource id="MyJmsConnectionFactory"
type="javax.jms.ConnectionFactory">
    
        ResourceAdapter = MyJmsResourceAdapter
    </Resource>

    <Container id="MyJmsMdbContainer" ctype="MESSAGE">
        ResourceAdapter = MyJmsResourceAdapter
    </Container>

    <Resource id="messageQueue1" type="javax.jms.Queue"/>
    <Resource id="messageQueue2" type="javax.jms.Queue"/>
    <Resource id="messageQueue3" type="javax.jms.Queue"/>

<Deployments dir="apps" />
</tomee>

Here is my code:
props.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
    props.put(Context.URL_PKG_PREFIXES, "org.apache.activemq.jndi");
    props.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.RemoteInitialContextFactory");
props.put(Context.PROVIDER_URL, "tcp://10.1.0.56:61616");
InitialContext initialContext = new InitialContext(props);

//The below is not working
          ConnectionFactory connectionFactory = (ConnectionFactory)
initialContext.lookup("MyJmsConnectionFactory");

//The below is working from standalone app, but not from Ear code
          ConnectionFactory connectionFactory = (ConnectionFactory)
initialContext.lookup("ConnectionFactory");

//The below is not working from stand alone app
initialContext.lookup("messageQueue1");

//The below is working from stand alone up - it looks like it is creating
new queue? But I dont want to create new queue as I already created in
tomee.xml
initialContext.lookup("dynamicQueues/messageQueue1");

I didn't even try looking up for queue from Ear code as I am struck at
connection factory itself. 

My MDB is working fine with the below entry in ejb-jar.xml:
<activation-config-property>
             
<activation-config-property-name>destination</activation-config-property-name>
             
<activation-config-property-value>messageQueue1</activation-config-property-value>
          </activation-config-property>

Basically, I want to configure a connection factory and queues during
startup and then use from 3 different places via JNDI:
1. From stand alone app to send messages - working as ConnectionFactory not
as MyJmsConnectionFactory. Working as dynamicQueues/messageQueue1 not as
messageQueue1
2. From ear app to send the messages - ConnectionFactory is not working
3. Process messages using MDB - working fine and I could process messages
from messageQueue1 - didn't specify any connection factory in ejb-jar.xml. I
guess it is using ConnectionFactory from my MDB.

Questions:
Am I declaring correct in tomee.xml?
How do I call it from the stand alone app?
How do I call it from Ear app?
Do I need to use same connection factory in ejb-jar.xml?




--
View this message in context: 
http://tomee-openejb.979440.n4.nabble.com/How-to-reference-connection-factory-and-queues-from-code-tp4675980.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Reply via email to