use of javax.jms.Connection in project camel by apache.
the class SjmsProducer method createSession.
protected Session createSession() throws Exception {
ConnectionResource connectionResource = getOrCreateConnectionResource();
Connection conn = connectionResource.borrowConnection();
try {
return conn.createSession(isEndpointTransacted(), getAcknowledgeMode());
} catch (Exception e) {
log.error("Unable to create the Session", e);
throw e;
} finally {
connectionResource.returnConnection(conn);
}
}
use of javax.jms.Connection in project spring-boot by spring-projects.
the class JmsHealthIndicatorTests method jmsBrokerUsesFailover.
@Test
public void jmsBrokerUsesFailover() throws JMSException {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
ConnectionMetaData connectionMetaData = mock(ConnectionMetaData.class);
given(connectionMetaData.getJMSProviderName()).willReturn("JMS test provider");
Connection connection = mock(Connection.class);
given(connection.getMetaData()).willReturn(connectionMetaData);
willThrow(new JMSException("Could not start", "123")).given(connection).start();
given(connectionFactory.createConnection()).willReturn(connection);
JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory);
Health health = indicator.health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat(health.getDetails().get("provider")).isNull();
}
use of javax.jms.Connection in project spring-boot by spring-projects.
the class JmsHealthIndicator method doHealthCheck.
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
Connection connection = this.connectionFactory.createConnection();
try {
connection.start();
builder.up().withDetail("provider", connection.getMetaData().getJMSProviderName());
} finally {
connection.close();
}
}
use of javax.jms.Connection in project spring-framework by spring-projects.
the class JmsTransactionManagerTests method testSuspendedTransaction.
@Test
public void testSuspendedTransaction() throws JMSException {
final ConnectionFactory cf = mock(ConnectionFactory.class);
Connection con = mock(Connection.class);
final Session session = mock(Session.class);
final Session session2 = mock(Session.class);
given(cf.createConnection()).willReturn(con);
given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session);
given(con.createSession(false, Session.AUTO_ACKNOWLEDGE)).willReturn(session2);
JmsTransactionManager tm = new JmsTransactionManager(cf);
TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition());
final JmsTemplate jt = new JmsTemplate(cf);
jt.execute(new SessionCallback<Void>() {
@Override
public Void doInJms(Session sess) {
assertTrue(sess == session);
return null;
}
});
TransactionTemplate tt = new TransactionTemplate(tm);
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_NOT_SUPPORTED);
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
jt.execute(new SessionCallback<Void>() {
@Override
public Void doInJms(Session sess) {
assertTrue(sess != session);
return null;
}
});
}
});
jt.execute(new SessionCallback<Void>() {
@Override
public Void doInJms(Session sess) {
assertTrue(sess == session);
return null;
}
});
tm.commit(ts);
verify(session).commit();
verify(session).close();
verify(session2).close();
verify(con, times(2)).close();
}
use of javax.jms.Connection in project spring-framework by spring-projects.
the class JmsTransactionManagerTests method testParticipatingTransactionWithRollbackOnly.
@Test
public void testParticipatingTransactionWithRollbackOnly() throws JMSException {
ConnectionFactory cf = mock(ConnectionFactory.class);
Connection con = mock(Connection.class);
final Session session = mock(Session.class);
given(cf.createConnection()).willReturn(con);
given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session);
JmsTransactionManager tm = new JmsTransactionManager(cf);
TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition());
final JmsTemplate jt = new JmsTemplate(cf);
jt.execute(new SessionCallback<Void>() {
@Override
public Void doInJms(Session sess) {
assertTrue(sess == session);
return null;
}
});
TransactionTemplate tt = new TransactionTemplate(tm);
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
jt.execute(new SessionCallback<Void>() {
@Override
public Void doInJms(Session sess) {
assertTrue(sess == session);
return null;
}
});
status.setRollbackOnly();
}
});
try {
tm.commit(ts);
fail("Should have thrown UnexpectedRollbackException");
} catch (UnexpectedRollbackException ex) {
// expected
}
verify(session).rollback();
verify(session).close();
verify(con).close();
}
Aggregations