转载

java – JMS和Spring批处理

我们的项目是使用每个的rest api集成两个应用程序,使用JMS(提供异步性质)和 spring

批处理从JMS队列读取批量数据并处理它,然后将其发布到接收应用程序.

我是JMS和春季批次的新手.我有几个基本问​​题要问:

>未来的哪个JMS模型 – (PTP或Pub / Sub)

>可以从JMS队列批量读取消息(使用JMSItemReader).如果是的话,任何人都可以提供代码.

>我们希望在将消息成功发布(即读取 – 处理 – 写入)到接收应用程序之后将消息确认为“已读”,而不是在JMSItemReader读取消息时.我们怎样才能做到这一点?

高级设计图如下

java – JMS和Spring批处理

PTP vs Pub / sub

使用消息队列的点对点方法是最标准的方法.特别是在批处理应用程序中,我看不到使用Publish订阅的直接原因,假设您有多个相同消息的使用者.

理论上如果需要在相同的数据块上执行多个功能,您可以将不同的处理器组织为订户,这样就可以扩展应用程序,但这是非常先进的使用场景.

可以从JMS队列批量读取消息:

这里的JMS规范只讨论(模糊地可能误读它)关于消息的批量确认,但它没有对消息的批量传递设置要求.

CLIENT_ACKNOWLEDGE – With this option, a client acknowledges a message  by calling the message’s acknowledge method. Acknowledging a consumed  message automatically acknowledges the receipt of all messages that  have been delivered by its session. 

简单地说,关于批量交付的答案是“如果JMS提供商支持它,那么是,否则没有”

大多数提供商允许批量确认消息

这是Oracles的界面:

public interface com.sun.messaging.jms.Message {
          void acknowledgeThisMessage() throws JMSException;
          void acknowledgeUpThroughThisMessage() throws JMSException;
}

CLIENT_ACKNOWLEDGE的组合.在a上调用方法acknowledgeUpThroughThisMessage.消息将确认到那时为止收到的所有消息.

手动确认消息:

这可以通过CLIENT_ACKNOWLEDGE和Message上的确认方法来实现.在这里,我将再次引用您的确认方法的javadoc,它还引用了您的第二个问题,并且它讨论了直到某一点的所有消息的批量确认.

void acknowledge()  throws JMSException Acknowledges all consumed messages of the session of this consumed message. All consumed JMS messages  support the acknowledge method for use when a client has specified  that its JMS session’s consumed messages are to be explicitly  acknowledged. By invoking acknowledge on a consumed message, a client  acknowledges all messages consumed by the session that the message was  delivered to.
Calls to acknowledge are ignored for both transacted sessions and  sessions specified to use implicit acknowledgement modes.
A client may individually acknowledge each message as it is consumed,  or it may choose to acknowledge messages as an application-defined  group (which is done by calling acknowledge on the last received  message of the group, thereby acknowledging all messages consumed by  the session.)
Messages that have been received but not acknowledged may be  redelivered.

翻译自:https://stackoverflow.com/questions/32992665/jms-and-spring-batch

原文  https://codeday.me/bug/20190112/503948.html
正文到此结束
Loading...