Search code examples
javajbossjms

Error deploying JMS appplication on JBoss EAP 7


I receive the following error when the application is deployed:

/opt/eap/bin # cat ../standalone/deployments/SitioWebFinal.war.failed { "WFLYCTL0412: Required services that are not installed:" => ["jboss.naming.context.java.jboss.java:env.jms.fabrica"], "WFLYCTL0180: Services with missing/unavailable dependencies" => ["jboss.naming.context.java.module.SitioWebFinal.SitioWebFinal.env.jms.fabrica is missing [jboss.naming.context.java.jboss.java:env.jms.fabrica]"]

I have the following code where send the messages to a amq server:

package amqlib;

import javax.naming.*;
import javax.jms.*;

public class Producctor {
    public void enviaMensajeCola(String mundo) throws JMSException {
        try { 
            InitialContext initCtx = new InitialContext();

            QueueConnectionFactory f = (QueueConnectionFactory) initCtx.lookup("java:jboss/exported/jms/fabrica");
            QueueConnection con = f.createQueueConnection();
            con.start();

            QueueSession ses = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

            InitialContext initCtx2 = new InitialContext();
            Queue t = (Queue) initCtx2.lookup("/queue");

            QueueSender sender = ses.createSender(t);

            TextMessage msg = ses.createTextMessage();

            InputStreamReader(System.in));

            String s = mundo;
            msg.setText(s);
            // 7) send message

            sender.send(msg);

            System.out.println("Message successfully sent.");

            // 8) connection close

            con.close();

        }

        catch (Exception e) {
            System.out.println("Este es el error " + e);
        }
    }

    public static void main(String[] args) throws JMSException {
        Producctor p = new Producctor();
        p.enviaMensajeCola("Hola Mundo");

    }
}

And this is the of the conection factory in standalone-full-ha.xml configuraton file.

<connection-factory name="fabrica" entries="java:jboss/exported/jms/fabrica" connectors="in-vm"/>

This is the web.xml inside the .war this is the same xml I use in tomcat 9. I dont if it can be the seme file.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
  <display-name>SitioWebFinal</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

      <distributable/>

  <resource-ref>
    <description>ConnectionFactory</description>
    <res-ref-name>jms/fabrica</res-ref-name>
    <res-type>org.apache.activemq.ActiveMQConnectionFactory</res-type>
    <res-auth>Container</res-auth>
    <lookup-name>java:env/jms/fabrica</lookup-name>
  </resource-ref>
</web-app>

I have the context.xml as well

<?xml version="1.0" encoding="UTF-8"?>
<Context name="/SitioWebFinal" antiJARLocking="true">
        <Resource
            name="jms/fabrica"
            auth="Container"
            type="org.apache.activemq.ActiveMQConnectionFactory"
            description="JMS Connection Factory"
            factory="org.apache.activemq.jndi.JNDIReferenceFactory"
            brokerURL="tcp://amq-cicd-int-amq-tcp.svc.cluster.local:61616"
            brokerName="ActiveMQBroker"
            useEmbeddedBroker="false"/>

        <Resource name="jms/topic"
            auth="Container"
            type="org.apache.activemq.command.ActiveMQTopic"
            factory="org.apache.activemq.jndi.JNDIReferenceFactory"
            physicalName="APP.JMS.TOPIC"/>
        <Resource name="jms/queue"
            auth="Container"
            type="org.apache.activemq.command.ActiveMQQueue"
            factory="org.apache.activemq.jndi.JNDIReferenceFactory"
            physicalName="APP.JMS.QUEUE"/>  
</Context>

Regards


Solution

  • Your connection-factory configuration doesn't make a lot of sense. Here's what you're using:

    <connection-factory name="fabrica" entries="java:jboss/exported/jms/fabrica" connectors="in-vm"/>
    

    You're using the exported JNDI namespace which exposes this connection factory to clients running outside the JVM (i.e. remote clients), but you're using in-vm for the connectors which means clients running outside the JVM won't actually be able to use the connection factory since the in-vm connector won't work for them.

    Try simply modifying the existing InVmConnectionFactory for your clients running in the application server, e.g.:

    <connection-factory name="InVmConnectionFactory" entries="java:/ConnectionFactory java:/jms/fabrica" connectors="in-vm"/>
    

    Then try modifying the existing RemoteConnectionFactory for your remote clients, e.g.:

    <connection-factory name="RemoteConnectionFactory" entries="java:jboss/exported/jms/RemoteConnectionFactory java:jboss/exported/jms/fabrica" connectors="http-connector"/>
    

    Once you've made those changes redeploy your application.