是否需要按顺序在慰安队列中的消息进行确认? [英] Do messages on a solace queue need to be acked in the order they are on the queue?

查看:132
本文介绍了是否需要按顺序在慰安队列中的消息进行确认?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些工作线程,这些线程从不同的提供程序类中提取消息.每个提供程序类都添加/获取内部队列的消息.每个提供者仅迎合一个慰问队列,而慰问者将消息添加到队列的提供者.

I have worker threads that pick up messages from different provider classes. Each provider class adds/takes messages of an internal queue. Each provider caters to only one solace queue and the solace consumer adds messages to the provider of the queue.

多个工作人员可以获取提供者的消息,对其进行处理,然后发送对该消息的确认(以下的message.commit()方法进行确认).

Multiple workers can take messages of a provider, process them and then send an ack for the message (the message.commit() method below does the ack).

场景

  1. Worker1从提要1中提取message1进行处理
  2. Worker2从提要1中提取message2进行处理
  3. Worker2在worker1之前完成,因此将确认2发送回给消息

问题

  1. message2仍会坐在慰问队列上,等待message1被确认,或者尽管message1尚未确认,但message2是否会从队列中弹出?
  2. 收到确认后,solace硬件上会发生什么?消息2是否已完全删除,队列顺序又如何维护?
  1. Would message2 still sit on the solace queue and wait for message1 to be acked or would message2 be popped off the queue despite message1 not acked yet?
  2. What happens on the solace hardware when the ack is received? Is the message2 removed completely, how is the queue order then maintained?

提供程序类

    public abstract class BaseProvider implements IProvider {

     private LinkedBlockingQueue<CoreMessage> internalQueue = new LinkedBlockingQueue<CoreMessage>();

    @Override
    public synchronized List<CoreMessage> getNextQueuedItem() {
        List<CoreMessage> arrMessages = new ArrayList<CoreMessage>();
        if (internalQueue.size() > 0) {
            Logger.debug("Queue has entries");
            CoreMessage msg = null;
            try {
                msg = internalQueue.take();
            } catch (InterruptedException e) {
                Logger.warn("Interruption");
                e.printStackTrace();
            }
            if (msg != null) {
                arrMessages.add(msg);
            }
        }
        return arrMessages;
    }

    protected synchronized void addToQueue(CoreMessage message) {
        try {
            internalQueue.put(message);
        } catch (InterruptedException e) {
            Logger.error("Exception adding message to queue " + message);
        }
    }
}

//有一组通过这些队列读取的工作线程

// There are a set of worker threads that read through these queues

  public class Worker implements Runnable 
    @Override
    public void run() {
    Logger.info("Worker - Running Thread : " + Thread.currentThread().getName());

    while (!stopRequested) {
        boolean processedMessage = false;
        for (IProvider provider : providers) {
            List<CoreMessage> messages = provider.getNextQueuedItem();
            if (messages == null || messages.size() != 0) {
                processedMessage = true;
                for (CoreMessage message : messages) {
                    final Message msg = createEndurMessage(provider, message);
                    processMessage(msg);
                    message.commit();
                }
            }
        }
        if (!(processedMessage || stopRequested)) {
            // this is to stop the thread from spinning when there are no messages
            try {
                Thread.sleep(WAIT_INTERVAL);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
}

推荐答案

这似乎是围绕Solace API的自定义包装. 这使得很难为您的问题提供答案,因为我们根本不知道该包装程序在做什么.

This appear to be your custom wrapper around the Solace API. This make it very difficult to provide answers to your question because we simply don't know what is this wrapper doing.

以下答案做出以下假设.

The answers below make the following assumptions.

  1. 包装器使用的是未交易的JCSMPSession

  1. The wrapper is using a non-transacted JCSMPSession

正在使用客户端确认

  1. message2仍将坐在舒适队列上并等待message1被确认,或者尽管message1仍将message2从队列中弹出 还没确认?
  1. Would message2 still sit on the solace queue and wait for message1 to be acked or would message2 be popped off the queue despite message1 not acked yet?

Message2将被删除.

Message2 will be removed.

  1. 收到确认后,安慰硬件上会发生什么? message2是否已完全删除,队列顺序如何? 维持吗?
  1. What happens on the solace hardware when the ack is received? Is the message2 removed completely, how is the queue order then maintained?

Message2将被确认并从队列中删除.

Message2 will be acknowledged and removed from the queue.

对队列顺序没有影响. 消息顺序指的是将传入消息传递到使用应用程序的顺序. 在这种情况下,message1,message2和message3依次传递到了消费应用程序.

There's no effect on queue order. Order of messages refer to the order in which incoming messages are delivered to the consuming application. In this case, message1, message2 and message3 was delivered to the consuming application in order.

这篇关于是否需要按顺序在慰安队列中的消息进行确认?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