我正在創建一個在隊列上偵聽的JMS偵聽器應用程序。我正在使用TIBCO JMS 實現,並面臨一個問題,即我的多個偵聽器線程 間歇性地選取相同的消息並導致重複處理。使用多個MessageListener線程處理重複的JMS消息
以下是我如何創建連接: 。 .. ...
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.PROVIDER_URL, url);
env.put(Context.INITIAL_CONTEXT_FACTORY, contextFactoryClass);
env.put(Context.SECURITY_PRINCIPAL, userName);
String decryptedPass = null;
//Decryption logic
try {
// Look up queue connection factory from naming context.
if (log.isEnabledFor(Level.DEBUG)) {
log.debug("Attempting to lookup queue connection factory at '" +
this.url + "' as user '" + userName + "'.");
}
Context ctx = new InitialContext(env);
QueueConnectionFactory factory =
(QueueConnectionFactory) ctx.lookup(connectionFactoryName);
// Create JMS connection using the factory we just looked up.
if (log.isEnabledFor(Level.DEBUG)) {
log.debug("Creating queue connection as user '" + userName + "'.");
}
connection = factory.createQueueConnection(userName, decryptedPass);
...
..
.
然後我在這裏創建與上述
//This is called in a loop.
// Create a JMS session that is non-transacted, but in client
// acknowledge mode. This will allow us to control when
// messages are acknowledged.
QueueSession session =
getQueueConnection().createQueueSession(
false, Tibjms.EXPLICIT_CLIENT_ACKNOWLEDGE);
// Create a receiver for the queue we are interested in. Then
// set the message listener defined on the outer class. Messages
// will be delivered on a dispatcher thread created by the
// JMS provider.
Queue queue = session.createQueue(getQueueName());
session.createReceiver(queue).setMessageListener(getListener());
...
..
.
現在創建相同的連接監聽線程在這裏,讓我們假設,5個偵聽器線程的創建和他們的聽隊列中的接收器。我看到一個行爲,即有時多於一個監聽器線程/接收器收到相同的消息,並且我最終得到重複處理?我如何 通過JMS配置來處理它?它甚至有可能嗎?或者我將不得不求助於一些程序化解決方案?任何建議 將不勝感激。謝謝。