public class BatchReceiver extends Object implements Closeable
//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();
Modifier | Constructor and Description |
---|---|
protected |
BatchReceiver(javax.jms.Queue queue,
long timeout,
javax.jms.Connection connection) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this resource (calling it is mandatory).
|
void |
commit()
Commits a current transaction.
|
List<String> |
receiveTextMessages(int maxSize)
Receives and returns
size Strings from the queue. |
void |
rollback()
Rolls back current transaction.
|
protected BatchReceiver(javax.jms.Queue queue, long timeout, javax.jms.Connection connection) throws javax.jms.JMSException
javax.jms.JMSException
public List<String> receiveTextMessages(int maxSize)
size
Strings from the queue.
Presumes that messages in queue are TextMessage
.maxSize
- maximum number of messages to receivesize
messages from the queue.public void commit()
public void rollback()
public void close()
close
in interface Closeable
close
in interface AutoCloseable
Copyright © 2019 JavaLite. All rights reserved.