简体   繁体   English

ActiveMQ Artemis 2.10.1 忽略 TomEE 中的重试设置

[英]ActiveMQ Artemis 2.10.1 ignoring retry settings in TomEE

I downloaded latest ActiveMQ Artemis 2.10.1 (Windows 10, JDK 8) and can't get the address-settings to take affect.我下载了最新的 ActiveMQ Artemis 2.10.1(Windows 10,JDK 8)并且无法使address-settings生效。 Reading the documentation (not much) on line I edited the broker.xml by adding:在线阅读文档(不多)我通过添加以下内容编辑了broker.xml

<address-settings>
    <address-setting match="BETATESTQ">
        <dead-letter-address>BETATESTQ_DLQ</dead-letter-address>
        <expiry-address>BETATESTQ_EXPIRY</expiry-address>
        <redelivery-delay>30000</redelivery-delay>
        <redelivery-delay-multiplier>1.5</redelivery-delay-multiplier>         
        <redelivery-collision-avoidance-factor>0.15</redelivery-collision-avoidance-factor>
        <max-redelivery-delay>100000</max-redelivery-delay>
        <max-delivery-attempts>999</max-delivery-attempts>      
    </address-setting>   
</address-settings>

<addresses>
    <address name="BETATESTQ_DLQ">
        <anycast>
            <queue name="BETATESTQ_DLQ" />
        </anycast>
    </address>   
    <address name="BETATESTQ_EXPIRY">
        <anycast>
            <queue name="BETATESTQ_EXPIRY" />
        </anycast>
    </address>   
    <address name="BETATESTQ">
        <anycast>
            <queue name="BETATESTQ" />
        </anycast>
    </address>  
</addresses>

Everything else is default broker.xml when create a broker.创建broker.xml时,其他所有内容都是默认的broker.xml

It seems to always use default values for redelivery-delay , max-redelivery-delay , max-delivery-attempts .它似乎总是使用默认值redelivery-delaymax-redelivery-delaymax-delivery-attempts It does read the dead letter and expiry values correctly.它确实正确读取死信和到期值。 I can see the message getting retried in TomEE logs and shows up in Artemis console and moves to dead letter queue when done.我可以看到消息在 TomEE 日志中重试并显示在 Artemis 控制台中,并在完成后移动到死信队列。

I am not passing in and delivery or retry data when put it on the queue initially (using bare minimal Java J2EE code).最初将数据放入队列时,我没有传入和传递或重试数据(使用最少的 Java J2EE 代码)。

How can I get it to not ignore redelivery-delay , max-redelivery-delay , max-delivery-attempts ?我怎样才能让它不忽略redelivery-delaymax-redelivery-delaymax-delivery-attempts

I connected to the queue with Apache TomEE (not using built-in ActiveMQ 5.x in TomEE but pointing it to ActiveMQ Artemis)我使用 Apache TomEE 连接到队列(不在 TomEE 中使用内置的 ActiveMQ 5.x,而是将其指向 ActiveMQ Artemis)

JMS listener: JMS 侦听器:

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.*;

@MessageDriven(name = "BETATESTQ", activationConfig = {
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName = "destination", propertyValue = "BETATESTQ"),
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") 
})
public class BetaTestQueueListener implements MessageListener, java.io.Serializable {
    private static final long serialVersionUID = 1L;     

    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public void onMessage(Message rcvMessage) {
        System.out.println("omMessage throw runtime exception");          
        throw new RuntimeException("trigger retry");
    }
}

12/20/19 - Working values I found for TomEE 8.0.0: 2019 年 12 月 20 日 - 我为 TomEE 8.0.0 找到的工作值:

tomee.xml: tomee.xml:

<?xml version="1.0" encoding="UTF-8"?>
<tomee>

    <Resource id="artemis" class-name="org.apache.activemq.artemis.ra.ActiveMQResourceAdapter">
        ConnectorClassName=org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory
        ConnectionParameters=host=127.0.0.1;port=61617;needClientAuth=false;sslEnabled=true;keyStorePath=../ssl/server_jks_keystore.jks;keyStorePassword=mypassword;trustStorePath=../ssl/client_jks_truststore.jks;trustStorePassword=mypassword;trustAll=true;verifyHost=false;wantClientAuth=false;needClientAuth=false;keyStoreProvider=JKS;trustSToreProvider=JKS
        UserName=admin
        Password=admin     
        JndiParams=java.naming.factory.initial=org.apache.openejb.core.OpenEJBInitialContextFactory
    </Resource>

    <Resource id="MyJmsConnectionFactory"
              class-name="org.apache.activemq.artemis.jms.client.ActiveMQXAConnectionFactory"
              constructor="uri,username,password"
              type="javax.jms.ConnectionFactory">
        uri=tcp://localhost:61617?needClientAuth=false;sslEnabled=true;keyStorePath=C:/apache-tomee-plus-8.0.0/ssl/server_jks_keystore.jks;keyStorePassword=mypassword;trustStorePath=C:/apache-tomee-plus-8.0.0/ssl/client_jks_truststore.jks;trustStorePassword=mypassword;trustAll=true;verifyHost=false;wantClientAuth=false;needClientAuth=false;keyStoreProvider=JKS;trustSToreProvider=JKS
        username=admin
        password=admin
        TransactionSupport=xa
        PoolMaxSize=20
        PoolMinSize=0   
    </Resource>     

    <Resource id="BETATESTQ_DLQ"
              class-name="org.apache.activemq.artemis.api.jms.ActiveMQJMSClient"
              constructor="name"
              factory-name="createQueue"
              type="javax.jms.Queue">
        name=BETATESTQ_DLQ
    </Resource> 
    <Resource id="BETATESTQ"
              class-name="org.apache.activemq.artemis.api.jms.ActiveMQJMSClient"
              constructor="name"
              factory-name="createQueue"
              type="javax.jms.Queue">
        name=BETATESTQ
    </Resource> 
    <Container id="mdb" type="MESSAGE">
        InstanceLimit = -1
        ResourceAdapter = artemis
        ActivationSpecClass = org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec
    </Container>
