--- url: "http://www.enterpriseintegrationpatterns.com/MessageExpiration.html" titulek: "Message Expiration - Enterprise Integration Patterns" h1: "" popis: "How can a sender indicate when a message should be considered stale and thus shouldn’t be processed?" jazyk: "en" kanonicka: "" drobecky: [] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-15 15:34:08" znaku: 7322 slov: 715 kodovani: "utf-8" sha256: "9522e7c0d36b461b363796225d7fc9cef2609467e252c9ac17edc1d2354a98ee" --- | | Message Expiration[Messaging Patterns](index.html) » [Message Construction](MessageConstructionIntro.html) | [Contents](toc.html)[⇐ Prev](MessageSequence.html)[Next ⇒](FormatIndicator.html) | | --- | --- | --- | My application is using [*Messaging*](Messaging.html). If a [*Message*](Message.html)’s data or request is not received by a certain time, it is useless and should be ignored. How can a sender indicate when a message should be considered stale and thus shouldn’t be processed? Set the *Message Expiration* to specify a time limit how long the message is viable. Once the time for which a message is viable passes, and the message still has not been consumed, then the message will expire. The messaging system’s consumers will ignore an expired message; they treat the message as if it where never sent in the first place. Most messaging system implementations reroute expired messages to the [*Dead Letter Channel*](DeadLetterChannel.html), while others simply discard expired messages; this may be configurable. A *Message Expiration* is like the expiration date on a carton of milk—after that date, you’re not supposed to drink the milk. If the expiration date passes while the milk is on the grocery store shelf, the grocer is supposed to pull the milk off the shelf and not sell it. If you end up with a carton on milk that expires, you’re supposed to pour it out. Likewise, when a message expires, the messaging system should no longer deliver it. If a receiver nevertheless receives a message but cannot process it before the expiration, the receiver should throw away the message. ... Read the entire pattern in the book [Enterprise Integration Patterns](/books1.html) ## Example: Azure Service Bus[NEW](/ramblings/eip1_examples_updated.html) [Azure Service Bus](https://azure.microsoft.com/en-au/products/service-bus/) implements *Message Expiration* [both at the entity and the message level](https://learn.microsoft.com/en-us/azure/service-bus-messaging/message-expiration). Messages expire at the earliest of the *Message Expiration* set in the message or the entity, e.g. the queue or topic. Expired messages are sent to a [*Dead Letter Channel*](DeadLetterChannel.html) if one is specified. Messages that are locked for delivery (see [*Transactional Client*](TransactionalClient.html)) won't expire as long as they are locked. ## Example: Amazon EventBridge[NEW](/ramblings/eip1_examples_updated.html) [Amazon EventBridge](https://aws.amazon.com/eventbridge/) uses a built-in *Message Expiration* that can [trigger on elapsed time or the number of failed delivery attempts](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-rule-dlq.html), whichever comes first. The default values are 24 hours and 185 retries, but can be customized in the console or via the command-line by using the RetryPolicy setting of the EventBridge target: ``` "RetryPolicy": { "MaximumRetryAttempts": integer, "MaximumEventAgeInSeconds": integer } ``` Asynchronous targets like SQS, SNS, or CloudWatch logs rarely trigger the *Message Expiration* because they can consume messages at the same rate as they arrive on the event bus. However, *Message Expiration* is an important setting when using rate-limited targets like [API Destinations](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-api-destinations.html) (HTTP calls). ## Example: Google Cloud PubSub[NEW](/ramblings/eip1_examples_updated.html) [*Publish-Subscribe Channel*](PublishSubscribeChannel.html)s generally have longer *Message Expiration* as a new subscriber might be interested in messages that have already been consumed by existing subscribers. [Google Cloud PubSub](https://cloud.google.com/pubsub/) includes a message_retention_duration setting for both topics and subscriptions (see [*Publish-Subscribe Channel*](PublishSubscribeChannel.html) for an explanation of topics and subscriptions) that allows subscriptions to [replay messages that predate the subscription](https://cloud.google.com/pubsub/docs/replay-overview), allowing subscriptions to act as [*Durable Subscriber*](DurableSubscription.html)s. The maximum setting is a generous 31 days, but you pay for storage. **Related patterns:** [*Dead Letter Channel*](DeadLetterChannel.html), [*Durable Subscriber*](DurableSubscription.html), [*Guaranteed Delivery*](GuaranteedMessaging.html), [*Invalid Message Channel*](InvalidMessageChannel.html), [*Message*](Message.html), [*Messaging*](Messaging.html), [*Publish-Subscribe Channel*](PublishSubscribeChannel.html), [*Request-Reply*](RequestReply.html), [*Transactional Client*](TransactionalClient.html) --- ## Integration Pattern Language [Message Construct.](MessageConstructionIntro.html) [Message](Message.html) [Command Message](CommandMessage.html) [Document Message](DocumentMessage.html) [Event Message](EventMessage.html) [Request-Reply](RequestReply.html) [Return Address](ReturnAddress.html) [Correlation Identifier](CorrelationIdentifier.html) [Message Sequence](MessageSequence.html) [Message Expiration](MessageExpiration.html) [Format Indicator](FormatIndicator.html) [Message Routing](MessageRoutingIntro.html) [Pipes-and-Filters](PipesAndFilters.html) [Message Router](MessageRouter.html) [Content-based Router](ContentBasedRouter.html) [Message Filter](Filter.html) [Dynamic Router](DynamicRouter.html) [Recipient List](RecipientList.html) [Splitter](Sequencer.html) [Aggregator](Aggregator.html) [Resequencer](Resequencer.html) [Composed Msg. Processor](DistributionAggregate.html) [Scatter-Gather](BroadcastAggregate.html) [Routing Slip](RoutingTable.html) [Process Manager](ProcessManager.html) [Message Broker](MessageBroker.html) [Message Transformation](MessageTransformationIntro.html) [Message Translator](MessageTranslator.html) [Envelope Wrapper](EnvelopeWrapper.html) [Content Enricher](DataEnricher.html) [Content Filter](ContentFilter.html) [Claim Check](StoreInLibrary.html) [Normalizer](Normalizer.html) [Canonical Data Model](CanonicalDataModel.html) [Messaging Endpoints](MessagingEndpointsIntro.html) [Message Endpoint](MessageEndpoint.html) [Messaging Gateway](MessagingGateway.html) [Messaging Mapper](MessagingMapper.html) [Transactional Client](TransactionalClient.html) [Polling Consumer](PollingConsumer.html) [Event-driven Consumer](EventDrivenConsumer.html) [Competing Consumers](CompetingConsumers.html) [Message Dispatcher](MessageDispatcher.html) [Selective Consumer](MessageSelector.html) [Durable Subscriber](DurableSubscription.html) [Idempotent Receiver](IdempotentReceiver.html) [Service Activator](MessagingAdapter.html) [Messaging Channels](MessagingChannelsIntro.html) [Message Channel](MessageChannel.html) [Point-to-Point Channel](PointToPointChannel.html) [Publish-Subscr. Channel](PublishSubscribeChannel.html) [Datatype Channel](DatatypeChannel.html) [Invalid Message Channel](InvalidMessageChannel.html) [Dead Letter Channel](DeadLetterChannel.html) [Guaranteed Delivery](GuaranteedMessaging.html) [Channel Adapter](ChannelAdapter.html) [Messaging Bridge](MessagingBridge.html) [Message Bus](MessageBus.html) [Systems Mgmt.](SystemManagementIntro.html) [Control Bus](ControlBus.html) [Detour](Detour.html) [Wire Tap](WireTap.html) [Message History](MessageHistory.html) [Message Store](MessageStore.html) [Smart Proxy](SmartProxy.html) [Test Message](TestMessage.html) [Channel Purger](ChannelPurger.html)