Da parte nostra scegliamo di aggiungere il tempo di scadenza a destinazioni specifiche utilizzando un percorso cammello distribuito nel servizio ActiveMQ stesso.
L'unica cosa da fare è creare un file XML come il seguente con il nome e.g. setJMSExpiration.xml
:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<camelContext id="camel-set-expiration" xmlns="http://camel.apache.org/schema/spring">
<!-- Copy route for each destination to expire -->
<route id="setJMSExpiration.my.queue.dlq">
<from uri="broker:queue:MY.QUEUE.DLQ"/>
<setHeader headerName="JMSExpiration">
<!-- Message will expire after 1 day -->
<spel>#{T(java.lang.System).currentTimeMillis() + 86400000}</spel>
</setHeader>
<to uri="broker:queue:MY.QUEUE.DLQ"/>
</route>
<route id="setJMSExpiration.another.queue">
<from uri="broker:queue:ANOTHER.QUEUE"/>
<setHeader headerName="JMSExpiration">
<!-- Message will expire after 5 days -->
<spel>#{T(java.lang.System).currentTimeMillis() + 432000000}</spel>
</setHeader>
<to uri="broker:queue:ANOTHER.QUEUE"/>
</route>
</camelContext>
</beans>
e importarlo nel vostro activemq.xml
configurazione con:
<!-- Add default Expiration (file in the same directory) -->
<import resource="setJMSExpiration.xml"/>
In alternativa si può anche fornire specifica per destination policies se non si desidera che i messaggi scaduti per raggiungere la coda di ActiveMQ.DLQ.
<policyEntry queue="MY.QUEUE.DLQ">
<deadLetterStrategy>
<sharedDeadLetterStrategy processExpired="false" />
</deadLetterStrategy>
</policyEntry>
<policyEntry queue="ANOTHER.QUEUE">
<deadLetterStrategy>
<sharedDeadLetterStrategy processExpired="false" />
</deadLetterStrategy>
</policyEntry>
L'unica limitazione di questo modo è che non è possibile utilizzare facilmente i caratteri jolly come è codificato qui (è possibile, ma avrete bisogno di alcuni adattamenti utilizzando intestazione destinazione JMS nel percorso cammello).
Cerchiamo di consentire ai produttori di definire timeToLive (e forzarli il più possibile) ma non è sempre possibile costringerli a cambiare il loro codice, questo per minimizzare il numero di tali percorsi.
fonte
2017-07-21 12:24:01
Sembra promettente, lo farò un tentativo –