Search in sources :

Example 11 with JmsTemplate

use of org.springframework.jms.core.JmsTemplate in project spring-boot by spring-projects.

the class ArtemisAutoConfigurationTests method embeddedWithPersistentMode.

@Test
public void embeddedWithPersistentMode() throws IOException, JMSException {
    File dataFolder = this.folder.newFolder();
    // Start the server and post a message to some queue
    load(EmptyConfiguration.class, "spring.artemis.embedded.queues=TestQueue", "spring.artemis.embedded.persistent:true", "spring.artemis.embedded.dataDirectory:" + dataFolder.getAbsolutePath());
    final String msgId = UUID.randomUUID().toString();
    JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
    jmsTemplate.send("TestQueue", new MessageCreator() {

        @Override
        public Message createMessage(Session session) throws JMSException {
            return session.createTextMessage(msgId);
        }
    });
    // Shutdown the broker
    this.context.close();
    // Start the server again and check if our message is still here
    load(EmptyConfiguration.class, "spring.artemis.embedded.queues=TestQueue", "spring.artemis.embedded.persistent:true", "spring.artemis.embedded.dataDirectory:" + dataFolder.getAbsolutePath());
    JmsTemplate jmsTemplate2 = this.context.getBean(JmsTemplate.class);
    jmsTemplate2.setReceiveTimeout(1000L);
    Message message = jmsTemplate2.receive("TestQueue");
    assertThat(message).isNotNull();
    assertThat(((TextMessage) message).getText()).isEqualTo(msgId);
}
Also used : Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) JmsTemplate(org.springframework.jms.core.JmsTemplate) JMSException(javax.jms.JMSException) File(java.io.File) MessageCreator(org.springframework.jms.core.MessageCreator) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 12 with JmsTemplate

use of org.springframework.jms.core.JmsTemplate in project spring-boot by spring-projects.

the class ArtemisAutoConfigurationTests method nativeConnectionFactory.

@Test
public void nativeConnectionFactory() {
    load(EmptyConfiguration.class, "spring.artemis.mode:native");
    JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
    ActiveMQConnectionFactory connectionFactory = this.context.getBean(ActiveMQConnectionFactory.class);
    assertThat(connectionFactory).isEqualTo(jmsTemplate.getConnectionFactory());
    assertNettyConnectionFactory(connectionFactory, "localhost", 61616);
    assertThat(connectionFactory.getUser()).isNull();
    assertThat(connectionFactory.getPassword()).isNull();
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) JmsTemplate(org.springframework.jms.core.JmsTemplate) Test(org.junit.Test)

Example 13 with JmsTemplate

use of org.springframework.jms.core.JmsTemplate in project spring-boot by spring-projects.

the class JmsAutoConfigurationTests method testActiveMQOverriddenPool.

@Test
public void testActiveMQOverriddenPool() {
    load(TestConfiguration.class, "spring.activemq.pool.enabled:true");
    JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
    PooledConnectionFactory pool = this.context.getBean(PooledConnectionFactory.class);
    assertThat(jmsTemplate).isNotNull();
    assertThat(pool).isNotNull();
    assertThat(pool).isEqualTo(jmsTemplate.getConnectionFactory());
    ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) pool.getConnectionFactory();
    assertThat(factory.getBrokerURL()).isEqualTo(ACTIVEMQ_EMBEDDED_URL);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) JmsTemplate(org.springframework.jms.core.JmsTemplate) PooledConnectionFactory(org.apache.activemq.pool.PooledConnectionFactory) Test(org.junit.Test)

Example 14 with JmsTemplate

use of org.springframework.jms.core.JmsTemplate in project spring-boot by spring-projects.

the class JmsAutoConfigurationTests method testPubSubDomainActive.

@Test
public void testPubSubDomainActive() {
    load(TestConfiguration.class, "spring.jms.pubSubDomain:true");
    JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
    DefaultMessageListenerContainer defaultMessageListenerContainer = this.context.getBean(DefaultJmsListenerContainerFactory.class).createListenerContainer(mock(JmsListenerEndpoint.class));
    assertThat(jmsTemplate.isPubSubDomain()).isTrue();
    assertThat(defaultMessageListenerContainer.isPubSubDomain()).isTrue();
}
Also used : DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) JmsListenerEndpoint(org.springframework.jms.config.JmsListenerEndpoint) DefaultJmsListenerContainerFactory(org.springframework.jms.config.DefaultJmsListenerContainerFactory) JmsTemplate(org.springframework.jms.core.JmsTemplate) Test(org.junit.Test)

Example 15 with JmsTemplate

use of org.springframework.jms.core.JmsTemplate in project spring-boot by spring-projects.

the class JmsAutoConfigurationTests method testJmsTemplateFullCustomization.

@Test
public void testJmsTemplateFullCustomization() {
    load(MessageConvertersConfiguration.class, "spring.jms.template.default-destination=testQueue", "spring.jms.template.delivery-delay=500", "spring.jms.template.delivery-mode=non-persistent", "spring.jms.template.priority=6", "spring.jms.template.time-to-live=6000", "spring.jms.template.receive-timeout=2000");
    JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
    assertThat(jmsTemplate.getMessageConverter()).isSameAs(this.context.getBean("myMessageConverter"));
    assertThat(jmsTemplate.isPubSubDomain()).isFalse();
    assertThat(jmsTemplate.getDefaultDestinationName()).isEqualTo("testQueue");
    assertThat(jmsTemplate.getDeliveryDelay()).isEqualTo(500);
    assertThat(jmsTemplate.getDeliveryMode()).isEqualTo(1);
    assertThat(jmsTemplate.getPriority()).isEqualTo(6);
    assertThat(jmsTemplate.getTimeToLive()).isEqualTo(6000);
    assertThat(jmsTemplate.isExplicitQosEnabled()).isTrue();
    assertThat(jmsTemplate.getReceiveTimeout()).isEqualTo(2000);
}
Also used : JmsTemplate(org.springframework.jms.core.JmsTemplate) Test(org.junit.Test)

Aggregations

JmsTemplate (org.springframework.jms.core.JmsTemplate)45 Test (org.junit.Test)30 ConnectionFactory (javax.jms.ConnectionFactory)12 Session (javax.jms.Session)9 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)8 Connection (javax.jms.Connection)7 TransactionStatus (org.springframework.transaction.TransactionStatus)7 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)7 Bean (org.springframework.context.annotation.Bean)5 Destination (javax.jms.Destination)4 TextMessage (javax.jms.TextMessage)4 CamelContext (org.apache.camel.CamelContext)4 SessionCallback (org.springframework.jms.core.SessionCallback)4 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)4 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)4 JMSException (javax.jms.JMSException)3 Message (javax.jms.Message)3 PooledConnectionFactory (org.apache.activemq.pool.PooledConnectionFactory)3 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)3 JmsOperations (org.springframework.jms.core.JmsOperations)3