Shoaib Mohammed
Shoaib Mohammed

Reputation: 23

Set individualDeadLetterStrategy, sharedDeadLetterStrategy and expiry for messages in dead letter queue

I want to set the following things

  1. individualDeadLetterStrategy to set DL queue prefix per queue
  2. sharedDeadLetterStrategy to disable processing of expired messages in DL queue
  3. Set expiry on messages in DL queue

On Following dl-queue-handling, I came up with the following snippets which don't work

  <destinationPolicy>
        <policyMap>
          <policyEntries>

            <policyEntry queue=">">
              <deadLetterStrategy>
                <individualDeadLetterStrategy queuePrefix="DLQ." useQueueForQueueMessages="true"/>
              </deadLetterStrategy>
            </policyEntry>

            <policyEntry queue=">">
              <deadLetterStrategy>
                <sharedDeadLetterStrategy processExpired="false" />
              </deadLetterStrategy>
            </policyEntry>

            <policyEntry queue="CommandQueue">
              <deadLetterStrategy>
                <expiration="600000" />
              </deadLetterStrategy>
            </policyEntry>

          </policyEntries>
        </policyMap>
    </destinationPolicy>

error: XML document from class path resource [activemq.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 74; columnNumber: 32; Element type "expiration" must be followed by either attribute specifications, ">" or "/>"

where lineNumber: 74 corresponds to line <expiration="600000" /> in the snippet above.

Alternatively, I assumed that all policies for a given queue name should be under the same policyEntry so I tried the following snippet too:

  <destinationPolicy>
        <policyMap>
          <policyEntries>

            <policyEntry queue=">">
              <deadLetterStrategy>
                <individualDeadLetterStrategy queuePrefix="DLQ." useQueueForQueueMessages="true"/>
                <sharedDeadLetterStrategy processExpired="false" />
              </deadLetterStrategy>
            </policyEntry>

            <policyEntry queue="CommandQueue">
              <deadLetterStrategy>
                <expiration="600000" />
              </deadLetterStrategy>
            </policyEntry>

          </policyEntries>
        </policyMap>
    </destinationPolicy>

error: reason: Line 63 in XML document from class path resource [activemq.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 63; columnNumber: 72; cvc-complex-type.2.4.d: Invalid content was found starting with element 'sharedDeadLetterStrategy'. No child element is expected at this point.

where line 63 corresponds to: sharedDeadLetterStrategy processExpired="false"

Upvotes: 2

Views: 1682

Answers (1)

Justin Bertram
Justin Bertram

Reputation: 34998

As noted in the documentation you cited, expiration is an attribute. It can't exist by itself in a tag. That's invalid XML. You should set this on your individualDeadLetterStrategy.

Also, you can set processExpired="false" on the individualDeadLetterStrategy as well.

Try this instead:

<destinationPolicy>
  <policyMap>
    <policyEntries>

      <policyEntry queue=">">
        <deadLetterStrategy>
          <individualDeadLetterStrategy queuePrefix="DLQ." useQueueForQueueMessages="true" processExpired="false" expiration="600000"/>
        </deadLetterStrategy>
      </policyEntry>

    </policyEntries>
  </policyMap>
</destinationPolicy>

Upvotes: 3

Related Questions