How do I *send* JMS messages from an MDB?

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

How do I *send* JMS messages from an MDB?

Bjorn Danielsson
I have problems sending JMS messages from my MDB. This MDB
listens on a queue and then calls an EJB that updates persistent
storage. The EJB then sends out a notification to a JMS topic.

All this used to work in GlassFish, but on TomEE-plus I always
get this error that stops the notification from being sent:

javax.jms.JMSException: The resource is allready being used in transaction context.

The error message doesn't specify which resource is the culprit,
but I guess it means the JMS Session? My EJB uses an injected
ConnectionFactory, just like in the OpenEJB examples. Shouldn't
that work also when the EJB is called from an MDB, using one
big nice container-managed transaction that starts when the
incoming queue message is received?

Version: apache-tomee-plus-1.0.0-beta-2

--
Björn Danielsson
Cuspy Code AB
Reply | Threaded
Open this post in threaded view
|

Re: How do I *send* JMS messages from an MDB?

Romain Manni-Bucau
Hi,

It should work, can you reproduce it in a uniy test?
Le 16 avr. 2012 16:48, "Bjorn Danielsson" <[hidden email]>
a écrit :

> I have problems sending JMS messages from my MDB. This MDB
> listens on a queue and then calls an EJB that updates persistent
> storage. The EJB then sends out a notification to a JMS topic.
>
> All this used to work in GlassFish, but on TomEE-plus I always
> get this error that stops the notification from being sent:
>
> javax.jms.JMSException: The resource is allready being used in transaction
> context.
>
> The error message doesn't specify which resource is the culprit,
> but I guess it means the JMS Session? My EJB uses an injected
> ConnectionFactory, just like in the OpenEJB examples. Shouldn't
> that work also when the EJB is called from an MDB, using one
> big nice container-managed transaction that starts when the
> incoming queue message is received?
>
> Version: apache-tomee-plus-1.0.0-beta-2
>
> --
> Björn Danielsson
> Cuspy Code AB
>
Reply | Threaded
Open this post in threaded view
|

Re: How do I *send* JMS messages from an MDB?

Bjorn Danielsson
Hi,

Thanks for your reassuring reply! I have now written a simple
test for this, and of course now the test works. So mea culpa,
and now I only have to figure out in what way my application
code differs from my 100-line test. I'll post back here again
when I find the reason, in case anyone else gets this error
"resource is allready being used in transaction" and googles it.

--
Björn Danielsson
Cuspy Code AB


Romain Manni-Bucau <[hidden email]> wrote:

> Hi,
>
> It should work, can you reproduce it in a uniy test?
> Le 16 avr. 2012 16:48, "Bjorn Danielsson" <[hidden email]>
> a écrit :
>
>> I have problems sending JMS messages from my MDB. This MDB
>> listens on a queue and then calls an EJB that updates persistent
>> storage. The EJB then sends out a notification to a JMS topic.
>>
>> All this used to work in GlassFish, but on TomEE-plus I always
>> get this error that stops the notification from being sent:
>>
>> javax.jms.JMSException: The resource is allready being used in transaction
>> context.
>>
>> The error message doesn't specify which resource is the culprit,
>> but I guess it means the JMS Session? My EJB uses an injected
>> ConnectionFactory, just like in the OpenEJB examples. Shouldn't
>> that work also when the EJB is called from an MDB, using one
>> big nice container-managed transaction that starts when the
>> incoming queue message is received?
>>
>> Version: apache-tomee-plus-1.0.0-beta-2
>>
>> --
>> Björn Danielsson
>> Cuspy Code AB
>>
Reply | Threaded
Open this post in threaded view
|

Re: How do I *send* JMS messages from an MDB?

Bjorn Danielsson
Update

I can now reproduce the error in a small test program.
All I did was increase the messaging from 2 to 4 messages
and fiddle a bit with the JPA code. The fiddling required
seems to be different depending on whether I use OpenJPA
or EclipseLink.

I am beginning to suspect that I might be bitten by this
bug, fixed in ActiveMQ 5.6.0:

https://issues.apache.org/jira/browse/AMQ-3465

Now I am itching to try a newer ActiveMQ than the bundled one.
Is this possible? I naively tried replacing the activemq-core
jar but that just gave me "peer did not send his wire format".

--
Björn Danielsson
Cuspy Code AB
Reply | Threaded
Open this post in threaded view
|

Re: How do I *send* JMS messages from an MDB?

Romain Manni-Bucau
Hi,

i think activemq-ra should be updated too. I don't know if there is API
changes between both version but i guess you'll see it soon ;).

- Romain


2012/4/17 Bjorn Danielsson <[hidden email]>

> Update
>
> I can now reproduce the error in a small test program.
> All I did was increase the messaging from 2 to 4 messages
> and fiddle a bit with the JPA code. The fiddling required
> seems to be different depending on whether I use OpenJPA
> or EclipseLink.
>
> I am beginning to suspect that I might be bitten by this
> bug, fixed in ActiveMQ 5.6.0:
>
> https://issues.apache.org/jira/browse/AMQ-3465
>
> Now I am itching to try a newer ActiveMQ than the bundled one.
> Is this possible? I naively tried replacing the activemq-core
> jar but that just gave me "peer did not send his wire format".
>
> --
> Björn Danielsson
> Cuspy Code AB
>
Reply | Threaded
Open this post in threaded view
|

Re: How do I *send* JMS messages from an MDB?

AndyG
These are the required activemq jars:

openejb\lib\activeio-core-3.2-20090713.104929-1.jar
openejb\lib\activemq-core-5.6-SNAPSHOT.jar
openejb\lib\activemq-protobuf-1.1.jar
openejb\lib\activemq-ra-5.6-SNAPSHOT.jar
openejb\lib\kahadb-5.6-SNAPSHOT.jar
Reply | Threaded
Open this post in threaded view
|

