简体   繁体   中英

Using Artemis, JBoss EAP 7.1, and last-value-queue

We use JMS queues over JBoss EAP 7.1 and Spring 4.3.10.

We want to set a specific queue as "last-value-queue", as detailed here .

If we comment out consumer configuration, ie the queue has no consumers attached, it works as last-value-queue, so an incoming message with the same _AMQ_LVQ_NAME value takes place of pre-existing messages and messages don't accumulate.

If we keep consumer configuration and use Thread.sleep() to simulate a long running process in order to not immediately consume messages other than the first, messages with the same _AMQ_LVQ_NAME value aren't discarded, and accumulate into the queue.

Do you have any clues?

Our JBoss configuration in standalone.xml :

<?xml version="1.0" encoding="UTF-8"?>
<subsystem xmlns="urn:jboss:domain:messaging-activemq:2.0">
   <server name="default">
    ...
      <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="jms.queue.NgedeRequestQueue" last-value-queue="true" address-full-policy="BLOCK" />
      <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" redistribution-delay="1000" />
      <jms-queue name="ExpiryQueue" entries="java:/jms/queue/ExpiryQueue" />
      <jms-queue name="DLQ" entries="java:/jms/queue/DLQ" />
      <jms-queue name="NgedeRequestQueue" entries="java:/jms/queue/NgedeRequestQueue" durable="true" />
      ...
      <connection-factory name="InVmConnectionFactory" entries="java:/ConnectionFactory" connectors="in-vm" />
      <connection-factory name="RemoteConnectionFactory" entries="java:jboss/exported/jms/RemoteConnectionFactory" connectors="http-connector" ha="true" block-on-acknowledge="true" reconnect-attempts="-1" />
      <connection-factory name="NgedeConnectionFactory" entries="java:jboss/exported/jms/NgedeConnectionFactory" connectors="http-connector" />
      <pooled-connection-factory name="activemq-ra" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" connectors="in-vm" transaction="xa" />
   </server>
</subsystem>

Our Spring consumer configuration:

<!-- Listener Definition -->
<bean id="messageListenerRequest" class="it.eng.ngede.jms.consumer.NationalApplicationRequestConsumer"/>

<bean id="NgedeRequestQueue" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:/jms/queue/NgedeRequestQueue" />
    <property name="jndiTemplate" ref="jnditemplate" />
</bean>

<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:/ConnectionFactory" />
    <property name="jndiTemplate" ref="jnditemplate" />
</bean>

<bean id="jnditemplate" class="org.springframework.jndi.JndiTemplate">
    <property name="environment">
        <props>
            <prop key="java.naming.factory.initial">org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory</prop>
        </props>
    </property>
</bean>

<!-- JmsContainer Definition -->
<bean id="jmsContainerRequest" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="connectionFactory" ref="connectionFactory" />
    <property name="destination" ref="NgedeRequestQueue" />
    <property name="messageListener" ref="messageListenerRequest" />
    <property name="concurrentConsumers" value="1" />
</bean>

You're seeing the expected behavior. If a consumer is connected then by default messages sent to the broker will be dispatched to the consumer immediately due to message buffering. Messages which are dispatched to the consumer are considered "in delivery" (ie they've been sent to the client but they haven't yet been acknowledged). Messages which are "in delivery" cannot be replaced by the "last value" since they are essentially out of the broker's control at that point.

If you want different behavior then I recommend you set consumerWindowSize=0 on your connection URL so that consumers don't buffer messages. Of course, this may reduce message throughput, but that may not even matter for your use-case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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