Package org.javalite.async
Class BatchReceiver
- java.lang.Object
-
- org.javalite.async.BatchReceiver
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class BatchReceiver extends Object implements Closeable
Use to batch-read text messages from Async in a cont5ext of a transaction. Usually used to pass JSON or XML documents.
Typical usage pattern://send messages: async.sendTextMessage(QUEUE_NAME, jsonDocument); ... // repeat //receive messages: BatchReceiver br = async.getBatchReceiver(QUEUE_NAME, 100); List
*** NEVER FORGET TO COMMIT AND CLOSE! ***messages = br.receiveTextMessages(500); //... process messages, commit to database br.commit(); // <<< -- deletes messages from queue br.close(); - Author:
- igor on 8/8/17.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBatchReceiver(String queueName, long timeout, javax.jms.Connection connection)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes this resource (calling it is mandatory).voidcommit()Commits a current transaction.List<String>receiveTextMessages(int maxSize)Receives and returnssizeStrings from the queue.voidrollback()Rolls back current transaction.
-
-
-
Constructor Detail
-
BatchReceiver
protected BatchReceiver(String queueName, long timeout, javax.jms.Connection connection) throws javax.jms.JMSException
- Throws:
javax.jms.JMSException
-
-
Method Detail
-
receiveTextMessages
public List<String> receiveTextMessages(int maxSize)
Receives and returnssizeStrings from the queue. Presumes that messages in queue areTextMessage.- Parameters:
maxSize- maximum number of messages to receive- Returns:
sizemessages from the queue.
-
commit
public void commit()
Commits a current transaction. This acknowledges that all messages have been processed. All messages received before this call will be removed from queue and not delivered again.
-
rollback
public void rollback()
Rolls back current transaction. All "received" messages will be re-delivered.
-
close
public void close()
Closes this resource (calling it is mandatory).- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
-