在JBoss EAP 7上部署JMS应用程序时出错

时间:2019-11-13 17:11:37

标签: java jboss jms

部署应用程序时收到以下错误:

/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]"]

我有以下代码将消息发送到amq服务器:

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");

    }
}

这是standalone-full-ha.xml配置文件中的连接工厂的名称。

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

这是.war内的web.xml,这与我在tomcat 9中使用的xml是相同的。如果它不是seme文件,我就不知道。

<?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>

我也有context.xml

<?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>

致谢

1 个答案:

答案 0 :(得分:0)

您的connection-factory配置没有多大意义。这是您正在使用的:

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

您正在使用exported JNDI名称空间,该名称空间将此连接工厂公开给在JVM外部运行的客户端(例如,远程客户端),但是您在in-vm中使用了connectors意味着在JVM外部运行的客户端实际上将无法使用连接工厂,因为in-vm连接器将无法对其使用。

尝试简单地为应用服务器中运行的客户端修改现有的InVmConnectionFactory,例如:

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

然后尝试为您的远程客户端修改现有的RemoteConnectionFactory,例如:

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

完成这些更改后,将重新部署应用程序。