title: Error: AMQ154003: Unable to connect to JMS ActiveMQ using Wildfly
body: <p>I'm trying to create a simple JMS ActiveMQ connection in WildFly 19, using IntelliJ. I've followed setup guidelines, but I'm hitting a connection error.</p>
  
  <p>I'm running Wildfly as a local server, in standalone mode. I've updated the Startup Script environment variables in IntelliJ, to point to standalone-full.xml (apparently I need to use <code>standalone-full.xml</code>, in order to use JMS?)</p>
  
  <pre><code>/Users/../IdeaProjects/appservers/wildfly-19.1.0.Final/bin/standalone.sh
  JAVA_OPTS environment variable -Djboss.server.default.config=standalone-full.xml
  </code></pre>
  
  <p>I've updated the XML file to add the JMS queue I'm connecting to in my code:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;jms-queue name="HsportsQueue" entries="java:/jms/queue/HsportsQueue"/&gt;
  </code></pre>
  
  <p>The EAR is deploying and the JSF is rendering, but I'm getting a JMS error, which just infinitely loops in the stack trace. I've attached the <code>standalone-full.xml</code>, the stack trace and the java code.</p>
  
  <p>Any help would be massively appreciated.</p>
  
  <p><code>standalone-full.xml</code> (redacted due to character limit):</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  
  &lt;server xmlns="urn:jboss:domain:12.0"&gt;
      &lt;extensions&gt;
          &lt;extension module="org.jboss.as.clustering.infinispan"/&gt;
          &lt;extension module="org.jboss.as.connector"/&gt;
          &lt;extension module="org.jboss.as.deployment-scanner"/&gt;
          &lt;extension module="org.jboss.as.ee"/&gt;
          &lt;extension module="org.jboss.as.ejb3"/&gt;
          &lt;extension module="org.jboss.as.jaxrs"/&gt;
          &lt;extension module="org.jboss.as.jdr"/&gt;
          &lt;extension module="org.jboss.as.jmx"/&gt;
          &lt;extension module="org.jboss.as.jpa"/&gt;
          &lt;extension module="org.jboss.as.jsf"/&gt;
          &lt;extension module="org.jboss.as.jsr77"/&gt;
          &lt;extension module="org.jboss.as.logging"/&gt;
          &lt;extension module="org.jboss.as.mail"/&gt;
          &lt;extension module="org.jboss.as.naming"/&gt;
          &lt;extension module="org.jboss.as.pojo"/&gt;
          &lt;extension module="org.jboss.as.remoting"/&gt;
          &lt;extension module="org.jboss.as.sar"/&gt;
          &lt;extension module="org.jboss.as.security"/&gt;
          &lt;extension module="org.jboss.as.transactions"/&gt;
          &lt;extension module="org.jboss.as.webservices"/&gt;
          &lt;extension module="org.jboss.as.weld"/&gt;
          &lt;extension module="org.wildfly.extension.batch.jberet"/&gt;
          &lt;extension module="org.wildfly.extension.bean-validation"/&gt;
          &lt;extension module="org.wildfly.extension.clustering.web"/&gt;
          &lt;extension module="org.wildfly.extension.core-management"/&gt;
          &lt;extension module="org.wildfly.extension.discovery"/&gt;
          &lt;extension module="org.wildfly.extension.ee-security"/&gt;
          &lt;extension module="org.wildfly.extension.elytron"/&gt;
          &lt;extension module="org.wildfly.extension.io"/&gt;
          &lt;extension module="org.wildfly.extension.messaging-activemq"/&gt;
          &lt;extension module="org.wildfly.extension.microprofile.config-smallrye"/&gt;
          &lt;extension module="org.wildfly.extension.microprofile.health-smallrye"/&gt;
          &lt;extension module="org.wildfly.extension.microprofile.jwt-smallrye"/&gt;
          &lt;extension module="org.wildfly.extension.microprofile.metrics-smallrye"/&gt;
          &lt;extension module="org.wildfly.extension.microprofile.opentracing-smallrye"/&gt;
          &lt;extension module="org.wildfly.extension.request-controller"/&gt;
          &lt;extension module="org.wildfly.extension.security.manager"/&gt;
          &lt;extension module="org.wildfly.extension.undertow"/&gt;
          &lt;extension module="org.wildfly.iiop-openjdk"/&gt;
      &lt;/extensions&gt;
  
      &lt;subsystem xmlns="urn:jboss:domain:ejb3:6.0"&gt;
          &lt;session-bean&gt;
              &lt;stateless&gt;
                  &lt;bean-instance-pool-ref pool-name="slsb-strict-max-pool"/&gt;
              &lt;/stateless&gt;
              &lt;stateful default-access-timeout="5000" cache-ref="simple" passivation-disabled-cache-ref="simple"/&gt;
              &lt;singleton default-access-timeout="5000"/&gt;
          &lt;/session-bean&gt;
          &lt;mdb&gt;
              &lt;resource-adapter-ref resource-adapter-name="${ejb.resource-adapter-name:activemq-ra.rar}"/&gt;
              &lt;bean-instance-pool-ref pool-name="mdb-strict-max-pool"/&gt;
          &lt;/mdb&gt;
          &lt;pools&gt;
              &lt;bean-instance-pools&gt;
                  &lt;strict-max-pool name="mdb-strict-max-pool" derive-size="from-cpu-count" instance-acquisition-timeout="5" instance-acquisition-timeout-unit="MINUTES"/&gt;
                  &lt;strict-max-pool name="slsb-strict-max-pool" derive-size="from-worker-pools" instance-acquisition-timeout="5" instance-acquisition-timeout-unit="MINUTES"/&gt;
              &lt;/bean-instance-pools&gt;
          &lt;/pools&gt;
          &lt;caches&gt;
              &lt;cache name="simple"/&gt;
              &lt;cache name="distributable" passivation-store-ref="infinispan" aliases="passivating clustered"/&gt;
          &lt;/caches&gt;
          &lt;passivation-stores&gt;
              &lt;passivation-store name="infinispan" cache-container="ejb" max-size="10000"/&gt;
          &lt;/passivation-stores&gt;
          &lt;async thread-pool-name="default"/&gt;
          &lt;timer-service thread-pool-name="default" default-data-store="default-file-store"&gt;
              &lt;data-stores&gt;
                  &lt;file-data-store name="default-file-store" path="timer-service-data" relative-to="jboss.server.data.dir"/&gt;
              &lt;/data-stores&gt;
          &lt;/timer-service&gt;
          &lt;remote connector-ref="http-remoting-connector" thread-pool-name="default"&gt;
              &lt;channel-creation-options&gt;
                  &lt;option name="MAX_OUTBOUND_MESSAGES" value="1234" type="remoting"/&gt;
              &lt;/channel-creation-options&gt;
          &lt;/remote&gt;
          &lt;thread-pools&gt;
              &lt;thread-pool name="default"&gt;
                  &lt;max-threads count="10"/&gt;
                  &lt;keepalive-time time="60" unit="seconds"/&gt;
              &lt;/thread-pool&gt;
          &lt;/thread-pools&gt;
          &lt;iiop enable-by-default="false" use-qualified-name="false"/&gt;
          &lt;default-security-domain value="other"/&gt;
          &lt;default-missing-method-permissions-deny-access value="true"/&gt;
          &lt;statistics enabled="${wildfly.ejb3.statistics-enabled:${wildfly.statistics-enabled:false}}"/&gt;
          &lt;log-system-exceptions value="true"/&gt;
      &lt;/subsystem&gt;
  
      &lt;subsystem xmlns="urn:jboss:domain:messaging-activemq:9.0"&gt;
          &lt;server name="default"&gt;
              &lt;statistics enabled="${wildfly.messaging-activemq.statistics-enabled:${wildfly.statistics-enabled:false}}"/&gt;
              &lt;security-setting name="#"&gt;
                  &lt;role name="guest" send="true" consume="true" create-non-durable-queue="true" delete-non-durable-queue="true"/&gt;
              &lt;/security-setting&gt;
              &lt;address-setting name="#" dead-letter-address="jms.queue.DLQ" expiry-address="jms.queue.ExpiryQueue" max-size-bytes="10485760" page-size-bytes="2097152" message-counter-history-day-limit="10"/&gt;
              &lt;http-connector name="http-connector" socket-binding="http" endpoint="http-acceptor"/&gt;
              &lt;http-connector name="http-connector-throughput" socket-binding="http" endpoint="http-acceptor-throughput"&gt;
                  &lt;param name="batch-delay" value="50"/&gt;
              &lt;/http-connector&gt;
              &lt;in-vm-connector name="in-vm" server-id="0"&gt;
                  &lt;param name="buffer-pooling" value="false"/&gt;
              &lt;/in-vm-connector&gt;
              &lt;http-acceptor name="http-acceptor" http-listener="default"/&gt;
              &lt;http-acceptor name="http-acceptor-throughput" http-listener="default"&gt;
                  &lt;param name="batch-delay" value="50"/&gt;
                  &lt;param name="direct-deliver" value="false"/&gt;
              &lt;/http-acceptor&gt;
              &lt;in-vm-acceptor name="in-vm" server-id="0"&gt;
                  &lt;param name="buffer-pooling" value="false"/&gt;
              &lt;/in-vm-acceptor&gt;
              &lt;jms-queue name="ExpiryQueue" entries="java:/jms/queue/ExpiryQueue"/&gt;
              &lt;jms-queue name="DLQ" entries="java:/jms/queue/DLQ"/&gt;
              &lt;jms-queue name="HsportsQueue" entries="java:/jms/queue/HsportsQueue"/&gt;
              &lt;connection-factory name="InVmConnectionFactory" entries="java:/ConnectionFactory" connectors="in-vm"/&gt;
              &lt;connection-factory name="RemoteConnectionFactory" entries="java:jboss/exported/jms/RemoteConnectionFactory" connectors="http-connector"/&gt;
              &lt;pooled-connection-factory name="activemq-ra" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" connectors="in-vm" transaction="xa"/&gt;
          &lt;/server&gt;
      &lt;/subsystem&gt;
      ...
  &lt;/server&gt;
  </code></pre>
  
  <p>Error stack trace<br></p>
  
  <pre><code>10:30:55,530 ERROR [org.apache.activemq.artemis.ra] (default-threads - 1) AMQ154003: Unable to reconnect org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec(ra=org.wildfly.extension.messaging.activemq.ActiveMQResourceAdapter@798f9ea7 destination=javax.jms.Queue destinationType=null ack=Auto-acknowledge durable=false clientID=null user=null maxSession=15): javax.naming.NameNotFoundException: javax.jms.Queue -- service jboss.naming.context.java."javax.jms.Queue"
      at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:106)
      at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:207)
      at org.jboss.as.naming.InitialContext$DefaultInitialContext.lookup(InitialContext.java:237)
      at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:193)
      at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:189)
      at javax.naming.InitialContext.lookup(InitialContext.java:417)
      at javax.naming.InitialContext.lookup(InitialContext.java:417)
      at org.apache.activemq.artemis.ra.ActiveMQRaUtils.lookup(ActiveMQRaUtils.java:164)
      at org.apache.activemq.artemis.ra.inflow.ActiveMQActivation.setupDestination(ActiveMQActivation.java:578)
      at org.apache.activemq.artemis.ra.inflow.ActiveMQActivation.setup(ActiveMQActivation.java:305)
      at org.apache.activemq.artemis.ra.inflow.ActiveMQActivation.reconnect(ActiveMQActivation.java:693)
      at org.apache.activemq.artemis.ra.inflow.ActiveMQActivation$SetupActivation.run(ActiveMQActivation.java:733)
      at org.wildfly.extension.messaging.activemq.ActiveMQResourceAdapter$WorkWrapper.run(ActiveMQResourceAdapter.java:161)
      at org.jboss.jca.core.workmanager.WorkWrapper.runWork(WorkWrapper.java:445)
      at org.jboss.as.connector.services.workmanager.WildflyWorkWrapper.runWork(WildflyWorkWrapper.java:69)
      at org.jboss.jca.core.workmanager.WorkWrapper.run(WorkWrapper.java:223)
      at org.jboss.threads.SimpleDirectExecutor.execute(SimpleDirectExecutor.java:29)
      at org.jboss.threads.QueueExecutor.runTask(QueueExecutor.java:789)
      at org.jboss.threads.QueueExecutor.access$100(QueueExecutor.java:44)
      at org.jboss.threads.QueueExecutor$Worker.run(QueueExecutor.java:809)
      at java.lang.Thread.run(Thread.java:748)
      at org.jboss.threads.JBossThread.run(JBossThread.java:485)
  </code></pre>
  
  <p>JMS Consumer class:</p>
  
  <pre class="lang-java prettyprint-override"><code>package ejb_javacode;
  
  @MessageDriven(
          activationConfig = {
                  @ActivationConfigProperty(propertyName = "destination", propertyValue = "/jms/queue/HsportsQueue"),
                  @ActivationConfigProperty(propertyName = "destination", propertyValue = "javax.jms.Queue")
          },
          mappedName = "/jms/queue/HsportsQueue")
  
  public class JmsConsumerBean implements javax.jms.MessageListener {
  
      public JmsConsumerBean() {
      }
  
      // defines what the consumer does, when msg is received from jms queue
  
      @Override
      public void onMessage(Message message) {
  
          System.out.println("From JMS Consumer message-driven bean");
          try {
              System.out.println(message.getBody(String.class));
          } catch (JMSException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>JMS producer class:</p>
  
  <pre class="lang-java prettyprint-override"><code>package jaxrs_javacode;
  
  @ApplicationScoped
  public class JmsService {
  
      // injects JMS queue we want to send the message to
      @Resource(mappedName = "java:/jms/queue/HsportsQueue")  // JNDI name
      private Queue hsportsQueue;
  
      @Inject
      @JMSConnectionFactory("java:/ConnectionFactory")
      private JMSContext context;
  
      // code that sends the message to the consumer
      public void send(String message) {
  
          try {
              TextMessage textMessage = context.createTextMessage(message);   
              context.createProducer().send(hsportsQueue, textMessage);       
              System.out.println("Message sent to JMS queue");                
  
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>JAX-RS resource endpoint:</p>
  
  <pre class="lang-java prettyprint-override"><code>package jaxrs_javacode;
  
  
  // resource defines the various http operations required
  @RequestScoped
  @Path("/inventoryitems")                // appends URI app path
  @Produces("application/json")           // receives and provides json
  @Consumes("application/json")
  public class InventoryItemEndpoint {
  
      // adds JPS persistence
      // methods updated to use em &amp; jpa data layer
      @PersistenceContext
      private EntityManager entityManager;
  
      // injects JMS service into REST endpoint
      @Inject
      private JmsService jmsService;
  
      @Transactional
      @POST   // post request; creates new inventory item and gets response back
      public Response create(final InventoryItem inventoryItem) {
  
          entityManager.persist(inventoryItem); // uses em persist method
          jmsService.send(inventoryItem.getName()); // sends inventory item name as JMS text msg
          return Response.created(UriBuilder.fromResource(InventoryItemEndpoint.class)
                  .path(String.valueOf(inventoryItem.getInventoryItemId())).build()).build();
      }
  
      @GET    // get request; gets inventory item by id
      @Path("/{id:[0-9][0-9]*}")  // method level @Path annotation, appends URI with id value
      public Response findById(@PathParam("id") final Long id) {
  
          // now using em find method
          InventoryItem inventoryItem = entityManager.find(InventoryItem.class, id);
  
          if (inventoryItem == null) {
              return Response.status(Response.Status.NOT_FOUND).build();
          }
  
          inventoryItem.setQuantity(ThreadLocalRandom.current().nextLong(1,100));
          return Response.ok(inventoryItem).build();
      }
  
      // new async method; async methods are void
      // onward processing done through resume() method call
  
      @GET
      @Path("/catalog/{catalogItemId}")
      public void asyncFindByCatalogId(@NotNull @PathParam("catalogItemId") Long catalogItemId,
                                       @Suspended AsyncResponse ar) {
  
          // creates new thread
          // sleeps for 5 seconds
          new Thread(() -&gt; {
              try {
                  Thread.sleep(5000);
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
              // tells AsyncResponse to resume, once thread.sleep completes
              // resumes with call to findByCatalogId
              ar.resume(findByCatalogId(catalogItemId));
          }).start();
      }
  
      // used by getQuantity method on remote inventory service
      // takes catalogItemId as param
      // @GET
      // @Path("/catalog/{catalogItemId}") // appends path // updates from @QueryParam to @PathParam
      // Mapping annotations removed; is now called from asyncMethod above
      public InventoryItem findByCatalogId(@NotNull @PathParam("catalogItemId") Long catalogItemId) {
  
          TypedQuery&lt;InventoryItem&gt; query = this.entityManager
                  .createQuery("select i from InventoryItem i where i.catalogItemId = :catalogItemId", InventoryItem.class)
                  .setParameter("catalogItemId", catalogItemId);
  
          InventoryItem item = query.getSingleResult();
          item.setQuantity(ThreadLocalRandom.current().nextLong(1,100));
  
          return item;
      }
  
      @GET    // gets all inventory items
      public List&lt;InventoryItem&gt; listAll(@QueryParam("start") final Integer startPosition,
                                         @QueryParam("max") final Integer maxResult) {
  
          TypedQuery&lt;InventoryItem&gt; query = entityManager.createQuery("select i from InventoryItem i",
                  InventoryItem.class); // now uses em createQuery method
  
          final List&lt;InventoryItem&gt; inventoryItems = query.getResultList();
          return inventoryItems;
      }
  
      @Transactional
      @PUT    // updates existing inventory item
      @Path("/{id:[0-9][0-9]*}")
      public Response update(@PathParam("id") Long id, final InventoryItem inventoryItem) {
          entityManager.merge(inventoryItem); // now uses em.merge method
          return Response.noContent().build();
      }
  
      @Transactional
      @DELETE // deletes an item from inventory
      @Path("/{id:[0-9][0-9]*}")
      public Response deleteById(@PathParam("id") final Long id) {
          entityManager.remove(entityManager.find(InventoryItem.class, id)); // now uses em.remove method
          return Response.noContent().build();
      }
  }
  </code></pre>