Re: How do I *send* JMS messages from an MDB?

Romain Manni-Bucau
i think pulling activemq-ra should be enough with maven to override the
version.

@Andy: did you try?

- Romain


2012/4/17 AndyG <[hidden email]>

> These are the required activemq jars:
>
> openejb\lib\activeio-core-3.2-20090713.104929-1.jar
> openejb\lib\activemq-core-5.6-SNAPSHOT.jar
> openejb\lib\activemq-protobuf-1.1.jar
> openejb\lib\activemq-ra-5.6-SNAPSHOT.jar
> openejb\lib\kahadb-5.6-SNAPSHOT.jar
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/How-do-I-send-JMS-messages-from-an-MDB-tp4561773p4564896.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: How do I *send* JMS messages from an MDB?

AndyG
This post was updated on .
In reply to this post by Bjorn Danielsson
Bjorn Danielsson wrote
The EJB then sends out a notification to a JMS topic
How is this EJB sending the message?

javax.jms.JMSException: The resource is already being used in transaction context. - Means exactly that, and it is usually a good sign that there is some misuse or a concurrency issue at the root.

Access to a shared JMS resource is crossing a transaction/thread boundary and this will only happen if two or more threads are concurrently accessing the resource.

Never share a JMS Connection/topic or queue across different threads, putting them in a Singleton is always a good idea as this allows you to keep the connection open for the application lifetime. Here is a really dumbed down example:

@Singleton
SomeClass....

private Connection conJms = null;

@Resource(mappedName = "JMSConnectionFactory")
private ConnectionFactory connectionFactory;

@Override
public void sendMessage(final String messge) {
    if(null == this.conJms){
        this.conJms = this.connectionFactory.createConnection();
        //Do some JMS magic, open a queue and or topic etc etc....
    }

    //Send the message here
}

@PreDestroy
public void preDestroy() {
    //Cleanup and close this.conJms and any queues and topics etc...
}

Any EJB that wants to send a message must then inject the 'SomeClass' instance:

@EJB
private SomeClass sc;
....
this.sc.sendMessage("Hello Tom, Dick and Harry");
Reply | Threaded
Open this post in threaded view
|

Re: How do I *send* JMS messages from an MDB?

AndyG
In reply to this post by Romain Manni-Bucau
Romain Manni-Bucau wrote
i think pulling activemq-ra should be enough with maven to override the
version.

@Andy: did you try?
I pull, build and deploy activemq daily snapshot to my local repo, but:

<org.apache.activemq.version>5.6-SNAPSHOT</org.apache.activemq.version>

...will do the trick.
Reply | Threaded
Open this post in threaded view
|

Re: How do I *send* JMS messages from an MDB?

Romain Manni-Bucau
was more about the integration with openejb. I remember we had some API
changes mounths ago.

- Romain


2012/4/17 AndyG <[hidden email]>

>
> Romain Manni-Bucau wrote
> >
> > i think pulling activemq-ra should be enough with maven to override the
> > version.
> >
> > @Andy: did you try?
> >
>
> I pull, build and deploy activemq daily snapshot to my local repo, but:
>
> <org.apache.activemq.version>5.6-SNAPSHOT</org.apache.activemq.version>
>
> ...will do the trick.
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/How-do-I-send-JMS-messages-from-an-MDB-tp4561773p4565102.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: How do I *send* JMS messages from an MDB?

Bjorn Danielsson
In reply to this post by AndyG
Problem solved!

Thanks AndyG, this did the trick. I compiled a fresh ActiveMQ
snapshot (r1327126) and replaced the files from your list, and
now everything works. Tried with OpenJPA and EclipseLink, both
worked without a glitch. So the bug was in ActiveMQ-5.5.1.

--
Björn Danielsson
Cuspy Code AB


AndyG <[hidden email]> wrote:

> These are the required activemq jars:
>
> openejb\lib\activeio-core-3.2-20090713.104929-1.jar
> openejb\lib\activemq-core-5.6-SNAPSHOT.jar
> openejb\lib\activemq-protobuf-1.1.jar
> openejb\lib\activemq-ra-5.6-SNAPSHOT.jar
> openejb\lib\kahadb-5.6-SNAPSHOT.jar
>
>
> --
> View this message in context: http://openejb.979440.n4.nabble.com/How-do-I-send-JMS-messages-from-an-MDB-tp4561773p4564896.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: How do I *send* JMS messages from an MDB?

Romain Manni-Bucau
Thanks for the feedback!

- Romain
Le 17 avr. 2012 18:31, "Bjorn Danielsson" <[hidden email]>
a écrit :

> Problem solved!
>
> Thanks AndyG, this did the trick. I compiled a fresh ActiveMQ
> snapshot (r1327126) and replaced the files from your list, and
> now everything works. Tried with OpenJPA and EclipseLink, both
> worked without a glitch. So the bug was in ActiveMQ-5.5.1.
>
> --
> Björn Danielsson
> Cuspy Code AB
>
>
> AndyG <[hidden email]> wrote:
> > These are the required activemq jars:
> >
> > openejb\lib\activeio-core-3.2-20090713.104929-1.jar
> > openejb\lib\activemq-core-5.6-SNAPSHOT.jar
> > openejb\lib\activemq-protobuf-1.1.jar
> > openejb\lib\activemq-ra-5.6-SNAPSHOT.jar
> > openejb\lib\kahadb-5.6-SNAPSHOT.jar
> >
> >
> > --
> > View this message in context:
> http://openejb.979440.n4.nabble.com/How-do-I-send-JMS-messages-from-an-MDB-tp4561773p4564896.html
> > Sent from the OpenEJB User mailing list archive at Nabble.com.
>