You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Karl Kildén <ka...@gmail.com> on 2013/10/24 19:39:38 UTC

Learning EJB with CDI background

Hello,

as someone who previously used only plain tomcat I finally decided to let
go of old principles and start using parts of EJB that looks promising.

I am very quite accustomed to CDI and I must say the syntax I've seen in
most examples so far is confusing and for the most part not so pretty.
Anyways I would just like to clear out some fundamentals to see if I got
this right.

*What I want: *Message Driven Beans are my main reason for wanting in. My
interpretation is that I can get a pool with MDB instances consuming
messages asynchronously with a transactional nature. It's sounds like
something that could scale out well as a Middleware and I need just that.

*How I tried it (based of tomee examples): *
*
*
https://gist.github.com/karlkilden/7141469  <---- My MDB

https://gist.github.com/karlkilden/7141488 <----- My Example Msg Producer


The following are my questions:

1. Does it look "right"?

2. Must my producer use name = "some name" for the @Resource injection of
the queue and my @MessageDriven have that good awful
 @ActivationConfigProperty to map them together?

3.  Can use a MDB with just a @MessageDriven (since no values seems
mandatory)? I tried that but it didn't work so It confused me.

4.  I Inject a ConnectionFactory with @Resource. Can I inject it with
@Inject? Why not @Inject the session directly? Can I fix it with a CDI
producer?


Any good resource for some more fundamentals and updated for EE7 (or at
least EE6)?  For example I don't understand what's supposed to go
in ejb-jar.xml and tomee.xml. I don't get the concept of "mappedBy".

Finally, When I run my example it looks right and my loggers behaves as if
it got the message but in the log i get the following:

okt 24, 2013 7:08:57 EM org.apache.geronimo.connector.work.WorkerContext run
INFO: Removing non-required WorkContextHandler with no context:
org.apache.geronimo.connector.work.TransactionContextHandler@6df8723c
okt 24, 2013 7:08:57 EM org.apache.geronimo.connector.work.WorkerContext run
INFO: Removing non-required WorkContextHandler with no context:
org.apache.openejb.core.security.SecurityContextHandler@1d643ec6
okt 24, 2013 7:08:57 EM org.apache.geronimo.connector.work.WorkerContext run
INFO: Removing non-required WorkContextHandler with no context:
org.apache.geronimo.connector.work.HintsContextHandler@41561668


I don't understand what that means. However very few libraries log frequent
happy flows so It has me concerned...

Thanks for reading, cheers

Re: Learning EJB with CDI background

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

logs are about the JCA threads and JTA contexts. That's ok.

Your code seems ok, you need to close MessageProducer too. You can
create CDI producers to get Session but I have to admit I don't know
if @RequestScoped would work here. A custom scope started/stopped in a
MDB interceptor would work.

openejb-jar.xml doesn't need anything

about tomee.xml all is here
http://tomee.apache.org/containers-and-resources.html:

ActiveMQResourceAdapter, ConnectionFactory, Queue, MESSAGE (all have defaults)
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2013/10/24 Karl Kildén <ka...@gmail.com>:
> Hello,
>
> as someone who previously used only plain tomcat I finally decided to let
> go of old principles and start using parts of EJB that looks promising.
>
> I am very quite accustomed to CDI and I must say the syntax I've seen in
> most examples so far is confusing and for the most part not so pretty.
> Anyways I would just like to clear out some fundamentals to see if I got
> this right.
>
> *What I want: *Message Driven Beans are my main reason for wanting in. My
> interpretation is that I can get a pool with MDB instances consuming
> messages asynchronously with a transactional nature. It's sounds like
> something that could scale out well as a Middleware and I need just that.
>
> *How I tried it (based of tomee examples): *
> *
> *
> https://gist.github.com/karlkilden/7141469  <---- My MDB
>
> https://gist.github.com/karlkilden/7141488 <----- My Example Msg Producer
>
>
> The following are my questions:
>
> 1. Does it look "right"?
>
> 2. Must my producer use name = "some name" for the @Resource injection of
> the queue and my @MessageDriven have that good awful
>  @ActivationConfigProperty to map them together?
>
> 3.  Can use a MDB with just a @MessageDriven (since no values seems
> mandatory)? I tried that but it didn't work so It confused me.
>
> 4.  I Inject a ConnectionFactory with @Resource. Can I inject it with
> @Inject? Why not @Inject the session directly? Can I fix it with a CDI
> producer?
>
>
> Any good resource for some more fundamentals and updated for EE7 (or at
> least EE6)?  For example I don't understand what's supposed to go
> in ejb-jar.xml and tomee.xml. I don't get the concept of "mappedBy".
>
> Finally, When I run my example it looks right and my loggers behaves as if
> it got the message but in the log i get the following:
>
> okt 24, 2013 7:08:57 EM org.apache.geronimo.connector.work.WorkerContext run
> INFO: Removing non-required WorkContextHandler with no context:
> org.apache.geronimo.connector.work.TransactionContextHandler@6df8723c
> okt 24, 2013 7:08:57 EM org.apache.geronimo.connector.work.WorkerContext run
> INFO: Removing non-required WorkContextHandler with no context:
> org.apache.openejb.core.security.SecurityContextHandler@1d643ec6
> okt 24, 2013 7:08:57 EM org.apache.geronimo.connector.work.WorkerContext run
> INFO: Removing non-required WorkContextHandler with no context:
> org.apache.geronimo.connector.work.HintsContextHandler@41561668
>
>
> I don't understand what that means. However very few libraries log frequent
> happy flows so It has me concerned...
>
> Thanks for reading, cheers