use of javax.jms.QueueConnection in project activemq-artemis by apache.
the class OutgoingConnectionJTATest method testSimpleMessageSendAndReceiveTransacted.
@Test
public void testSimpleMessageSendAndReceiveTransacted() throws Exception {
setDummyTX();
setupDLQ(10);
resourceAdapter = newResourceAdapter();
MyBootstrapContext ctx = new MyBootstrapContext();
resourceAdapter.start(ctx);
ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
mcf.setResourceAdapter(resourceAdapter);
ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
Session s = queueConnection.createSession(true, Session.AUTO_ACKNOWLEDGE);
Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
MessageProducer mp = s.createProducer(q);
MessageConsumer consumer = s.createConsumer(q);
Message message = s.createTextMessage("test");
mp.send(message);
s.commit();
queueConnection.start();
TextMessage textMessage = (TextMessage) consumer.receive(1000);
assertNotNull(textMessage);
assertEquals(textMessage.getText(), "test");
s.rollback();
textMessage = (TextMessage) consumer.receive(1000);
assertNotNull(textMessage);
assertEquals(textMessage.getText(), "test");
s.commit();
}
use of javax.jms.QueueConnection in project activemq-artemis by apache.
the class OutgoingConnectionNoJTATest method testSimpleMessageSendAndReceiveSessionTransacted2.
@Test
public void testSimpleMessageSendAndReceiveSessionTransacted2() throws Exception {
setupDLQ(10);
resourceAdapter = newResourceAdapter();
MyBootstrapContext ctx = new MyBootstrapContext();
resourceAdapter.start(ctx);
ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
mcf.setAllowLocalTransactions(true);
mcf.setResourceAdapter(resourceAdapter);
ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
Session s = queueConnection.createSession(Session.SESSION_TRANSACTED);
Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
MessageProducer mp = s.createProducer(q);
MessageConsumer consumer = s.createConsumer(q);
Message message = s.createTextMessage("test");
mp.send(message);
s.commit();
queueConnection.start();
TextMessage textMessage = (TextMessage) consumer.receive(1000);
assertNotNull(textMessage);
assertEquals(textMessage.getText(), "test");
s.rollback();
textMessage = (TextMessage) consumer.receive(1000);
assertNotNull(textMessage);
assertEquals(textMessage.getText(), "test");
s.commit();
textMessage = (TextMessage) consumer.receiveNoWait();
assertNull(textMessage);
}
use of javax.jms.QueueConnection in project activemq-artemis by apache.
the class OutgoingConnectionNoJTATest method testQueueSessionAckMode.
@Test
public void testQueueSessionAckMode() throws Exception {
QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
Session s = queueConnection.createSession(false, Session.SESSION_TRANSACTED);
s.close();
}
use of javax.jms.QueueConnection in project oxAuth by GluuFederation.
the class ApplicationAuditLogger method loggingThroughJMS.
private boolean loggingThroughJMS(OAuth2AuditLog oAuth2AuditLog) {
QueueConnection connection = null;
try {
connection = pooledConnectionFactory.createQueueConnection();
connection.start();
QueueSession session = connection.createQueueSession(transacted, ACK_MODE);
MessageProducer producer = session.createProducer(session.createQueue(CLIENT_QUEUE_NAME));
TextMessage txtMessage = session.createTextMessage();
txtMessage.setText(ServerUtil.asPrettyJson(oAuth2AuditLog));
producer.send(txtMessage);
return true;
} catch (JMSException e) {
log.error("Can't send message", e);
} catch (IOException e) {
log.error("Can't serialize the audit log", e);
} catch (Exception e) {
log.error("Can't send message, please check your activeMQ configuration.", e);
} finally {
if (connection == null) {
return false;
}
try {
connection.close();
} catch (JMSException e) {
log.error("Can't close connection.");
}
}
return false;
}
use of javax.jms.QueueConnection in project wildfly by wildfly.
the class QueueTestMDB method sendReply.
private void sendReply(Queue destination, String messageID, Exception e) throws JMSException {
QueueConnection conn = qFactory.createQueueConnection();
try {
QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
QueueSender sender = session.createSender(destination);
ObjectMessage message = session.createObjectMessage(e);
message.setJMSCorrelationID(messageID);
sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 500);
} finally {
conn.close();
}
}
Aggregations