You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by fcosfc <fc...@hotmail.com> on 2013/11/14 14:34:28 UTC

MDB doesn't read messages

Hi there,

I'm a newbie user of Apache TomEE, I'm evaluating its future use on our
deployments. I have configured a global queue in order to be used by several
applications, here you have an excerpt of my tomee.xml file that follows 
the documentation I've read
<http://tomee.apache.org/jms-resources-and-mdb-container.html>  :

  <Resource id="TomEEJmsResourceAdapter" type="ActiveMQResourceAdapter">
     BrokerXmlConfig =  broker:(tcp://localhost:61616)
     ServerUrl       =  tcp://localhost:61616
  </Resource>

  <Resource id="TomEEJmsConnectionFactory"
type="javax.jms.ConnectionFactory">
     ResourceAdapter = TomEEJmsResourceAdapter
  </Resource>

  <Container id="TomEEJmsMdbContainer" ctype="MESSAGE">
     ResourceAdapter = TomEEJmsResourceAdapter
  </Container>

  <Resource id="MoviesQueue" type="javax.jms.Queue"/>

How I might connect to that queue from my MDB? I don't know how the example 
simple-mdb <http://tomee.apache.org/examples-trunk/simple-mdb/README.html>  
does it. Here you have the code of my MDB:

@MessageDriven(activationConfig = {
    @ActivationConfigProperty(propertyName = "destination",
            propertyValue = "openejb:Resource/MoviesQueue"),
    @ActivationConfigProperty(propertyName = "destinationType",
            propertyValue = "javax.jms.Queue")})
public class MoviesLog implements MessageListener {

    private static final Logger logger =
Logger.getLogger(MoviesLog.class.getName());

    @Resource
    private MessageDrivenContext mdc;

    @Override
    public void onMessage(Message message) {
        TextMessage msg;
        try {
            if (message instanceof TextMessage) {
                msg = (TextMessage) message;

                logger.log(Level.INFO, "Message received {0}",
msg.getText());
            } else {
                logger.log(Level.WARNING, "Message received of a wrong type
{0}", message.getClass().getName());
            }
        } catch (JMSException ex) {
            logger.log(Level.SEVERE, null, ex);
            
            mdc.setRollbackOnly();
        }
    }

}

Regards,

Paco.




--
View this message in context: http://openejb.979440.n4.nabble.com/MDB-doesn-t-read-messages-tp4666169.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: MDB doesn't read messages

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Well a patch for the doc is welcomed (and very appreciated!).
class-name/factory-name/constructor are quite new so the doc needs to
be updated.

About TransactionSupport that true but I think you get it wrong (blame
us for the doc on this point). TransactionSupport is the way the
resource adapter transactional resources are handled (said "quickly").
This parameter is not used for AMQ since we have a custom integration
but even if used as expected you would have had this issue (we should
just remove this parameter IMO).
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2013/11/19 fcosfc <fc...@hotmail.com>:
> Hi Romain,
>
> I'm newbie at TomEE and OpenEJB.
>
> I suppose there are many people like me, who uses open-source projects but
> are not involved in them. I say it because the use of the class-name
> parameter is not documented in TomEE and the supposed behaviour
> (TransactionSupport = xa) is failing, I'd like to fix it.
>
> Regards,
>
> Paco.
>
>
>
> --
> View this message in context: http://openejb.979440.n4.nabble.com/MDB-doesn-t-read-messages-tp4666169p4666244.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: MDB doesn't read messages

Posted by fcosfc <fc...@hotmail.com>.
Hi Romain,

I'm newbie at TomEE and OpenEJB. 

I suppose there are many people like me, who uses open-source projects but
are not involved in them. I say it because the use of the class-name
parameter is not documented in TomEE and the supposed behaviour
(TransactionSupport = xa) is failing, I'd like to fix it.   

Regards,

Paco.



--
View this message in context: http://openejb.979440.n4.nabble.com/MDB-doesn-t-read-messages-tp4666169p4666244.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: MDB doesn't read messages

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Not sure you are familiar with properties format of openejb, if no
please shout, if yes you can read this test which uses XA AMQ
connections: http://svn.apache.org/repos/asf/tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/activemq/AMQXASupportTest.java

Globally something like:

<Resource id="TomEEJmsConnectionFactory"
class-name="org.apache.activemq.ActiveMQXAConnectionFactory">
     BrokerUrl = vm://localhost
  </Resource>
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2013/11/18 Romain Manni-Bucau <rm...@gmail.com>:
> Did you try:
>
> <Resource id="TomEEJmsConnectionFactory"
> class-name="org.apache.activemq.ActiveMQXAConnectionFactory">
>      ResourceAdapter = TomEEJmsResourceAdapter
>   </Resource>
>
> ?
>
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
>
> 2013/11/18 fcosfc <fc...@hotmail.com>:
>> Hi Romain,
>>
>>    It seems to be a TomEE issue:
>> http://activemq.2283324.n4.nabble.com/ActiveMQ-resource-adapter-doesn-t-return-a-XA-connection-factory-td4674604.html
>>
>>    Should I open a JIRA?
>>
>> Regards,
>>
>> Paco.
>>
>>
>>
>> --
>> View this message in context: http://openejb.979440.n4.nabble.com/MDB-doesn-t-read-messages-tp4666169p4666233.html
>> Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: MDB doesn't read messages

Posted by fcosfc <fc...@hotmail.com>.
Hi Romain,

   It worked with:

  <Resource id="TomEEJmsConnectionFactory"
type="javax.jms.ConnectionFactory"
class-name="org.apache.activemq.ActiveMQXAConnectionFactory">
     ResourceAdapter = TomEEJmsResourceAdapter
  </Resource> 

  Thank you very much for your help.

Regards,

Paco Saucedo.



--
View this message in context: http://openejb.979440.n4.nabble.com/MDB-doesn-t-read-messages-tp4666169p4666237.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: MDB doesn't read messages

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Did you try:

<Resource id="TomEEJmsConnectionFactory"
class-name="org.apache.activemq.ActiveMQXAConnectionFactory">
     ResourceAdapter = TomEEJmsResourceAdapter
  </Resource>

?

Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2013/11/18 fcosfc <fc...@hotmail.com>:
> Hi Romain,
>
>    It seems to be a TomEE issue:
> http://activemq.2283324.n4.nabble.com/ActiveMQ-resource-adapter-doesn-t-return-a-XA-connection-factory-td4674604.html
>
>    Should I open a JIRA?
>
> Regards,
>
> Paco.
>
>
>
> --
> View this message in context: http://openejb.979440.n4.nabble.com/MDB-doesn-t-read-messages-tp4666169p4666233.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: MDB doesn't read messages

Posted by fcosfc <fc...@hotmail.com>.
Hi Romain,

   It seems to be a TomEE issue:
http://activemq.2283324.n4.nabble.com/ActiveMQ-resource-adapter-doesn-t-return-a-XA-connection-factory-td4674604.html

   Should I open a JIRA?

Regards,

Paco.



--
View this message in context: http://openejb.979440.n4.nabble.com/MDB-doesn-t-read-messages-tp4666169p4666233.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: MDB doesn't read messages

Posted by fcosfc <fc...@hotmail.com>.
Hi Romain,

   I've asked about this issue to the ActiveMQ user forum.

Regards,

Paco.



--
View this message in context: http://openejb.979440.n4.nabble.com/MDB-doesn-t-read-messages-tp4666169p4666232.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: MDB doesn't read messages

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Tomee delegates a lot so i'd say amq first but i didnt check
Le 15 nov. 2013 21:46, "fcosfc" <fc...@hotmail.com> a écrit :

> Hi Romain,
>
> I've been debugging a bit. First of all, the connection factory resource
> injection doesn't return an ActiveMQXAConnectionFactory, even when I
> request
> a XAConnectionFactory:
>
> <http://openejb.979440.n4.nabble.com/file/n4666192/screenshot.png>
>
> With a simple @Resource annotation the result is the same.
>
> On the other hand, TomEE  documentation about the
> javax.jms.ConnectionFactory resource type
> <http://tomee.apache.org/containers-and-resources.html>   says:
>
> /TransactionSupport     Specifies if the connection is enrolled in global
> transaction
> allowed values: xa, local or none
>
> *Default value is xa*./
>
> So, is it an ActiveMQ resource adapter problem? or, is it a TomEE problem?
>
>
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/MDB-doesn-t-read-messages-tp4666169p4666192.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: MDB doesn't read messages

Posted by fcosfc <fc...@hotmail.com>.
Hi Romain,

I've been debugging a bit. First of all, the connection factory resource
injection doesn't return an ActiveMQXAConnectionFactory, even when I request
a XAConnectionFactory:

<http://openejb.979440.n4.nabble.com/file/n4666192/screenshot.png> 

With a simple @Resource annotation the result is the same.

On the other hand, TomEE  documentation about the
javax.jms.ConnectionFactory resource type
<http://tomee.apache.org/containers-and-resources.html>   says:

/TransactionSupport 	Specifies if the connection is enrolled in global
transaction
allowed values: xa, local or none

*Default value is xa*./

So, is it an ActiveMQ resource adapter problem? or, is it a TomEE problem? 






--
View this message in context: http://openejb.979440.n4.nabble.com/MDB-doesn-t-read-messages-tp4666169p4666192.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: MDB doesn't read messages

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

Didnt test with recent amq version but can be an issue in amq resource
adapter. Did you ask amq list?
Le 14 nov. 2013 19:07, "fcosfc" <fc...@hotmail.com> a écrit :

> Hi Romain,
>
> I made a mistake in my former reply, the statement that makes the system
> work is:
>
> session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
>
> with
>
> session = connection.createSession(false, Session.SESSION_TRANSACTED);
>
> doesn't work.
>
> I've tried:
>
> @Stateless
> @TransactionAttribute(TransactionAttributeType.MANDATORY)
> public class MoviesMessaging {
> ...
> @Resource(name="*XAConnectionFactory*")
> private ConnectionFactory connectionFactory;
> ...
> session = connection.createSession(false, Session.SESSION_TRANSACTED);
>
> but doesn't work properly.
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/MDB-doesn-t-read-messages-tp4666169p4666177.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: MDB doesn't read messages

Posted by fcosfc <fc...@hotmail.com>.
Hi Romain,

I made a mistake in my former reply, the statement that makes the system
work is:

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

with

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

doesn't work.

I've tried:

@Stateless
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public class MoviesMessaging {
...
@Resource(name="*XAConnectionFactory*")
private ConnectionFactory connectionFactory;
...
session = connection.createSession(false, Session.SESSION_TRANSACTED); 

but doesn't work properly.



--
View this message in context: http://openejb.979440.n4.nabble.com/MDB-doesn-t-read-messages-tp4666169p4666177.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: MDB doesn't read messages

Posted by Romain Manni-Bucau <rm...@gmail.com>.
When using transacted the first param (boolean) is ignored by spec AFAIK
Le 14 nov. 2013 18:16, "fcosfc" <fc...@hotmail.com> a écrit :

> Hi Romain,
>
>    I'm sorry, I've added a sleep statement and the test runs successfully,
> so I've reviewed my code. I'd like to use Container Managed Transactions so
> I have the following statement at the EJB that sends the messages:
>
> session = connection.createSession(true, Session.SESSION_TRANSACTED);
>
> The EJB has the annotation
> @TransactionAttribute(TransactionAttributeType.MANDATORY) and it works with
> another EJB that save the message in a db, in the context of the same
> transaction.
>
> When I change the former statement to:
>
> session = connection.createSession(false, Session.SESSION_TRANSACTED);
>
> The MDB starts to read messages. The question here is that if the container
> has to rollback the transaction where a message is sent, the MDB receives
> the message, which it isn't an incorrect behaviour for me.
>
> Regards.
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/MDB-doesn-t-read-messages-tp4666169p4666175.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: MDB doesn't read messages

Posted by fcosfc <fc...@hotmail.com>.
Hi Romain,

   I'm sorry, I've added a sleep statement and the test runs successfully,
so I've reviewed my code. I'd like to use Container Managed Transactions so
I have the following statement at the EJB that sends the messages:

session = connection.createSession(true, Session.SESSION_TRANSACTED);

The EJB has the annotation
@TransactionAttribute(TransactionAttributeType.MANDATORY) and it works with
another EJB that save the message in a db, in the context of the same
transaction. 

When I change the former statement to:

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

The MDB starts to read messages. The question here is that if the container
has to rollback the transaction where a message is sent, the MDB receives
the message, which it isn't an incorrect behaviour for me.

Regards.



--
View this message in context: http://openejb.979440.n4.nabble.com/MDB-doesn-t-read-messages-tp4666169p4666175.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: MDB doesn't read messages

Posted by Romain Manni-Bucau <rm...@gmail.com>.
this is asynchronous by default, add a sleep in your test
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2013/11/14 fcosfc <fc...@hotmail.com>:
> Hi Romain,
>
> Please find attached my maven project. I've added a test case that simply
> sends a message. Thank you very much for your help.
>
> movies.rar <http://openejb.979440.n4.nabble.com/file/n4666173/movies.rar>
>
>
>
> --
> View this message in context: http://openejb.979440.n4.nabble.com/MDB-doesn-t-read-messages-tp4666169p4666173.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: MDB doesn't read messages

Posted by fcosfc <fc...@hotmail.com>.
Hi Romain,

Please find attached my maven project. I've added a test case that simply
sends a message. Thank you very much for your help.

movies.rar <http://openejb.979440.n4.nabble.com/file/n4666173/movies.rar>  



--
View this message in context: http://openejb.979440.n4.nabble.com/MDB-doesn-t-read-messages-tp4666169p4666173.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: MDB doesn't read messages

Posted by Romain Manni-Bucau <rm...@gmail.com>.
MoviesQueue should be enough but openejb:Resource/MoviesQueue is
normally the same.

if you can reproduce your issue just share a sample with a unit test
proving it doesn't work mvn clean test -> fail)
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2013/11/14 fcosfc <fc...@hotmail.com>:
> No, it doesn't. Is the JNDI value openejb:Resource/MoviesQueue of the
> destination property correct to connect to the resource defined in
> tomee.xml?
>
> Regards,
>
> Paco.
>
>
>
> --
> View this message in context: http://openejb.979440.n4.nabble.com/MDB-doesn-t-read-messages-tp4666169p4666171.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: MDB doesn't read messages

Posted by fcosfc <fc...@hotmail.com>.
No, it doesn't. Is the JNDI value openejb:Resource/MoviesQueue of the
destination property correct to connect to the resource defined in
tomee.xml?

Regards,

Paco.



--
View this message in context: http://openejb.979440.n4.nabble.com/MDB-doesn-t-read-messages-tp4666169p4666171.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: MDB doesn't read messages

Posted by Romain Manni-Bucau <rm...@gmail.com>.
destination doesn't work?
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2013/11/14 fcosfc <fc...@hotmail.com>:
> Hi there,
>
> I'm a newbie user of Apache TomEE, I'm evaluating its future use on our
> deployments. I have configured a global queue in order to be used by several
> applications, here you have an excerpt of my tomee.xml file that follows
> the documentation I've read
> <http://tomee.apache.org/jms-resources-and-mdb-container.html>  :
>
>   <Resource id="TomEEJmsResourceAdapter" type="ActiveMQResourceAdapter">
>      BrokerXmlConfig =  broker:(tcp://localhost:61616)
>      ServerUrl       =  tcp://localhost:61616
>   </Resource>
>
>   <Resource id="TomEEJmsConnectionFactory"
> type="javax.jms.ConnectionFactory">
>      ResourceAdapter = TomEEJmsResourceAdapter
>   </Resource>
>
>   <Container id="TomEEJmsMdbContainer" ctype="MESSAGE">
>      ResourceAdapter = TomEEJmsResourceAdapter
>   </Container>
>
>   <Resource id="MoviesQueue" type="javax.jms.Queue"/>
>
> How I might connect to that queue from my MDB? I don't know how the example
> simple-mdb <http://tomee.apache.org/examples-trunk/simple-mdb/README.html>
> does it. Here you have the code of my MDB:
>
> @MessageDriven(activationConfig = {
>     @ActivationConfigProperty(propertyName = "destination",
>             propertyValue = "openejb:Resource/MoviesQueue"),
>     @ActivationConfigProperty(propertyName = "destinationType",
>             propertyValue = "javax.jms.Queue")})
> public class MoviesLog implements MessageListener {
>
>     private static final Logger logger =
> Logger.getLogger(MoviesLog.class.getName());
>
>     @Resource
>     private MessageDrivenContext mdc;
>
>     @Override
>     public void onMessage(Message message) {
>         TextMessage msg;
>         try {
>             if (message instanceof TextMessage) {
>                 msg = (TextMessage) message;
>
>                 logger.log(Level.INFO, "Message received {0}",
> msg.getText());
>             } else {
>                 logger.log(Level.WARNING, "Message received of a wrong type
> {0}", message.getClass().getName());
>             }
>         } catch (JMSException ex) {
>             logger.log(Level.SEVERE, null, ex);
>
>             mdc.setRollbackOnly();
>         }
>     }
>
> }
>
> Regards,
>
> Paco.
>
>
>
>
> --
> View this message in context: http://openejb.979440.n4.nabble.com/MDB-doesn-t-read-messages-tp4666169.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.