当前位置: 首页 > 知识库问答 >
问题:

错误:AMQ154003:无法使用Wildfly连接到JMS ActiveMQ

公冶智刚
2023-03-14

我正在尝试使用IntelliJ在WildFly 19中创建一个简单的JMS ActiveMQ连接。我遵循了安装指南,但遇到了连接错误。

我将Wildfly作为本地服务器运行,处于独立模式。我已经更新了IntelliJ中的启动脚本环境变量,以指向standalone-full.xml(显然我需要使用standalone-full.xml,以便使用JMS?)

/Users/../IdeaProjects/appservers/wildfly-19.1.0.Final/bin/standalone.sh
JAVA_OPTS environment variable -Djboss.server.default.config=standalone-full.xml

我已经更新了XML文件,以便在代码中添加要连接的JMS队列:

<jms-queue name="HsportsQueue" entries="java:/jms/queue/HsportsQueue"/>

EAR正在部署,JSF正在渲染,但是我得到了一个JMS错误,它只是在堆栈跟踪中无限循环。我已经附加了standalone-full.xml,堆栈跟踪和java代码。

任何帮助都将不胜感激。

standalone-full.xml(由于字符限制而编辑):

<?xml version='1.0' encoding='UTF-8'?>

<server xmlns="urn:jboss:domain:12.0">
    <extensions>
        <extension module="org.jboss.as.clustering.infinispan"/>
        <extension module="org.jboss.as.connector"/>
        <extension module="org.jboss.as.deployment-scanner"/>
        <extension module="org.jboss.as.ee"/>
        <extension module="org.jboss.as.ejb3"/>
        <extension module="org.jboss.as.jaxrs"/>
        <extension module="org.jboss.as.jdr"/>
        <extension module="org.jboss.as.jmx"/>
        <extension module="org.jboss.as.jpa"/>
        <extension module="org.jboss.as.jsf"/>
        <extension module="org.jboss.as.jsr77"/>
        <extension module="org.jboss.as.logging"/>
        <extension module="org.jboss.as.mail"/>
        <extension module="org.jboss.as.naming"/>
        <extension module="org.jboss.as.pojo"/>
        <extension module="org.jboss.as.remoting"/>
        <extension module="org.jboss.as.sar"/>
        <extension module="org.jboss.as.security"/>
        <extension module="org.jboss.as.transactions"/>
        <extension module="org.jboss.as.webservices"/>
        <extension module="org.jboss.as.weld"/>
        <extension module="org.wildfly.extension.batch.jberet"/>
        <extension module="org.wildfly.extension.bean-validation"/>
        <extension module="org.wildfly.extension.clustering.web"/>
        <extension module="org.wildfly.extension.core-management"/>
        <extension module="org.wildfly.extension.discovery"/>
        <extension module="org.wildfly.extension.ee-security"/>
        <extension module="org.wildfly.extension.elytron"/>
        <extension module="org.wildfly.extension.io"/>
        <extension module="org.wildfly.extension.messaging-activemq"/>
        <extension module="org.wildfly.extension.microprofile.config-smallrye"/>
        <extension module="org.wildfly.extension.microprofile.health-smallrye"/>
        <extension module="org.wildfly.extension.microprofile.jwt-smallrye"/>
        <extension module="org.wildfly.extension.microprofile.metrics-smallrye"/>
        <extension module="org.wildfly.extension.microprofile.opentracing-smallrye"/>
        <extension module="org.wildfly.extension.request-controller"/>
        <extension module="org.wildfly.extension.security.manager"/>
        <extension module="org.wildfly.extension.undertow"/>
        <extension module="org.wildfly.iiop-openjdk"/>
    </extensions>

    <subsystem xmlns="urn:jboss:domain:ejb3:6.0">
        <session-bean>
            <stateless>
                <bean-instance-pool-ref pool-name="slsb-strict-max-pool"/>
            </stateless>
            <stateful default-access-timeout="5000" cache-ref="simple" passivation-disabled-cache-ref="simple"/>
            <singleton default-access-timeout="5000"/>
        </session-bean>
        <mdb>
            <resource-adapter-ref resource-adapter-name="${ejb.resource-adapter-name:activemq-ra.rar}"/>
            <bean-instance-pool-ref pool-name="mdb-strict-max-pool"/>
        </mdb>
        <pools>
            <bean-instance-pools>
                <strict-max-pool name="mdb-strict-max-pool" derive-size="from-cpu-count" instance-acquisition-timeout="5" instance-acquisition-timeout-unit="MINUTES"/>
                <strict-max-pool name="slsb-strict-max-pool" derive-size="from-worker-pools" instance-acquisition-timeout="5" instance-acquisition-timeout-unit="MINUTES"/>
            </bean-instance-pools>
        </pools>
        <caches>
            <cache name="simple"/>
            <cache name="distributable" passivation-store-ref="infinispan" aliases="passivating clustered"/>
        </caches>
        <passivation-stores>
            <passivation-store name="infinispan" cache-container="ejb" max-size="10000"/>
        </passivation-stores>
        <async thread-pool-name="default"/>
        <timer-service thread-pool-name="default" default-data-store="default-file-store">
            <data-stores>
                <file-data-store name="default-file-store" path="timer-service-data" relative-to="jboss.server.data.dir"/>
            </data-stores>
        </timer-service>
        <remote connector-ref="http-remoting-connector" thread-pool-name="default">
            <channel-creation-options>
                <option name="MAX_OUTBOUND_MESSAGES" value="1234" type="remoting"/>
            </channel-creation-options>
        </remote>
        <thread-pools>
            <thread-pool name="default">
                <max-threads count="10"/>
                <keepalive-time time="60" unit="seconds"/>
            </thread-pool>
        </thread-pools>
        <iiop enable-by-default="false" use-qualified-name="false"/>
        <default-security-domain value="other"/>
        <default-missing-method-permissions-deny-access value="true"/>
        <statistics enabled="${wildfly.ejb3.statistics-enabled:${wildfly.statistics-enabled:false}}"/>
        <log-system-exceptions value="true"/>
    </subsystem>

    <subsystem xmlns="urn:jboss:domain:messaging-activemq:9.0">
        <server name="default">
            <statistics enabled="${wildfly.messaging-activemq.statistics-enabled:${wildfly.statistics-enabled:false}}"/>
            <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="jms.queue.DLQ" 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>
            <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="DLQ" entries="java:/jms/queue/DLQ"/>
            <jms-queue name="HsportsQueue" entries="java:/jms/queue/HsportsQueue"/>
            <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"/>
        </server>
    </subsystem>
    ...
