activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Niall Kelly <nial...@gmail.com>
Subject How to successfully use ActiveMQ 5.5.1 in a J2EE environment
Date Tue, 06 Mar 2012 16:27:05 GMT
Hi,

I'm currently using ActiveMQ 5.5.1 and have the resource adapter
activemq-rar-5.5.1.rar deployed within Glassfish 3.1. My connection pool is
set to use 'NoTransaction', however I'm coming across the exception
'javax.jms.JMSException: The resource is allready being used in transaction
context.'.  I found issue AMQ-3465 for this which is fixed in 5.6.0, but I'm
wondering if its possible to avoid this problem and if my use of the JMS
connection is correct.

I'd appreciate it if anyone could tell me if they are able to successfully
use ActiveMQ 5.5.1 from a J2EE environment without coming across this
exception? 
My current usage looks like this:


import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

@Stateless
public class ActiveMQExample {

    @Resource(name = "jms/ActiveMQFactory")
    private ConnectionFactory connectionFactory;

    @Resource(name = "jms/VirtualTopic.SampleTopic")
    private Destination sampleTopicDestination;

    public void submitMessage() throws JMSException {

            Connection connection = connectionFactory.createConnection();
            connection.start();
            Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
            MessageProducer producer =
session.createProducer(sampleTopicDestination);
            TextMessage msg = session.createTextMessage();
            msg.setText("Sample message");
            producer.send(msg);
            session.close();
            connection.close();	
   }

}

Regards,
Niall

--
View this message in context: http://activemq.2283324.n4.nabble.com/How-to-successfully-use-ActiveMQ-5-5-1-in-a-J2EE-environment-tp4450425p4450425.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Mime
View raw message