# Undelivered Message Queue

If a message could not be delivered for one of the reasons below, the server checks the message’s `JMS_TIBCO_PRESERVE_UNDELIVERED` property. If that property is set to true, the server moves the message to the undelivered message queue, `$sys.undelivered`. Otherwise, the message is deleted by the server.

The server will examine the `JMS_TIBCO_PRESERVE_UNDELIVERED` property of the message if any of the following conditions are met:

- the message has expired
- the message has exceeded the value specified by the `maxRedelivery` property on a queue
- the message had a delivery delay that has expired and was sent to a destination that has reached its `maxmsgs` limit and also has `overflowPolicy`=`rejectIncoming`

`$sys.undelivered` is a system queue that is always present and cannot be deleted. To make use of it, the application that sends or publishes the message must set the boolean `JMS_TIBCO_PRESERVE_UNDELIVERED` property to true before sending or publishing the message.

You can only set the undelivered property on individual messages, there is no way to set the undelivered message queue as an option at the per-topic or per-queue level.

You should create a queue receiver to receive and handle messages as they arrive on the undelivered message queue. If you wish to remove messages from the undelivered message queue without receiving them, you can purge the `$sys.undelivered` queue with the administration tool, using the `purge queue` command described under Command Listing. You can also remove messages using the administrative API included with TIBCO Enterprise Message Service.

Note that `$sys.undelivered` ignores the `global` destination property setting. Messages in the undelivered message queue are not routed to other servers.

Filtering Messages in the Undelivered Message Queue

You can filter messages in the undelivered message queue by destination using a selector. Note that this is an exception to the JMS Specification that is made only for messages in the undelivered message queue. In the undelivered message queue, the `JMSDestination` header field can be used in a selector the same way that a supported header field or any other message property with a string value is used.

The expected value of the `JMSDestination` field depends on the original message destination type and name:

    JMSDestination operator ’Topic|Queue[destination_name]’

For example:

    JMSDestination='Queue[A]'
    JMSDestination='Topic[B7]'
    JMSDestination NOT LIKE 'Queue[A]'
    JMSDestination LIKE 'Queue[A]'
    JMSDestination LIKE 'Q%'
    JMSDestination IS NOT NULL
    JMSDestination IN ('Queue[H]','Queue[J]')
    JMSDestination NOT IN ('Topic[H]','Topic[J]')
    JMSDestination='Queue[A]' OR JMSDestination='Queue[B]'

Copyright © Cloud Software Group, Inc. All rights reserved.