use of jakarta.jms.ConnectionFactory in project spring-boot by spring-projects.
the class JmsAutoConfigurationTests method testPubSubDomainOverride.
@Test
void testPubSubDomainOverride() {
this.contextRunner.withUserConfiguration(TestConfiguration.class).withPropertyValues("spring.jms.pubSubDomain:false").run((context) -> {
assertThat(context).hasSingleBean(JmsTemplate.class);
assertThat(context).hasSingleBean(ConnectionFactory.class);
JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
ConnectionFactory factory = context.getBean(ConnectionFactory.class);
assertThat(jmsTemplate).isNotNull();
assertThat(jmsTemplate.isPubSubDomain()).isFalse();
assertThat(factory).isNotNull().isEqualTo(jmsTemplate.getConnectionFactory());
});
}
use of jakarta.jms.ConnectionFactory in project spring-boot by spring-projects.
the class JmsHealthIndicatorTests method jmsBrokerIsDown.
@Test
void jmsBrokerIsDown() throws JMSException {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
given(connectionFactory.createConnection()).willThrow(new JMSException("test", "123"));
JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory);
Health health = indicator.health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat(health.getDetails().get("provider")).isNull();
}
use of jakarta.jms.ConnectionFactory in project spring-boot by spring-projects.
the class JmsHealthIndicatorTests method whenConnectionStartIsUnresponsiveStatusIsDown.
@Test
void whenConnectionStartIsUnresponsiveStatusIsDown() throws JMSException {
ConnectionMetaData connectionMetaData = mock(ConnectionMetaData.class);
given(connectionMetaData.getJMSProviderName()).willReturn("JMS test provider");
Connection connection = mock(Connection.class);
UnresponsiveStartAnswer unresponsiveStartAnswer = new UnresponsiveStartAnswer();
willAnswer(unresponsiveStartAnswer).given(connection).start();
willAnswer((invocation) -> {
unresponsiveStartAnswer.connectionClosed();
return null;
}).given(connection).close();
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
given(connectionFactory.createConnection()).willReturn(connection);
JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory);
Health health = indicator.health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat((String) health.getDetails().get("error")).contains("Connection closed");
}
use of jakarta.jms.ConnectionFactory in project spring-framework by spring-projects.
the class DelegatingConnectionFactory method obtainTargetConnectionFactory.
private ConnectionFactory obtainTargetConnectionFactory() {
ConnectionFactory target = getTargetConnectionFactory();
Assert.state(target != null, "No 'targetConnectionFactory' set");
return target;
}
use of jakarta.jms.ConnectionFactory in project spring-framework by spring-projects.
the class JmsTransactionManager method doBegin.
@Override
protected void doBegin(Object transaction, TransactionDefinition definition) {
if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
throw new InvalidIsolationLevelException("JMS does not support an isolation level concept");
}
ConnectionFactory connectionFactory = obtainConnectionFactory();
JmsTransactionObject txObject = (JmsTransactionObject) transaction;
Connection con = null;
Session session = null;
try {
JmsResourceHolder resourceHolder;
if (this.lazyResourceRetrieval) {
resourceHolder = new LazyJmsResourceHolder(connectionFactory);
} else {
con = createConnection();
session = createSession(con);
if (logger.isDebugEnabled()) {
logger.debug("Created JMS transaction on Session [" + session + "] from Connection [" + con + "]");
}
resourceHolder = new JmsResourceHolder(connectionFactory, con, session);
}
resourceHolder.setSynchronizedWithTransaction(true);
int timeout = determineTimeout(definition);
if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) {
resourceHolder.setTimeoutInSeconds(timeout);
}
txObject.setResourceHolder(resourceHolder);
TransactionSynchronizationManager.bindResource(connectionFactory, resourceHolder);
} catch (Throwable ex) {
if (session != null) {
try {
session.close();
} catch (Throwable ex2) {
// ignore
}
}
if (con != null) {
try {
con.close();
} catch (Throwable ex2) {
// ignore
}
}
throw new CannotCreateTransactionException("Could not create JMS transaction", ex);
}
}
Aggregations