Multithreading 使用多个MessageListener线程重复JMS消息处理

Multithreading 使用多个MessageListener线程重复JMS消息处理,multithreading,jms,duplicates,message,Multithreading,Jms,Duplicates,Message,我正在创建一个JMS侦听器应用程序,它侦听队列。我正在使用tibcojms 实现并面临一个问题,该问题间歇出现在我的多个侦听器线程中 拾取相同的消息会导致重复处理 以下是我创建连接的方式: . .. 现在让我们假设,创建了5个侦听器线程,它们作为队列上的接收者进行侦听。我看到一种行为 有时,多个侦听器线程/接收器接收到相同的消息,而我最终得到了重复的处理?我怎么能 通过JMS配置来处理它?有可能吗?或者我不得不求助于一些程序化的解决方案?有什么建议吗 非常感谢。谢谢 尝试将Tibjms.EXP

我正在创建一个JMS侦听器应用程序,它侦听队列。我正在使用tibcojms 实现并面临一个问题,该问题间歇出现在我的多个侦听器线程中 拾取相同的消息会导致重复处理

以下是我创建连接的方式: . ..

现在让我们假设,创建了5个侦听器线程,它们作为队列上的接收者进行侦听。我看到一种行为 有时,多个侦听器线程/接收器接收到相同的消息,而我最终得到了重复的处理?我怎么能 通过JMS配置来处理它?有可能吗?或者我不得不求助于一些程序化的解决方案?有什么建议吗
非常感谢。谢谢

尝试将Tibjms.EXPLICIT\u CLIENT\u ACKNOWLEDGE更改为javax.jms.Session.AUTO\u ACKNOWLEDGE


或者确保您的侦听器确认收到消息。

当消息传递到应用程序时,该消息将从队列中隐藏(或其他使用者不可用),直到应用程序确认为止。只有在应用程序确认该消息后,才会从队列中删除该消息。如果消费者未确认就离开,则消息将重新出现在队列中。因此,当一条消息被隐藏时,其他消费者将无法使用该消息

我想说的是:一条信息不应该同时发送给多个消费者。您可能需要重新检查侦听器代码

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());
        ...
        ..
        .