use of oracle.AQ.AQDequeueOption in project autonomous-database-for-developers by loiclefevre.
the class AQDequeueService method run.
@Override
public void run() {
try {
final AQQueue queue = aqSessionForDequeue.getQueue(ociConfiguration.getDatabaseUsername(), "AQ_NOTIFICATIONS_QUEUE");
final AQDequeueOption dequeueOption = new AQDequeueOption();
// timeout after 2 seconds
dequeueOption.setWaitTime(2);
try {
while (isRunning()) {
try {
final Event event = getMessage(queue, dequeueOption);
if (event.priority == AQEnqueueService.HIGH_PRIORITY) {
LOG.warn("Thread {} received HIGH priority message: {}", Thread.currentThread().getName(), event.message());
} else {
LOG.warn("Thread {} received message: {}", Thread.currentThread().getName(), event.message());
}
} catch (AQException e) {
if (e.getErrorCode() != AQ_TIMEOUT_ERROR_CODE && e.getErrorCode() != AQ_DEQUEUE_DISABLED) {
throw e;
}
}
}
} finally {
// and rollback before!
try {
aqSessionForDequeue.getDBConnection().rollback();
} catch (SQLException ignored) {
}
try {
queue.stopEnqueue(false);
queue.stopDequeue(false);
} catch (AQException ignored) {
}
}
} catch (AQException | SQLException e) {
LOG.error("While dequeuing!", e);
} finally {
if (aqSessionForDequeue != null) {
LOG.info("Closing AQ session...");
aqSessionForDequeue.close();
}
}
}
use of oracle.AQ.AQDequeueOption in project eclipselink by eclipse-ee4j.
the class OrderQueueTest method testReadTimeout.
/**
* Reading with a dequeue timeout test.
*/
@Test
public void testReadTimeout() throws Exception {
final DatabaseSession session = SessionHelper.createDatabaseSession(AQTestSuite.project);
XMLInteraction interaction = new XMLInteraction();
AQDequeueOption options = new AQDequeueOption();
options.setWaitTime(1);
interaction.setProperty(AQPlatform.QUEUE_OPERATION, AQPlatform.DEQUEUE);
interaction.setProperty(AQPlatform.DEQUEUE_OPTIONS, options);
boolean timeout = false;
try {
session.readObject(org.eclipse.persistence.testing.models.order.Order.class, interaction);
} catch (EISException exception) {
timeout = true;
if (exception.getMessage().indexOf("timeout") == -1) {
throw exception;
}
} finally {
session.logout();
}
if (!timeout) {
throw new TestErrorException("Timeout exception did not occur, was a message in the queue.");
}
}
use of oracle.AQ.AQDequeueOption in project eclipselink by eclipse-ee4j.
the class JavaDirectInteractionTest method testDirectInteraction.
/**
* Test AQ Java driver direct interactions.
*/
@Test
public void testDirectInteraction() throws Exception {
// Only this test uses "raw_order_queue" in this class so relational database session is local.
final DatabaseSession rDBSession = SessionHelper.createDatabaseSession(SessionHelper.createModelProject(SessionHelper.createDatabaseLogin(), JavaDirectInteractionTest.class));
ModelHelper.setupRawOrderQueue(rDBSession);
Connection connection = null;
AQSession session = null;
try {
connection = getConnection();
connection.setAutoCommit(false);
Class.forName("oracle.AQ.AQOracleDriver");
session = AQDriverManager.createAQSession(connection);
AQQueue queue = session.getQueue(NoSQLProperties.getDBUserName(), "raw_order_queue");
LOG.log(SessionLog.FINEST, queue.toString());
AQMessage message = queue.createMessage();
LOG.log(SessionLog.FINEST, message.toString());
AQRawPayload payload = message.getRawPayload();
byte[] bytes = "hello".getBytes();
payload.setStream(bytes, bytes.length);
AQEnqueueOption enqueueOption = new AQEnqueueOption();
queue.enqueue(enqueueOption, message);
connection.commit();
AQDequeueOption dequeueOption = new AQDequeueOption();
message = queue.dequeue(dequeueOption);
LOG.log(SessionLog.FINEST, message != null ? message.toString() : null);
LOG.log(SessionLog.FINEST, message != null ? new String(message.getRawPayload().getBytes()) : null);
connection.commit();
} finally {
if (session != null) {
session.close();
}
if (connection != null) {
connection.close();
}
ModelHelper.resetRawOrderQueue(rDBSession);
rDBSession.logout();
}
}
Aggregations