cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to write each document to a file rather than all documents to a single file

mohamadelmardin
New Contributor III

I am reading multiple messages using JMS consumer into one big binary file then using a binary to document snap I am breaking it into multiple documents. How can I write each document to a separate file with timestamp rather than writing all the documents at the end to one file?

I know there is a way to do that using ForEach pipeline where you can send each document seperately but I donโ€™t want to use a master pipeline and a child pipeline. I want all operations to be done in one single pipeline.

9 REPLIES 9

@Bhavin
Thank you this what I ended up doing and the closest thing to my solution. I have one clarification though regarding using two JMS Acknowledge snaps (Acknowledge, Reject) instead of just one. Isnโ€™t the other JMS Acknowledge snap for โ€˜Rejectโ€™ redundant? Why cannot we use just one Acknowledge snap and if the message processed successfully then it will be acknowledged but the message wasnโ€™t processed and didnโ€™t make it till the end then the message wonโ€™t be acknowledged therefore it will remain in the queue for future processing. I donโ€™t see what difference would it make to add a Reject snap with Recover message box checked since the first Acknowledge snap can cover both scenario.

Regarding your request to share the JMS account configuration I will be more than happy to share it below ๐Ÿ™‚

6c59ce9d0ceb6d9eed975b9afed3e86f8680ee4a.png

Isnโ€™t the other JMS Acknowledge snap for โ€˜Rejectโ€™ redundant?
yes, mine was geared more towards โ€œastheticsโ€ ๐Ÿ™‚

Regarding your request to share the JMS account configuration I will be more than happy to share it below
much obliged

tstack
Former Employee

Getting back to your original question, you can write separate documents with the JSON-Formatter, XML-Formatter, and DocumentToBinary snaps. You can then configure the FileWriter snap with an expression for the file name, for example:

'out_' + Date.now() + '.json'

Or, if you just want a sequence number, you can use the โ€˜snap.in.totalCountโ€™ variable:

'out_' + snap.in.totalCount + '.json'

So, every document generated by the formatter snap will be written to its own file with the name computed by the expression.

To configure the formatters:

  • JSON Formatter - Select the โ€˜Format each documentโ€™ option.
  • XML Formatter - Clear the โ€˜Root elementโ€™ field. Note that the input document should only have a single field that represents the root element.
  • Document To Binary - Set โ€˜Encode or Decodeโ€™ to DOCUMENT.

sandeepkasaram
New Contributor

@mohamadelmardini For breaking up each document from JMS queue we are following the same method as they suggested above,do we still having issue breaking up the documents ?also the JMS acknowledge we were able to acknowledge the messages based JMS Message ID as suggested above only thing we didnโ€™t do is having the reject acknowledge .

Sandeep the original solution wasnโ€™t working when I tested it out. I updated the approach and it is working now. You can check it out at DEV environment.

All is good now.