-
1. Re: XA datasource with JBM problem
ataylor Aug 19, 2008 11:39 AM (in response to perisb)firstly, what versions are you using. secondly, if you think its not working as required can you provide a test case.
-
2. Re: XA datasource with JBM problem
perisb Aug 19, 2008 1:16 PM (in response to perisb)I am on 4.0.2
Here is the Interceptor:
package test;
import org.jboss.invocation.Invocation;
import org.jboss.ejb.Interceptor;
import org.jboss.ejb.Container;
import org.jboss.ejb.EntityContainer;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.jms.*;
import javax.ejb.EJBObject;
import javax.transaction.TransactionManager;
import java.lang.reflect.Method;
import java.util.Arrays;
public
class TestInterceptor implements Interceptor {
public
void setNext(Interceptor next) {
this.next = next;
}
public
Interceptor getNext() {
return next;
}
public
void setContainer(Container container) {
this.container = (EntityContainer)container;
}
public
void create() throws Exception {
name = container.getBeanMetaData().getEjbName();
if (!name.equals("Foo")) // only operate on entity Foo
return;
Context ctx = new InitialContext();
QueueConnectionFactory qcf = (QueueConnectionFactory)ctx.lookup("java:/JmsXA");
conn = qcf.createQueueConnection();
queue = (Queue)ctx.lookup("queue/DDSListenerQ");
session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
conn.start();
}
public
Object invokeHome(Invocation invocation) throws Exception {
Object returnValue = getNext().invokeHome(invocation);
return returnValue;
}
public
Object invoke(Invocation invocation) throws Exception {
Object returnValue = getNext().invoke(invocation);
if (!name.equals("Foo"))
return returnValue;
Method method = invocation.getMethod();
if (method != null) {
String mname = method.getName();
if (mname.startsWith("set")) {
QueueSender sender = session.createSender(queue);
TextMessage tm = session.createTextMessage(invocation.getId()+",mname.substring(3),"+invocation.getArguments()[0]);
sender.send(tm);
sender.close();
}
}
return returnValue;
}
public
void start() throws Exception {
}
public
void stop() {
}
public
void destroy() {
//session.close();
//conn.close();
}
private Interceptor next;
private EntityContainer container;
private String name;
private QueueConnection conn;
private QueueSession session;
private Queue queue;
}
Here is the remote client test driver snippet: (there is an EJB wrapper framework in place; the Context object wraps UserTransaction, FooHomeRemote, etc.)
Context ctx = ContextRemoteImpl.instance();
ctx.begin();
Foo foo = ctx.FooFactory().findByOID(333l);
foo.setBar("Bat");
ctx.rollback();
Finally, here is an MDB that listens to the Queue, and receives a message, even though the client rolls back:
package test;
import javax.ejb.MessageDrivenBean;
import javax.ejb.MessageDrivenContext;
import javax.ejb.EJBException;
import javax.jms.MessageListener;
import javax.jms.Message;
public
class TestMDBImpl implements MessageDrivenBean, MessageListener {
public
void ejbCreate() {
}
public
void setMessageDrivenContext(MessageDrivenContext mdc) {
}
public
void onMessage(Message message) {
System.err.println("GOT MESSAGE:"+message);
}
public
void ejbRemove() throws EJBException {\
}
} -
3. Re: XA datasource with JBM problem
ataylor Aug 20, 2008 4:01 AM (in response to perisb)Which version of JBoss Messaging are you using, can you try with the latest versions (jboss 4.2.2 with JBM 1.4) to make sure it is still a problem.
-
4. Re: XA datasource with JBM problem
timfox Aug 20, 2008 4:38 AM (in response to perisb)Looks like you're creating a non transacted session.
There are lots of examples around of doing this correctly. I suggest you find one of those and copy it. -
5. Re: XA datasource with JBM problem
perisb Aug 20, 2008 9:16 AM (in response to perisb)So can I take it that what I am trying to do should be doable?
ataylor: I am using what comes bundled with 4.0.2. I can try moving to 4.2.2 just to know, if you're saying that this pattern is not supported under 4.0.2, but 4.0.2 is still our production environment.
timfox: The example I used came from the 4.0.2 admin guide. Since my last post, I noticed the transacted-session problem, said "aha!", and changed the first argument to createQueueSession() to true. This had no effect :{(>
Where might I find working examples of this, please? In the forum? I've read the admin guide, the wiki, the users guide, and failed.
I didn't really expect to find a working example of an Interceptor, so my first question is "should this work?". The JBMXADataSource wiki entry leads me to believe that can; it just lacks a working example. -
6. Re: XA datasource with JBM problem
timfox Aug 20, 2008 9:25 AM (in response to perisb)Ah I just noticed you're using an interceptor, I thought you were using an EJB which is an extremely common pattern.
The JMS JCA resource adapter requires a managed environment (read servlet or EJB) otherwise transaction won't get enlisted automatically. But this is app server stuff and not part of JBoss Messaging.
I've never seen anyone do what you're doing before so no idea whether it would work or not. Best to ask the JCA/AS guys. As I say, none of this is part of JBM. -
7. Re: XA datasource with JBM problem
perisb Aug 20, 2008 9:50 AM (in response to perisb)So your saying the enlistment of the JMS Session as an XA resource has nothing to do with JBM (or is completely orthogonal to it)? If not, is there anything explicit I can do to make this work?
Just curious: the connection factory name java:/JmsXA I'm using returns a JmsConnectionFactory. Snooping the source I noticed class JmsManagedConnectionFactory. What would be the purpose of this? -
8. Re: XA datasource with JBM problem
timfox Aug 20, 2008 9:55 AM (in response to perisb)"perisb" wrote:
So your saying the enlistment of the JMS Session as an XA resource has nothing to do with JBM (or is completely orthogonal to it)?
Yes, the resource enlistment is done by the JCA adapter, not JBM.
Just curious: the connection factory name java:/JmsXA I'm using returns a JmsConnectionFactory. Snooping the source I noticed class JmsManagedConnectionFactory. What would be the purpose of this?
That's a JCA resource adapter. The JCA spec will explain what all those things mean.
The JCA adapter is not part of JBM, it's handled by the JCA team (which is part of the AS). -
10. Re: XA datasource with JBM problem
timfox Aug 20, 2008 1:35 PM (in response to perisb)"perisb" wrote:
If not, is there anything explicit I can do to make this work?
If you can get a reference to the transaction, then you can always enlist the resources yourself.
I.e. don't use JmsXA, use XAConnectionFactory, create an XAConnection, create an XASession, and enlist the XAResource in the JTA tx manually.
The tx should be associated to the current thread. Have a look at the JTA api to see how to do this.