Spring integration 如果容量已满且有新消息出现,队列通道顺序如何工作?
我有一个容量无限的队列。我可以限制容量,但是,我的问题是消息的处理顺序。若队列中有100000条消息,则新消息仍将出现。 输出通道是否会收到新消息,或者将以FIFO顺序从队列中拾取新消息Spring integration 如果容量已满且有新消息出现,队列通道顺序如何工作?,spring-integration,Spring Integration,我有一个容量无限的队列。我可以限制容量,但是,我的问题是消息的处理顺序。若队列中有100000条消息,则新消息仍将出现。 输出通道是否会收到新消息,或者将以FIFO顺序从队列中拾取新消息 <channel id="DeliveryProcessChannel"> <queue/> </channel> <aggregator input-channel="DeliveryProcessChannel" output- channel="Ema
<channel id="DeliveryProcessChannel">
<queue/>
</channel>
<aggregator input-channel="DeliveryProcessChannel" output-
channel="EmailDispatchChannel"
discard-channel="EmailDispatchChannel"
expire-groups-upon-completion="true"
send-partial-result-on-expiry="true"
group-timeout="1000"
correlation-strategy-expression="T(Thread).currentThread().id"
release-strategy-expression="size() == 1000">
<poller max-messages-per-poll="1000" fixed-rate="1000"/>
</aggregator>
队列通道完全基于FIFO算法。
确切地说:内存中的默认值完全基于LinkedBlockingQueue
所有持久化实现都基于存储FIFO语义。例如,JDBC one有以下查询:
@Override
public String getPollFromGroupQuery() {
return "SELECT %PREFIX%CHANNEL_MESSAGE.MESSAGE_ID, %PREFIX%CHANNEL_MESSAGE.MESSAGE_BYTES from %PREFIX%CHANNEL_MESSAGE " +
"where %PREFIX%CHANNEL_MESSAGE.GROUP_KEY = :group_key and %PREFIX%CHANNEL_MESSAGE.REGION = :region " +
"order by CREATED_DATE, MESSAGE_SEQUENCE FETCH FIRST ROW ONLY";
}
如果容量已满,则执行此逻辑:
/**
* Inserts the specified element into this queue, waiting up to the
* specified wait time if necessary for space to become available.
*
* @param e the element to add
* @param timeout how long to wait before giving up, in units of
* {@code unit}
* @param unit a {@code TimeUnit} determining how to interpret the
* {@code timeout} parameter
* @return {@code true} if successful, or {@code false} if
* the specified waiting time elapses before space is available
* @throws InterruptedException if interrupted while waiting
* @throws ClassCastException if the class of the specified element
* prevents it from being added to this queue
* @throws NullPointerException if the specified element is null
* @throws IllegalArgumentException if some property of the specified
* element prevents it from being added to this queue
*/
boolean offer(E e, long timeout, TimeUnit unit)
它是从QueueChannel.send调用的,返回一个布尔值以指示是否需要为队列提供消息
如果要更改已处理队列通道中的订单消息,可以提供自己的队列impl:
在Spring Integration中还有一个优先频道:谢谢Artem!而且,我的民意测验没有遗嘱执行人。有executor是一种好的做法,还是可以使用默认的10个任务调度程序线程?好吧,如果引入executor,您将丢失从队列中提取的消息的FIFO顺序。所以,一切都取决于您的需求。我不知道执行器将如何丢失订单FIFO,执行器只是用于控制轮询器上的线程,轮询器默认有10个线程。顺序应由队列控制。您的意思是并行运行线程会导致顺序丢失吗?如果是这样的话,只要队列以FIFO顺序弹出消息,这将是微不足道的。是的,队列仍然以正确的顺序轮询。这不是问题。但您与该执行器的处理可能会导致并行。因此,我认为我们可以将其视为FIFO的丢失:对于执行器,如果我们在单独的线程中处理消息,那么无论我们如何从队列中提取消息,都已经是如此。
/**
* Create a channel with the specified queue.
*
* @param queue The queue.
*/
public QueueChannel(Queue<Message<?>> queue) {