Note that there are some explanatory texts on larger screens.

plurals
  1. POWriting into file under NFS in Grails app using Quartz and RabbitMQ
    primarykey
    data
    text
    <p>We have a Grails app, that uses RabbitMQ for passing messages. The architecture we have for the production environent is:<br> - 2 web servers, let's say web1, web2. Both of them run an instance of a grails app<br> - a RabbitMQ server is installed on only one of the servers, web1<br> - In the RabbitMQ configuration in the Grails app, we have 10 consumers (per application instance) </p> <p>We have a Quartz job that creates some messages and passes them to the queue, and we have a consumer service that handles the messages getting in the queue.<br> 1. How can we define which server (application instance)should execute the Quartz job? I assume there's only one server running the Job and Quartz is taking care of that.<br> 2. How can we define which server handles the messages from the queue? </p> <p>The problem is, that the methods that consume the queue messages, eventually write some rows in a .csv file, which is under NFS. </p> <p>Initially we had some <a href="https://stackoverflow.com/questions/5104074/writing-to-file-with-groovygrails-fails-for-some-lines-broken-lines">issues</a>, with the actual writing in the .csv file. There were some "broken", half-written rows in the file, but we resolved this by adding @Synchronized on the method that wrote in the .csv file. Now the issue is, that some rows, just don't get written at all. </p> <p>Any ideas? I am not sure whether this is a programming issue, and if so how could it be resolved, or if it is an architectural issue. </p> <p><strong>UPD</strong>:@Olexandr<br> Initially I had (example) <code><pre>def getStringsToWrite(File file, List someOtherList) { def stringsList = [] someOtherList.each { def someString = "someString" stringsList &lt;&lt; someString } writeRowsToFile(file, stringsList) }</p> <p>@Synchronized def writeRowsToFile(File file, List stringsList) { file.withWriterAppend {out-> stringsList.each {row-> out.writeLine row } } } </pre></code></p> <p>And it did was not working "properly"</p> <p>Now, I changed the code to something like: <pre> class someServiceClass { //singleton <strong>LinkedBlockingQueue csvWritingQueue = new LinkedBlockingQueue()</strong> </p> <p>def getStringsToWrite(File file, List someOtherList) { def stringsList = [] someOtherList.each { def someString = "someString" <strong>csvWritingQueue.put(someString)</strong> } writeRowsToFile(<strong>file</strong>) }</p> <p>@Synchronized def writeRowsToFile(File file) { file.withWriterAppend {out-> <strong>while (!csvWritingQueue.isEmpty()) {</strong> <strong>out.writeLine csvWritingQueue.poll()</strong> } } } } </pre> </p> <p>Please let me know if you need any additional info. I tried to keep it at a high level perspective, but I will be more than happy to include some code in the post. </p> <p>Thanks in advance,<br> Iraklis</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload