hmm, my proposal was to use UserTransaction more than that. About this particular exemple we would need a maven project to reproduce it.
Romain Manni-Bucau @rmannibucau <https://twitter.com/rmannibucau> | Blog <http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> | LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber <http://www.tomitribe.com> 2015-04-15 4:05 GMT+02:00 Leonardo K. Shikida <[email protected]>: > Hi > > So I've changed my MDBs to stateless > > public class Worker implements MessageListener { > > @Resource(name="MyJmsConnectionFactory") > private ConnectionFactory connectionFactory; > > @Resource(name="DriverJobQueue") > private Queue queue; > > private Connection connection = null; > private Session session = null; > private MessageConsumer consumer = null; > > @PostConstruct > public void initialize() { > System.out.println("Instantiating "+this); > try { > connection = connectionFactory.createConnection(); > connection.start(); //activemq site says it's here > // Create a Session > session = connection.createSession(false, > Session.AUTO_ACKNOWLEDGE); > > // Create a MessageConsumer from the Session to the Topic or > Queue > consumer = session.createConsumer(this.queue); > > consumer.setMessageListener(this); > > // connection.start(); //some sites says it's here > > } catch(Exception e) { > e.printStackTrace(); > } finally { > if (consumer != null) { > try { > consumer.close(); > } catch (JMSException e) { > e.printStackTrace(); > } > } > if (session != null) { > try { > session.close(); > } catch (JMSException e) { > e.printStackTrace(); > } > } > if (connection != null) { > try { > connection.close(); > } catch (JMSException e) { > e.printStackTrace(); > } > } > } > } > > @Override > public void onMessage(Message msg) { > System.out.println("On message for "+this); > } > > openejb-jar.xml > > <?xml version="1.0"?> > <openejb-jar xmlns="http://www.openejb.org/openejb-jar/1.1"> > <ejb-deployment > ejb-name="Worker" > deployment-id="Worker" > container-id="pseudo_mdb" /> > </openejb-jar> > > tomee.xml > > <Container id="myAllContainer" type="STATELESS"> > strictPooling = false > </Container> > > <Container id="pseudo_mdb" type="STATELESS"> > strictPooling = true > maxSize = 5 > minSize = 3 > </Container> > > The container part seems to be right, since only the Worker bean is > instantiated early. > > But for some reason, it's not consuming from the queue. > > Am I missing something here? > > Still, I feel I am running in circles here... because even if I have some > control on the context, I still won't be able to catch the timeout > exception :-( > > grrrrrrrrrrrr > > [] > > Leo > > On Tue, Apr 14, 2015 at 6:08 PM, Leonardo K. Shikida <[email protected]> > wrote: > > > thx! > > > > [] > > > > Leo > > > > On Tue, Apr 14, 2015 at 6:03 PM, Romain Manni-Bucau < > [email protected] > > > wrote: > > > >> using openejb-jar.xml you can wire a container to some beans only. > >> > >> > >> Romain Manni-Bucau > >> @rmannibucau <https://twitter.com/rmannibucau> | Blog > >> <http://rmannibucau.wordpress.com> | Github < > >> https://github.com/rmannibucau> | > >> LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber > >> <http://www.tomitribe.com> > >> > >> 2015-04-14 22:59 GMT+02:00 Leonardo K. Shikida <[email protected]>: > >> > >> > yeah, I think this will be the way to go > >> > > >> > since I can configure max/min instances for stateless ( > >> > http://tomee.apache.org/statelesscontainer-config.html) I think I can > >> just > >> > create a pool of stateless instances to work as MDBs that can deal > with > >> > timeout :-) > >> > > >> > is there any way to configure a container just for these specfic > >> stateless > >> > EJBs (so some other configuration can be used for stateless by > default)? > >> > > >> > [] > >> > > >> > Leo > >> > > >> > On Tue, Apr 14, 2015 at 5:46 PM, Romain Manni-Bucau < > >> [email protected] > >> > > > >> > wrote: > >> > > >> > > so just handle transactions yourself > >> > > > >> > > > >> > > Romain Manni-Bucau > >> > > @rmannibucau <https://twitter.com/rmannibucau> | Blog > >> > > <http://rmannibucau.wordpress.com> | Github < > >> > > https://github.com/rmannibucau> | > >> > > LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber > >> > > <http://www.tomitribe.com> > >> > > > >> > > 2015-04-14 22:42 GMT+02:00 Lars-Fredrik Smedberg < > [email protected] > >> >: > >> > > > >> > > > Another option is to look at the redelivered property/redelivery > >> count > >> > > and > >> > > > take action (write to db?) in case of redelivery.... requires you > >> to > >> > > set a > >> > > > redelivery policy / number of retries etc > >> > > > > >> > > > /LF > >> > > > On Apr 14, 2015 10:39 PM, "Leonardo K. Shikida" < > [email protected]> > >> > > wrote: > >> > > > > >> > > > > Yup, but if the MDB timeout, I need to set something in the DB, > >> > that's > >> > > > why > >> > > > > I need to treat the timeout. > >> > > > > > >> > > > > If the job to be executed timeout, then it will probably timeout > >> for > >> > > any > >> > > > > retry, because it's caused by a poorly chosen parameter, so > >> retries > >> > are > >> > > > not > >> > > > > important here (although increasing timeouts on each retry could > >> be > >> > an > >> > > > > interesting option) > >> > > > > > >> > > > > [] > >> > > > > > >> > > > > Leo > >> > > > > > >> > > > > On Tue, Apr 14, 2015 at 5:27 PM, Romain Manni-Bucau < > >> > > > [email protected] > >> > > > > > > >> > > > > wrote: > >> > > > > > >> > > > > > Hmm, with MDBs you have retries since they are transactional. > >> you > >> > can > >> > > > > even > >> > > > > > configure the redelivery policy with an exponential backoff > and > >> so > >> > on > >> > > > if > >> > > > > > really needed > >> > > > > > > >> > > > > > > >> > > > > > Romain Manni-Bucau > >> > > > > > @rmannibucau <https://twitter.com/rmannibucau> | Blog > >> > > > > > <http://rmannibucau.wordpress.com> | Github < > >> > > > > > https://github.com/rmannibucau> | > >> > > > > > LinkedIn <https://www.linkedin.com/in/rmannibucau> | > Tomitriber > >> > > > > > <http://www.tomitribe.com> > >> > > > > > > >> > > > > > 2015-04-14 22:13 GMT+02:00 Leonardo K. Shikida < > >> [email protected] > >> > >: > >> > > > > > > >> > > > > > > Well, what I need is a pool of workers to listen to a queue > >> and > >> > > > process > >> > > > > > > messages while they come, but I also need to properly treat > >> them > >> > > when > >> > > > > the > >> > > > > > > JMS transaction times out. > >> > > > > > > > >> > > > > > > So I guess I can't use a MDB here right? > >> > > > > > > > >> > > > > > > What would be a good approach in this situation? > >> > > > > > > > >> > > > > > > [] > >> > > > > > > > >> > > > > > > Leo > >> > > > > > > > >> > > > > > > On Tue, Apr 14, 2015 at 4:53 PM, Romain Manni-Bucau < > >> > > > > > [email protected] > >> > > > > > > > > >> > > > > > > wrote: > >> > > > > > > > >> > > > > > > > if you want to control and be able to catch it you need to > >> > handle > >> > > > > > > yourself > >> > > > > > > > the transaction otherwise if it takes more then you'll > get a > >> > > > rollback > >> > > > > > > and a > >> > > > > > > > (surely wrapped) RollbackException > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > Romain Manni-Bucau > >> > > > > > > > @rmannibucau <https://twitter.com/rmannibucau> | Blog > >> > > > > > > > <http://rmannibucau.wordpress.com> | Github < > >> > > > > > > > https://github.com/rmannibucau> | > >> > > > > > > > LinkedIn <https://www.linkedin.com/in/rmannibucau> | > >> > Tomitriber > >> > > > > > > > <http://www.tomitribe.com> > >> > > > > > > > > >> > > > > > > > 2015-04-14 21:45 GMT+02:00 Leonardo K. Shikida < > >> > > [email protected] > >> > > > >: > >> > > > > > > > > >> > > > > > > > > just checking > >> > > > > > > > > > >> > > > > > > > > I just add > >> > > > > > > > > > >> > > > > > > > > @Resource > >> > > > > > > > > private TransactionManager tx; > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > and in the MDB initialization I set some timeout > >> > > > > > > > > > >> > > > > > > > > @PostConstruct > >> > > > > > > > > public void initialize() { > >> > > > > > > > > try { > >> > > > > > > > > tx.setTransactionTimeout(3); > >> > > > > > > > > } catch (SystemException e) { > >> > > > > > > > > e.printStackTrace(); > >> > > > > > > > > } > >> > > > > > > > > } > >> > > > > > > > > > >> > > > > > > > > and when my onMessage() executes, if it takes more than > 3 > >> > > seconds > >> > > > > to > >> > > > > > > > > complete, it throws and exception? > >> > > > > > > > > > >> > > > > > > > > and if so, how do I catch it? (or I don't?) > >> > > > > > > > > > >> > > > > > > > > [] > >> > > > > > > > > > >> > > > > > > > > Leo > >> > > > > > > > > > >> > > > > > > > > On Tue, Apr 14, 2015 at 4:20 PM, Leonardo K. Shikida < > >> > > > > > > [email protected]> > >> > > > > > > > > wrote: > >> > > > > > > > > > >> > > > > > > > > > thx! > >> > > > > > > > > > > >> > > > > > > > > > [] > >> > > > > > > > > > > >> > > > > > > > > > Leo > >> > > > > > > > > > > >> > > > > > > > > > On Tue, Apr 14, 2015 at 4:16 PM, Romain Manni-Bucau < > >> > > > > > > > > [email protected] > >> > > > > > > > > > > wrote: > >> > > > > > > > > > > >> > > > > > > > > >> Get the Transactionmanager injected (@Resource) and > >> call > >> > > > > > > > > >> setTransactionTimeout(seconds) > >> > > > > > > > > >> > >> > > > > > > > > >> > >> > > > > > > > > >> Romain Manni-Bucau > >> > > > > > > > > >> @rmannibucau <https://twitter.com/rmannibucau> | > Blog > >> > > > > > > > > >> <http://rmannibucau.wordpress.com> | Github < > >> > > > > > > > > >> https://github.com/rmannibucau> | > >> > > > > > > > > >> LinkedIn <https://www.linkedin.com/in/rmannibucau> | > >> > > > Tomitriber > >> > > > > > > > > >> <http://www.tomitribe.com> > >> > > > > > > > > >> > >> > > > > > > > > >> 2015-04-14 19:38 GMT+02:00 Leonardo K. Shikida < > >> > > > > [email protected] > >> > > > > > >: > >> > > > > > > > > >> > >> > > > > > > > > >> > Hi > >> > > > > > > > > >> > > >> > > > > > > > > >> > How do I increase the MDB onMessage() transaction > >> > timeout? > >> > > > > > > > > >> > > >> > > > > > > > > >> > [] > >> > > > > > > > > >> > > >> > > > > > > > > >> > Leo > >> > > > > > > > > >> > > >> > > > > > > > > >> > >> > > > > > > > > > > >> > > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > >> > > > > > > > >> > > > > > > >> > > > > > >> > > > > >> > > > >> > > >> > > > > >
