Allow the use of a transacted session in a #Servlet with #JMS broker #Artemis

By | March 21, 2019

The open-source application server WildFly from which the RedHat owned JBoss application server is derived is one of the most used Java application server lately. This is caused by the strong market consolidation that is happening that caused the Java application server environment to become very restricted. Basically the only open-source enterprise grade Java application server that remained is WildFly.

WildFly is a project with a high feature count and with a fast development cycle. You have to be careful with what version you stick around if you are pressed by constraints like: stability, legacy features support etc.

I am a long time user of WildFly 10 and now in the process of upgrading to WildFly 13. Yes not the latest version because I have some legacy source code constraints that forces me to not consider yet WildFly 14 and up.

The biggest change between WildFly 10 and WildFly 13 for me is the fact that now WildFly 13 includes an Artemis implementation of the JMS engine. This means that all the internal JMS queues used by some enterprise applications no longer need to be defined in an external ActiveMQ server.

More on how to migrate from ActiveMQ to Artemis in another post.

The first issue I noticed after migrating to the internal Artemis JMS engine was an issue with sending messages to a JMS queue from an internal Servlet. The following exception occurred:

[0m.[31m18:09:39,851 ERROR [com….view.action.MyServlet] (ServerService Thread Pool — 90) An error occured while sending message for startup.: javax.jms.JMSException: AMQ159007: Invalid Session Mode SESSION_TRANSACTED, to enable Local Transacted Sessions you can set the allowLocalTransactions (allow-local-transactions) on the resource adapter
at org.apache.activemq.artemis.ra.ActiveMQRASessionFactoryImpl.allocateConnection(ActiveMQRASessionFactoryImpl.java:853)
at org.apache.activemq.artemis.ra.ActiveMQRASessionFactoryImpl.createQueueSession(ActiveMQRASessionFactoryImpl.java:302)

I like how this looks like an error caused by some deprecated configuration or settings. This is indicated by the fact that the error seems to give us some solution to the issue: “to enable Local Transacted Sessions you can set the allowLocalTransactions (allow-local-transactions) on the resource adapter

       <subsystem xmlns="urn:jboss:domain:messaging-activemq:3.0">
            <server name="default">
                <security enabled="false"/>
                <management address="localhost" jmx-enabled="true" jmx-domain="org.apache.activemq.artemis"/>
                <security-setting name="#">
                    <role name="guest" send="true" consume="true" create-non-durable-queue="true" delete-non-durable-queue="true"/>
                </security-setting>
                <address-setting name="#" dead-letter-address="queue/mq.sys.dmq" expiry-address="jms.queue.ExpiryQueue" max-size-bytes="10485760" page-size-bytes="2097152" message-counter-history-day-limit="10"/
>
                <http-connector name="http-connector" socket-binding="http" endpoint="http-acceptor"/>
                <http-connector name="http-connector-throughput" socket-binding="http" endpoint="http-acceptor-throughput">
                    <param name="batch-delay" value="50"/>
                </http-connector>
                <in-vm-connector name="in-vm" server-id="0">
                    <param name="buffer-pooling" value="false"/>
                </in-vm-connector>
                <http-acceptor name="http-acceptor" http-listener="default"/>
                <http-acceptor name="http-acceptor-throughput" http-listener="default">
                    <param name="batch-delay" value="50"/>
                    <param name="direct-deliver" value="false"/>
                </http-acceptor>
                <remote-acceptor name="internal-messaging-acceptor" socket-binding="internal-messaging"/>
                <in-vm-acceptor name="in-vm" server-id="0">
                    <param name="buffer-pooling" value="false"/>
                </in-vm-acceptor>
                <jms-queue name="ExpiryQueue" entries="java:/jms/queue/ExpiryQueue"/>
                <jms-queue name="mq.sys.dmq" entries="java:/queue/mq.sys.dmq java:jboss/exported/queue/mq.sys.dmq"/>
                <jms-queue name="startup" entries="queue/startup java:jboss/exported/jms/queue/startup"/>
                <jms-queue name="accountingSpace" entries="queue/accountingSpace java:jboss/exported/jms/queue/accountingSpace"/>
                <jms-queue name="dummy" entries="queue/dummy java:jboss/exported/jms/queue/dummy"/>
                <connection-factory name="InVmConnectionFactory" entries="java:/ConnectionFactory" connectors="in-vm"/>
                <connection-factory name="RemoteConnectionFactory" entries="java:jboss/exported/jms/RemoteConnectionFactory" connectors="http-connector"/>
                <pooled-connection-factory name="activemq-ra" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" connectors="in-vm" transaction="xa">
                   <outbound-config allow-local-transactions="true"/>
                </pooled-connection-factory>
            </server>
        </subsystem>

Contribute to this site maintenance !

This is a self hosted site, on own hardware and Internet connection, the old, down to earth way 🙂. If you think that you found something useful here please contribute. Choose the form below (default 1 EUR) or donate using Bitcoin (default 0.0001 BTC) using the QR code. Thank you !

€1.00

One thought on “Allow the use of a transacted session in a #Servlet with #JMS broker #Artemis

  1. Pingback: Migrate from #Wildfly 10 + external #ActiveMQ to #Wildfly 13 + embedded #Artemis – blog.voina.org

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.