</server>

错误堆栈跟踪

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)

JMS消费者类:

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();
        }
    }
}

JMS生产者类:

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();
        }
    }
}

JAX-RS资源endpoint:

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 & 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(() -> {
            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<InventoryItem> 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<InventoryItem> listAll(@QueryParam("start") final Integer startPosition,
                                       @QueryParam("max") final Integer maxResult) {

        TypedQuery<InventoryItem> query = entityManager.createQuery("select i from InventoryItem i",
                InventoryItem.class); // now uses em createQuery method

        final List<InventoryItem> 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();
    }
}

共有1个答案

满雨石
2023-03-14

我认为问题在于您的激活配置。您已经定义了目标属性两次:

@MessageDriven(activationConfig = {
                   @ActivationConfigProperty(propertyName = "destination", propertyValue = "/jms/queue/HsportsQueue"),
                   @ActivationConfigProperty(propertyName = "destination", propertyValue = "javax.jms.Queue")
               },
               mappedName = "/jms/queue/HsportsQueue")

因此,JCA资源适配器试图在JNDI中查找“javax.jms.Queue”,因此出现错误:

javax.naming.NameNotFoundException: javax.jms.Queue -- service jboss.naming.context.java."javax.jms.Queue"

值为javax的属性。jms。队列应使用名称destinationType:


@MessageDriven(activationConfig = {
                   @ActivationConfigProperty(propertyName = "destination", propertyValue = "/jms/queue/HsportsQueue"),
                   @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
               },
               mappedName = "/jms/queue/HsportsQueue")
 类似资料:
  • 尝试使用Docker容器将Kibana连接到ES时出错: kibana-product-624|{"type":"log","@time戳":"2018-05-25T14:56:36Z","tags":["警告","elasticsearch","admin"],"pid": 1,"消息":"无法恢复连接:超文本传输协议://elasticsearch: 9200/"}kibana-product

  • Q-我安装了git以获取最新版本的Angular。当我尝试运行时 我连接到github 443错误失败 我甚至试过 这使我无法连接,没有错误消息。 我在公司防火墙后面。转到控制面板时,我看不到我的代理详细信息- 我终于做到了。我将更新我所采取的程序,以便只是想编译我所做的所有步骤,以使它正常工作

  • 我有一个本地的postgresql 10服务器(在9.6上测试了相同的版本,不要认为它与数据库有关,只与pgAdmin4有关,因为pgAdmin3工作得很好) 正如屏幕截图中所示,我试图在新安装时使用用户postgres连接到localhost db,但我一直收到以下消息:

  • 我有一个问题已经一个月了,但我没有找到解决办法。我的笔记本电脑和个人电脑都有这些问题(我以前启动过mongod): 错误:无法连接到服务器 127.0.0.1:27017 src/mongo/shell/mongo.js:91 异常:连接失败 错误:无法连接到服务器127.0.0.1:27017 src/mongo/shell/mongo。js:93异常:连接失败 错误:无法连接到服务器127.0

  • 该应用程序有一个类,使用以下行创建上下文 其中这个IP是火花工作的机器的IP。

  • 我试图用Arquillian和Wildfly(8.1.0.Final和8.2.0.Final tested)容器运行一个简单的JPA测试(persist,read,JSON serialize),但是到目前为止我还不能将test.war部署到嵌入式服务器上。测试使用JBoss7.1.1.final容器运行。 我使用了Arquillian入门指南和Arquillian示例项目(Google:gith