</tomee>

Java EE class to send JMS message:发送 JMS 消息的 Java EE 类:

import java.util.*;
import javax.jms.*;
import org.slf4j.*;

public final class JmsPublisherInstance2 implements java.io.Serializable { 
   private static final long serialVersionUID = 1L;
   private static final Logger LOG = LoggerFactory.getLogger(JmsPublisherInstance2.class);

   public void send( String msg,
                     ConnectionFactory connectionFactory,
                     Queue queue ) throws Exception { 
      Session session = null;
      MessageProducer producer = null;
      TextMessage message = null;
      Connection connection = null;
      try {     
            connection = connectionFactory.createConnection();       
            connection.start();
            session = connection.createSession(true, Session.SESSION_TRANSACTED);
            producer = session.createProducer(queue);
            message = session.createTextMessage(msg);
            producer.send(message);
            session.commit();
      }  catch (Exception e) {
         session.rollback();
         LOG.error(e.getMessage(), e);
         throw e;
      }  finally {
          if (session!=null ) {
              session.close();
          }
          if (connection!=null ) {
              connection.close();
          }
      }
   }
}

Java EE listener: Java EE 侦听器:

import java.io.*;
import javax.annotation.*;
import javax.ejb.*;
import javax.jms.*;

@MessageDriven ( name = "BetaTESTQMDB" , activationConfig = {
    @ActivationConfigProperty(propertyName="destinationType", propertyValue = "javax.jms.Queue") ,
    @ActivationConfigProperty(propertyName="destination", propertyValue = "BetaTESTQ"),
    @ActivationConfigProperty(propertyName="maxSession", propertyValue = "5"),
    @ActivationConfigProperty(propertyName="acknowledgeMode", propertyValue = "Auto-acknowledge")
})

public class BetaTestQueueListener implements MessageListener, java.io.Serializable { 
      private static final long serialVersionUID = 1L;

      @Resource(name="MyJmsConnectionFactory")
      private ConnectionFactory connectionFactory;

      @Resource
      private MessageDrivenContext mdbContext;

      @Resource(name = "BETATESTQ") 
      private javax.jms.Queue betaTestQ;      

      @TransactionAttribute(TransactionAttributeType.REQUIRED)
      public void onMessage(Message rcvMessage) {
            try {
                jmsInstance.send("test message", connectionFactory, betaTestQ);
            } catch (Throwable t) {
                t.printStackTrace();
                mdbContext.setRollbackOnly();
            }
      }
}

It seems likely that you're using the OpenWire JMS client.您可能正在使用 OpenWire JMS 客户端。 This complicates matters because, as I understand it, the OpenWire JMS client implements redelivery in the client itself and those redelivery semantics are configured on the client side not the broker side.这使事情变得复杂,因为据我所知,OpenWire JMS 客户端在客户端本身实现重新传递,并且这些重新传递语义是在客户端而不是代理端配置的。 The broker doesn't have a chance to apply any kind of redelivery policy because the OpenWire client handles everything and doesn't inform the broker of the delivery failures.代理没有机会应用任何类型的重新交付策略,因为 OpenWire 客户端处理所有事情,并且不会将交付失败通知代理。 This documentation may help you configure redelivery for your OpenWire client.本文档可帮助您为 OpenWire 客户端配置重新传送。

That said, I recommend following this tutorial .也就是说,我建议遵循本教程 It demonstrates how to integrate TomEE and ActiveMQ Artemis without building/deploying the JCA RA.它演示了如何在不构建/部署 JCA RA 的情况下集成 TomEE 和 ActiveMQ Artemis。 This will allow you to use the Core JMS client rather than the OpenWire JMS client.这将允许您使用 Core JMS 客户端而不是 OpenWire JMS 客户端。

If you want to go the RA route you can build the ActiveMQ Artemis JCA RA by running mvn verify from the examples/features/sub-modules/artemis-ra-rar/ directory.如果你想走 RA 路线,你可以通过从examples/features/sub-modules/artemis-ra-rar/目录运行mvn verify来构建 ActiveMQ Artemis JCA RA。 The RA will be in the target directory named artemis-rar-<version>.rar . RA 将位于名为artemis-rar-<version>.rartarget目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM