[英]JMS messages to file in a reliable way
I'm looking for a way to reliably retrieve messages from a JMS queue and store them into a flat file. 我正在寻找一种从JMS队列可靠地检索消息并将其存储到平面文件中的方法。 By "reliably" I mean that in case of any failure (excluding failures of physical disks), possibly after system and processes are re-launched, I want: “可靠地”是指在发生任何故障(不包括物理磁盘故障)的情况下,可能在重新启动系统和进程之后,我要:
What would be a good way for achieving this goal? 什么是实现这个目标的好方法?
Context: WebLogic on Linux, receiving about 3000 messages/second for several hours. 上下文:Linux上的WebLogic,在几个小时内每秒接收大约3000条消息。
Thanks -- Florian. 谢谢-弗洛里安
The problem you'll face is the file system; 您将面临的问题是文件系统。 JMS supports JTA, but the file system does not. JMS支持JTA,但文件系统不支持。 Consider the following: 考虑以下:
public void onMessage(Message message){
try{
TextMessage msg = (TextMessage)message;
fileOutput.write( msg.getText());
fileOutput.flush();
}catch(Exception e){
e.printStackTrace();
throw e;
}
}
Assuming AUTO_ACKNOWLEDGE, each message received and serialized to the file will be auto acknowledged after onMessage()
returns successfully. 假定为AUTO_ACKNOWLEDGE,则onMessage()
成功返回后,将自动确认收到的每个消息并序列化到该文件。 But the JMS server may crash before the acknowledgment is received, but after the message was written to the file; 但是,JMS服务器可能在收到确认之前,而是在将消息写入文件之后崩溃。 so you'll get a duplicate. 所以你会得到一个副本。
Instead of writing to a file, have you considered saving to a database, preferably one that has a XA driver? 您是否考虑过保存到数据库(最好是具有XA驱动程序的数据库),而不是写入文件? If so, you can use a distributed transaction between JMS and RDBMS, resulting in no message loss or duplicates. 如果是这样,则可以在JMS和RDBMS之间使用分布式事务,不会导致消息丢失或重复。
Hope it helps 希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.