Package org.javalite.async
Class BatchReceiver
java.lang.Object
org.javalite.async.BatchReceiver
- All Implemented Interfaces:
Closeable
,AutoCloseable
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:
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
ModifierConstructorDescriptionprotected
BatchReceiver(String queueName, long timeout, javax.jms.Connection connection)
-
Method Summary
-
Constructor Details
-
BatchReceiver
protected BatchReceiver(String queueName, long timeout, javax.jms.Connection connection) throws javax.jms.JMSException- Throws:
javax.jms.JMSException
-
-
Method Details
-
receiveTextMessages
Receives and returnssize
Strings from the queue. Presumes that messages in queue areTextMessage
.- Parameters:
maxSize
- maximum number of messages to receive- Returns:
size
messages 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-