此类问题的模式
我需要有关用于解决以下问题的模式的建议。
在与一个文件相对应的表中,有很多行——我们称之为消息(由数据库中的 MSG_ID 标识)。意味着该文件已被分割成许多块并放入数据库中。
因此,可以使用 GROUP_ID 列来标识与文件对应的部分,并且 MSG_ID 对应于单独的消息。主键是 GROUP_ID 和 MSG_ID 的组合。
现在,每条消息由 n 个逻辑记录组成(通常是支付指令(kx 128 字节数据))。只有读完接下来的128个字符后才能得知当前读取支付指令结束。支付指令的一部分也可以位于连续的消息中。这意味着一条完整的支付指令可以分布在 MSG_ID n 的末尾和 MSG_ID n+1 的开头。
我们正在使用 Spring Batch 进行处理。
我尝试查询表并将所有记录一一写入到一个平面文件中,然后从那里开始春季批处理。
我想知道是否有任何模式可以用来在不使用平面文件的情况下实现要求。
例如,
从数据库中读取 MSG_ID 1 和 GROUP_ID“ABC”
分离支付指令并将每条指令发送给处理者。
当到达 MSG_ID 1 结束时,检查手中的最终记录是否构成付款指令,如果没有,则读取 MSG_ID 2 和 GROUP_ID“ABC”,并附加到之前剩余的记录。
读取直到MSG_ID==N,其中N在开始读取过程之前已知。
Spring 中是否有 ItemReaders 或 java 中的迭代器模式可供我使用?
更清楚地说,有一些处理模式,“如果您的逻辑记录分布在多行中”。是否有任何模式“如果数据库中的一行包含'M'个逻辑记录,其中M可能不是整数,请使用这种类型的Iterator或ItemReaders”
谢谢。
I need advise regarding the pattern to use for the following problem.
There are many rows -- let us call it messages(identified by MSG_ID in DB)-- in a table which corresponds to a file. Means, the file has been split into many pieces and put into database.
So parts corresponding to file can be identified using a GROUP_ID column, and MSG_ID corresponds to individual message. The primary key is a combination of GROUP_ID and MSG_ID.
Now, each message consists of n number of logical records(which are typically payment instructions(k x 128 bytes of data)). Where current reading payment instruction ends can be said only after reading the next 128 characters. Also parts of a payment instruction can be in consecutive messages. Which means a complete payment instruction can be spread across end of MSG_ID n and start of MSG_ID n+1.
We are using spring batch to do the processing.
I have tried querying the table and writing all the records to a flat file one by one and start the spring batch from there.
I would like to know whether there's any pattern which I can use to achieve the requirement without using a flat file.
Like,
Read MSG_ID 1 and GROUP_ID "ABC" from db
Seperate the payment instructions and give each instruction to the processor.
When end of MSG_ID 1 is reached check whether the final record in hand form a Payment Instruction, if not read MSG_ID 2 and GROUP_ID "ABC" and append to the previous left over record.
Read till MSG_ID==N where N is known before starting the read process.
Is there any ItemReaders in Spring or Iterator patterns in java which I can use ?
To be more clear, there are patterns for handling, "IF your logical record is spread in multiple rows". Is there any pattern for "IF one row in DB contains 'M' number logical records, where M may not be an integer, use this type of Iterator or ItemReaders"
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信您应该为您的场景编写一个自定义
Reader
(处理逻辑)。这显然不是一个常见的情况。你提出的算法看起来不错。您应该可以轻松编写一个读取完整付款指令并将其移交给进一步处理的
Reader
。I believe you should write a custom
Reader
(processing logic) for your scenario. It certainly doesn't seem as a common case.The algorithm you proposed seems OK. You should have no trouble writing a
Reader
which reads a complete payment instruction and hands it off for further processing.