You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by Claudio Cumetti <cl...@hotmail.com> on 2006/07/05 15:39:35 UTC

XA Transactions

I have a container managed stateless session EJB that inserts a row into a
database table using an XA Data Source.  From within that same EJB, I want
to be able to post a JBI message using ServiceMix and have that participate
in the same XA transaction.  Is that supported?  Could you provide me with a
how-to or snippet of code of how it's done?

Thanks,

Claudio Cumetti
claudio_cumetti@hotmail.com

-- 
View this message in context: http://www.nabble.com/XA-Transactions-tf1894755.html#a5181783
Sent from the ServiceMix - User forum at Nabble.com.


Re: XA Transactions

Posted by Claudio Cumetti <cl...@hotmail.com>.
Thanks, Bruce.

I'm interested in making a programmatic call from within my EJB which is NOT
running within a JBI container.

I looked at the sample code from the link that you provided me.  Here is a
snippet of it:

    public void sendMessages(ComponentContext context, int count) throws
MessagingException {
        DeliveryChannel deliveryChannel = context.getDeliveryChannel();
        MessageExchangeFactory factory =
deliveryChannel.createExchangeFactory();

        for (int i = 0; i < count; i++) {
            InOnly exchange = factory.createInOnlyExchange();
            NormalizedMessage message = exchange.createMessage();
            exchange.setInMessage(message);

            message.setProperty("id", new Integer(i));
            message.setContent(new StringSource("<example id='" + i +
"'/>"));

            deliveryChannel.send(exchange);
        }
    }

This method implies that you have a reference to an variable named "context"
which is defined as type ComponentContext.

How do I instantiate an instance of it from the client code (which is the
EJB in my case)?

Thanks,

Claudio
-- 
View this message in context: http://www.nabble.com/XA-Transactions-tf1894755.html#a5223618
Sent from the ServiceMix - User forum at Nabble.com.


Re: XA Transactions

Posted by Bruce Snyder <br...@gmail.com>.
On 7/5/06, Claudio Cumetti <cl...@hotmail.com> wrote:
>
> I have a container managed stateless session EJB that inserts a row into a
> database table using an XA Data Source.  From within that same EJB, I want
> to be able to post a JBI message using ServiceMix and have that participate
> in the same XA transaction.  Is that supported?  Could you provide me with a
> how-to or snippet of code of how it's done?

Claudio,

This depends on how you're developing your application actually. Are
you defining a flow in ServiceMix and one of the endpoints is a
Servlet fronting the EJB or are you simply looking to make a
programmatic call from within your EJB?

If you're looking to make the EJB an endpoint in a flow, I think the
only way to do this currently would be to front the EJB with a
Servlet. This would allow the EJB to be executed via HTTP and using
HTTP allows for an endpoint to be defined in ServiceMix. An example of
this type of client HTTP invocation is noted here:

http://goopen.org/confluence/display/SM/HTTP#HTTP-ClientsideHTTPinvocation

If you're interested in making a programmatic call from within your
EJB, this can be done using the ServiceMix client API. Examples are
provided here:

http://goopen.org/confluence/display/SM/Pojo%20Support#POJOsupport-BeingevenmorePOJO

There are also more examples of this here:

http://servicemix.org/site/client-api.html

Bruce
-- 
perl -e 'print unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'

Apache Geronimo - http://geronimo.apache.org/
Apache ActiveMQ - http://incubator.apache.org/activemq/
Apache ServiceMix - http://incubator.apache.org/servicemix/
Castor - http://castor.org/