検索

第25章 Configuring Duplicate Message Detection

download PDF

When a sender sends a message to another server, there can be a situation where the target server or the connection fails after sending the message, but before sending a response to the sender indicating that the process was successful. In these situations, it is very difficult for the sender to determine whether the message was sent successfully to the intended receiver. If the sender decides to resend the last message, it can result in a duplicate message being sent to the address.

You can configure duplicate message detection in JBoss EAP messaging so that your application does not need to provide the logic to filter duplicate messages.

25.1. Using Duplicate Message Detection for Sending Messages

To enable duplicate message detection for sent messages, you need to set the value of the org.apache.activemq.artemis.api.core.Message.HDR_DUPLICATE_DETECTION_ID property, which resolves to _AMQ_DUPL_ID, to a unique value. When the target server receives the messages, if the _AMQ_DUPL_ID property is set, it will check its memory cache to see if it has already received a message with the value of that header. If it has, then this message will be ignored. See Configuring the Duplicate ID Cache for more information.

The value of the _AMQ_DUPL_ID property can be of type byte[] or SimpleString if you are using the core API. If you are using JMS, it must be a String.

The following example shows how to set the property for core API.

SimpleString myUniqueID = "This is my unique id";   // Can use a UUID for this

ClientMessage message = session.createMessage(true);
message.setStringProperty(HDR_DUPLICATE_DETECTION_ID, myUniqueID);

The following example shows how to set the property for JMS clients.

String myUniqueID = "This is my unique id";   // Can use a UUID for this

Message jmsMessage = session.createMessage();
message.setStringProperty(HDR_DUPLICATE_DETECTION_ID.toString(), myUniqueID);
重要

Duplicate messages are not detected when they are sent within the same transaction using the HDR_DUPLICATE_DETECTION_ID property.

25.2. Configuring the Duplicate ID Cache

The server maintains caches of received values of the _AMQ_DUPL_ID property that is sent to each address. Each address maintains its own address cache.

The cache is fixed in terms of size. The maximum size of cache is configured using the id-cache-size attribute. The default value of this parameter is 20000 elements. If the cache has a maximum size of n elements, then the (n + 1)th ID stored will overwrite the element 0 in the cache. The value is set using the following management CLI command:

/subsystem=messaging-activemq/server=default:write-attribute(name=id-cache-size,value=SIZE)

The caches can also be configured to persist to disk. This can be configured by setting the persist-id-cache attribute using the following management CLI command.

/subsystem=messaging-activemq/server=default:write-attribute(name=persist-id-cache,value=true)

If this value is set to true, then each ID will be persisted to permanent storage as they are received. The default value for this parameter is true.

注記

Set the size of the duplicate ID cache to a large size in order to ensure that resending of messages does not overwrite the previously sent messages stored in the cache.

Red Hat logoGithubRedditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

© 2024 Red Hat, Inc.