JMS Transaction Confusion
cpuffalt Nov 20, 2012 1:10 PMI'm using JBoss v7.1.2 and have been having grief getting JMS messaging to work. Messages were seemingly being posted to a Queue without error but nothing was appearing in the corresponding consuming MDB.
Here's my setup:
{code}
$ ./bin/jboss-cli.sh
You are disconnected at the moment. Type 'connect' to connect to the server or 'help' for the list of supported commands.
[disconnected /] connect
[standalone@localhost:9999 /] jms-queue add --queue-address=MailServiceQ --entries=jms/queue/MailServiceQ
[standalone@localhost:9999 /] exit
{code}
A stateless session bean which posts messages to the queue:
{code}
@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class JmsMailService implements MailServiceRemote
{
@Resource(mappedName = "java:/ConnectionFactory")
private ConnectionFactory connectionFactory;
@Resource(mappedName = "java:/jms/queue/MailServiceQ")
private Queue queue;
@Override
public void sendMessage(EmailMessage msg)
{
Connection connection = null;
try
{
connection = connectionFactory.createConnection();
// This does not seem to work??
Session session =
connection.createSession(true, Session.SESSION_TRANSACTED);
// This works??
// connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer messageProducer = session.createProducer(queue);
connection.start();
ObjectMessage jmsMsg = session.createObjectMessage(msg);
messageProducer.send(jmsMsg);
}
catch (Exception e)
{ throw new RuntimeException(e); }
finally
{
if (connection != null) { try { connection.close(); } catch (JMSException e) { } }
}
}
}
{code}
And a MDB to consume the messages:
{code}
@MessageDriven(name = "MailServiceMDB", activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "java:/jms/queue/MailServiceQ"),
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })
@Singleton
@Startup
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class MailProcessor implements MessageListener
{
public void onMessage(Message m)
{
jmsMsg = (EmailMessage) ((ObjectMessage) m).getObject();
handleMessage(jmsMsg);
}
}
{code}
Can someone explain why messages are not received by the MDB at all when using a transacted JMS Session. I get no errors but the MDB never receives messages. If I change the Session to non-transacted in the connection.createSession() call then messages are delivered? Is it a bug? My understanding is that the parameters to the createSession() method are basically ignored when called from a session bean using container-managed transactions?
Thanks,
Corey