You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by kazak777 <ka...@gmail.com> on 2012/01/20 08:09:31 UTC

Locating JMS queue problem

I'm writing unit tests for application that works under JBoss. In this
application there is MDB defined as follows:

@MessageDriven(
		activationConfig = { 
		        @ActivationConfigProperty(propertyName = "destinationType",
propertyValue = "javax.jms.Queue"),
		        @ActivationConfigProperty(propertyName = "destination",
propertyValue = "jms/MonitoringQueue")
		}, 
		name = "ProcessMonitoring")
public class ProcessMonitoringBean implements MessageListener {
.........
}

The code which I test sends messages to ProcessMonitoringBean. It looks up
queue like this:

protected void bowl( MMonitoring theMessage ) {
	   Context context = new InitialContext();
	   Destination destination = (Destination)
context.lookup("jms/MonitoringQueue");
.......
}

This code works under JBoss AS 5, not under embedded openEJB. When I run my
unit test under openEJB, I get exception:

javax.naming.NameNotFoundException: Name "jms/MonitoringQueue" not found.

How can I make my test execute application code?




--
View this message in context: http://openejb.979440.n4.nabble.com/Locating-JMS-queue-problem-tp4312562p4312562.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Locating JMS queue problem

Posted by kazak777 <ka...@gmail.com>.
I tried to inject, but it didn't work. Nothing is injected. Perhaps I'm doing
something wrong (i never used EJBs before). Here is part of my code where I
tried to inject queue:

@Stateful(name = "Scenario")
public class ScenarioBean implements Scenario {

    @Resource(name = "jms/MonitoringQueue")
    private Destination destination;

    public void setDestination(Destination destination) {
        this.destination = destination;
    }

}

Here is part of test log:

......
INFO - Configuring Service(id=jms/MonitoringQueue, type=Resource,
provider-id=Default Queue)
DEBUG - Override [destination=jms/ProcessMonitoring]
......
INFO - Auto-linking resource-ref 'java:comp/env/jms/MonitoringQueue' in bean
Scenario to Resource(id=jms/MonitoringQueue)
......


Variable 'destination' remains null. As you can see, resource
'jms/MonitoringQueue' binds to 'java:comp/env/jms/MonitoringQueue'.
Destination of ProcessMonitoringBean binds to
'openejb/Resource/jms/MonitoringQueue'.

--
View this message in context: http://openejb.979440.n4.nabble.com/Locating-JMS-queue-problem-tp4312562p4320663.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Locating JMS queue problem

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi,

if the component you are using to send the message is managed simply get
the queue injected, you'll not need any lookup.

- Romain


2012/1/23 kazak777 <ka...@gmail.com>

> This is my ejb-jar.xml:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns="http://java.sun.com/xml/ns/javaee"
>         xmlns:ejb="http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
>         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
> http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
>         version="3.0">
>
>   <enterprise-beans>
>        <message-driven>
>            <ejb-name>ProcessMonitoringBean</ejb-name>
>            <ejb-class>package.ProcessMonitoringBean</ejb-class>
>            <activation-config>
>                <activation-config-property>
>
>
> <activation-config-property-name>destination</activation-config-property-name>
>
> <activation-config-property-value>openejb:Resource/jms/MonitoringQueue
>                    </activation-config-property-value>
>                </activation-config-property>
>                <activation-config-property>
>
>
> <activation-config-property-name>destinationType</activation-config-property-name>
>
>
> <activation-config-property-value>javax.jms.Queue</activation-config-property-value>
>                </activation-config-property>
>            </activation-config>
>        </message-driven>
>    </enterprise-beans>
> </ejb-jar>
>
> When I run the test, I get exception:
>
> javax.naming.NameNotFoundException: Name "jms/MonitoringQueue" not found.
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Locating-JMS-queue-problem-tp4312562p4320043.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: Locating JMS queue problem

Posted by kazak777 <ka...@gmail.com>.
This is my ejb-jar.xml:

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:ejb="http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
         version="3.0">

   <enterprise-beans>
        <message-driven>
            <ejb-name>ProcessMonitoringBean</ejb-name>
            <ejb-class>package.ProcessMonitoringBean</ejb-class>
            <activation-config>
                <activation-config-property>
                   
<activation-config-property-name>destination</activation-config-property-name>
                   
<activation-config-property-value>openejb:Resource/jms/MonitoringQueue
                    </activation-config-property-value>
                </activation-config-property>
                <activation-config-property>
                   
<activation-config-property-name>destinationType</activation-config-property-name>
                   
<activation-config-property-value>javax.jms.Queue</activation-config-property-value>
                </activation-config-property>
            </activation-config>
        </message-driven>
    </enterprise-beans>
</ejb-jar>

When I run the test, I get exception:

javax.naming.NameNotFoundException: Name "jms/MonitoringQueue" not found.



--
View this message in context: http://openejb.979440.n4.nabble.com/Locating-JMS-queue-problem-tp4312562p4320043.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Locating JMS queue problem

Posted by AndyG <an...@orprovision.com>.
You will have to use the ejb-jar.xml configuration to override the hard coded
annotation.

<message-driven>
  <ejb-name>ProcessMonitoringBean</ejb-name>
  <activation-config>
    <activation-config-property>
     
<activation-config-property-name>destination</activation-config-property-name>
     
<activation-config-property-value>openejb:Resource/jms/MonitoringQueue</activation-config-property-value>
    </activation-config-property>
  </activation-config>
</message-driven>


--
View this message in context: http://openejb.979440.n4.nabble.com/Locating-JMS-queue-problem-tp4312562p4313072.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Locating JMS queue problem

Posted by kazak777 <ka...@gmail.com>.
Xml-based configuration is not used in the application, all beans and
resources are declared using annotations. 
I did not find any equivalent to 'resource-env-ref-name'. 
Could You help me to find information about how to use
'resource-env-ref-name' in annotation-based environment?

Also I checked the content of JNDI context under debugger. I found that
queue 'jms/MonitoringQueue' can be resolved by
'openejb:Resource/jms/MonitoringQueue' name. So I wonder, why openEJB
registers some 'jms/Queue' resource as 'openejb:Resource/jms/Queue', but
trying to resolve it as 'local/jms/Queue'  ?

--
View this message in context: http://openejb.979440.n4.nabble.com/Locating-JMS-queue-problem-tp4312562p4312896.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Locating JMS queue problem

Posted by AndyG <an...@orprovision.com>.
Have a look here:

http://openejb.apache.org/jms-resources-and-mdb-container.html
http://openejb.apache.org/examples-trunk/simple-mdb-with-descriptor/README.html

There are no real standards defined for lookup names and they are usually
going to be different for each container. You will have to play with the
configuration and try and get a balance.

The propertyValue = "jms/MonitoringQueue" is going to be the focus.

See: resource-env-ref-name

Regards, Andy.

--
View this message in context: http://openejb.979440.n4.nabble.com/Locating-JMS-queue-problem-tp4312562p4312784.html
Sent from the OpenEJB User mailing list archive at Nabble.com.