You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Alex Soto <as...@gmail.com> on 2015/03/09 17:02:13 UTC

JMS

Hi I am creating a demo for using Apache TomEE and JMS and I don't know why
but simple example doesn't work. Probably because I have followed an
updated doc.

My class looks like:

@Stateless
@Path("/sender")
public class SenderMessage {

    @Resource
    private ConnectionFactory connectionFactory;

    @Resource(name = "messageQueue")
    private javax.jms.Queue messageQueue;

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    public void sendMessageToJms(String content) throws JMSException {
        System.out.println(content);
        sendMessage(content);
    }

    private void sendMessage(String text) throws JMSException {
        Connection connection = null;
        Session session = null;

        try {
            connection = connectionFactory.createConnection();
            connection.start();

            session =
                connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

            MessageProducer producer = session.createProducer(messageQueue);
            producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

            TextMessage message = session.createTextMessage(text);
            producer.send(message);
        } finally {
            if (session != null)
                session.close();
            if (connection != null)
                connection.close();
        }
    }

}

And resources.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

  <Resource id="senderResourceAdapter" type="ActiveMQResourceAdapter">
    BrokerXmlConfig =  broker:(tcp://localhost:61616)
    ServerUrl       =  tcp://localhost:61616
    startupTimeout  = 10 seconds
  </Resource>

  <Resource id="senderConnectionFactory" type="javax.jms.ConnectionFactory">
    ResourceAdapter = senderResourceAdapter
  </Resource>
</resources>

When I run the example at deployment time this exception is thrown:

org.apache.openejb.OpenEJBException: Unable to load type
'ActiveMQResourceAdapter' for
comp/env/openejb/Resource/projectD/senderResourceAdapter: Unable to load
type 'ActiveMQResourceAdapter' for
comp/env/openejb/Resource/projectD/senderResourceAdapter

But inspecting this file it seems is correctly named:
https://git-wip-us.apache.org/repos/asf?p=tomee.git;a=blob;f=container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml;h=b415e6a954e247b369b445b652ecc078d61088bc;hb=d48525c4d67667eb8e2a1295602e618cdd6c267d

Re: JMS

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

Maybe use class-name cause resources.xml shortcuts are not all  available
IIRC - is working in tomee.xml cause global only.
Le 9 mars 2015 17:05, "Alex Soto" <as...@gmail.com> a écrit :

> Hi I am creating a demo for using Apache TomEE and JMS and I don't know why
> but simple example doesn't work. Probably because I have followed an
> updated doc.
>
> My class looks like:
>
> @Stateless
> @Path("/sender")
> public class SenderMessage {
>
>     @Resource
>     private ConnectionFactory connectionFactory;
>
>     @Resource(name = "messageQueue")
>     private javax.jms.Queue messageQueue;
>
>     @POST
>     @Consumes(MediaType.APPLICATION_JSON)
>     public void sendMessageToJms(String content) throws JMSException {
>         System.out.println(content);
>         sendMessage(content);
>     }
>
>     private void sendMessage(String text) throws JMSException {
>         Connection connection = null;
>         Session session = null;
>
>         try {
>             connection = connectionFactory.createConnection();
>             connection.start();
>
>             session =
>                 connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
>
>             MessageProducer producer =
> session.createProducer(messageQueue);
>             producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
>
>             TextMessage message = session.createTextMessage(text);
>             producer.send(message);
>         } finally {
>             if (session != null)
>                 session.close();
>             if (connection != null)
>                 connection.close();
>         }
>     }
>
> }
>
> And resources.xml
>
> <?xml version="1.0" encoding="utf-8"?>
> <resources>
>
>   <Resource id="senderResourceAdapter" type="ActiveMQResourceAdapter">
>     BrokerXmlConfig =  broker:(tcp://localhost:61616)
>     ServerUrl       =  tcp://localhost:61616
>     startupTimeout  = 10 seconds
>   </Resource>
>
>   <Resource id="senderConnectionFactory"
> type="javax.jms.ConnectionFactory">
>     ResourceAdapter = senderResourceAdapter
>   </Resource>
> </resources>
>
> When I run the example at deployment time this exception is thrown:
>
> org.apache.openejb.OpenEJBException: Unable to load type
> 'ActiveMQResourceAdapter' for
> comp/env/openejb/Resource/projectD/senderResourceAdapter: Unable to load
> type 'ActiveMQResourceAdapter' for
> comp/env/openejb/Resource/projectD/senderResourceAdapter
>
> But inspecting this file it seems is correctly named:
>
> https://git-wip-us.apache.org/repos/asf?p=tomee.git;a=blob;f=container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml;h=b415e6a954e247b369b445b652ecc078d61088bc;hb=d48525c4d67667eb8e2a1295602e618cdd6c267d
>