首页 > 解决方案 > 在 JBoss EAP 7 上部署 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>

问候

标签: javajbossjms

解决方案


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

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

您正在使用exportedJNDI 命名空间,该名称空间将此连接工厂公开给在 JVM 外部运行的客户端(即远程客户端),但您使用的是in-vmfor,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"/>

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


推荐阅读