Search in sources :

Example 11 with CachingConnectionFactory

use of org.springframework.jms.connection.CachingConnectionFactory in project spring-integration by spring-projects.

the class SubscribableJmsChannelTests method setup.

@Before
public void setup() {
    ActiveMqTestUtils.prepare();
    ActiveMQConnectionFactory targetConnectionFactory = new ActiveMQConnectionFactory();
    targetConnectionFactory.setBrokerURL("vm://localhost?broker.persistent=false");
    targetConnectionFactory.setTrustAllPackages(true);
    this.connectionFactory = new CachingConnectionFactory(targetConnectionFactory);
    this.topic = new ActiveMQTopic("testTopic");
    this.queue = new ActiveMQQueue("testQueue");
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) CachingConnectionFactory(org.springframework.jms.connection.CachingConnectionFactory) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Before(org.junit.Before)

Example 12 with CachingConnectionFactory

use of org.springframework.jms.connection.CachingConnectionFactory in project spring-integration by spring-projects.

the class PollableJmsChannelTests method queueReference.

@Test
public void queueReference() throws Exception {
    this.queue = new ActiveMQQueue("pollableJmsChannelTestQueue");
    JmsChannelFactoryBean factoryBean = new JmsChannelFactoryBean(false);
    CachingConnectionFactory ccf = new CachingConnectionFactory(this.connectionFactory);
    ccf.setCacheConsumers(false);
    factoryBean.setConnectionFactory(ccf);
    factoryBean.setDestination(this.queue);
    factoryBean.setBeanFactory(mock(BeanFactory.class));
    factoryBean.afterPropertiesSet();
    PollableJmsChannel channel = (PollableJmsChannel) factoryBean.getObject();
    boolean sent1 = channel.send(new GenericMessage<String>("foo"));
    assertTrue(sent1);
    boolean sent2 = channel.send(new GenericMessage<String>("bar"));
    assertTrue(sent2);
    Message<?> result1 = channel.receive(10000);
    assertNotNull(result1);
    assertEquals("foo", result1.getPayload());
    Message<?> result2 = channel.receive(10000);
    assertNotNull(result2);
    assertEquals("bar", result2.getPayload());
}
Also used : JmsChannelFactoryBean(org.springframework.integration.jms.config.JmsChannelFactoryBean) CachingConnectionFactory(org.springframework.jms.connection.CachingConnectionFactory) BeanFactory(org.springframework.beans.factory.BeanFactory) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Test(org.junit.Test)

Example 13 with CachingConnectionFactory

use of org.springframework.jms.connection.CachingConnectionFactory in project spring-integration by spring-projects.

the class PollableJmsChannelTests method queueNameWithFalsePreReceiveInterceptors.

@Test
public void queueNameWithFalsePreReceiveInterceptors() throws Exception {
    JmsChannelFactoryBean factoryBean = new JmsChannelFactoryBean(false);
    CachingConnectionFactory ccf = new CachingConnectionFactory(this.connectionFactory);
    ccf.setCacheConsumers(false);
    factoryBean.setConnectionFactory(ccf);
    factoryBean.setDestinationName("someDynamicQueue");
    factoryBean.setPubSubDomain(false);
    List<ChannelInterceptor> interceptorList = new ArrayList<ChannelInterceptor>();
    ChannelInterceptor interceptor = spy(new SampleInterceptor(false));
    interceptorList.add(interceptor);
    factoryBean.setInterceptors(interceptorList);
    factoryBean.setBeanFactory(mock(BeanFactory.class));
    factoryBean.afterPropertiesSet();
    PollableJmsChannel channel = (PollableJmsChannel) factoryBean.getObject();
    boolean sent1 = channel.send(new GenericMessage<String>("foo"));
    assertTrue(sent1);
    Message<?> result1 = channel.receive(10000);
    assertNull(result1);
    verify(interceptor, times(1)).preReceive(Mockito.any(MessageChannel.class));
    verify(interceptor, times(0)).postReceive(Mockito.any(Message.class), Mockito.any(MessageChannel.class));
}
Also used : Message(org.springframework.messaging.Message) TextMessage(javax.jms.TextMessage) GenericMessage(org.springframework.messaging.support.GenericMessage) ChannelInterceptor(org.springframework.messaging.support.ChannelInterceptor) ArrayList(java.util.ArrayList) JmsChannelFactoryBean(org.springframework.integration.jms.config.JmsChannelFactoryBean) MessageChannel(org.springframework.messaging.MessageChannel) CachingConnectionFactory(org.springframework.jms.connection.CachingConnectionFactory) BeanFactory(org.springframework.beans.factory.BeanFactory) Test(org.junit.Test)

Example 14 with CachingConnectionFactory

use of org.springframework.jms.connection.CachingConnectionFactory in project spring-integration by spring-projects.

the class PollableJmsChannelTests method selector.

@Test
public void selector() throws Exception {
    this.queue = new ActiveMQQueue("pollableJmsChannelSelectorTestQueue");
    JmsChannelFactoryBean factoryBean = new JmsChannelFactoryBean(false);
    CachingConnectionFactory ccf = new CachingConnectionFactory(this.connectionFactory);
    ccf.setCacheConsumers(false);
    factoryBean.setConnectionFactory(ccf);
    factoryBean.setDestination(this.queue);
    factoryBean.setMessageSelector("baz='qux'");
    factoryBean.setBeanFactory(mock(BeanFactory.class));
    factoryBean.afterPropertiesSet();
    PollableJmsChannel channel = (PollableJmsChannel) factoryBean.getObject();
    boolean sent1 = channel.send(new GenericMessage<String>("foo"));
    assertTrue(sent1);
    Message<?> result1 = channel.receive(100);
    assertNull(result1);
    JmsTemplate jmsTemplate = new JmsTemplate(this.connectionFactory);
    jmsTemplate.setDefaultDestinationName("pollableJmsChannelSelectorTestQueue");
    jmsTemplate.send(session -> {
        TextMessage message = session.createTextMessage("bar");
        message.setStringProperty("baz", "qux");
        return message;
    });
    Message<?> result2 = channel.receive(10000);
    assertNotNull(result2);
    assertEquals("bar", result2.getPayload());
}
Also used : JmsChannelFactoryBean(org.springframework.integration.jms.config.JmsChannelFactoryBean) CachingConnectionFactory(org.springframework.jms.connection.CachingConnectionFactory) BeanFactory(org.springframework.beans.factory.BeanFactory) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) JmsTemplate(org.springframework.jms.core.JmsTemplate) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 15 with CachingConnectionFactory

use of org.springframework.jms.connection.CachingConnectionFactory in project spring-boot by spring-projects.

the class JmsAutoConfigurationTests method testDefaultJmsConfiguration.

private void testDefaultJmsConfiguration(AssertableApplicationContext loaded) {
    assertThat(loaded).hasSingleBean(ConnectionFactory.class);
    assertThat(loaded).hasSingleBean(CachingConnectionFactory.class);
    CachingConnectionFactory factory = loaded.getBean(CachingConnectionFactory.class);
    assertThat(factory.getTargetConnectionFactory()).isInstanceOf(ActiveMQConnectionFactory.class);
    JmsTemplate jmsTemplate = loaded.getBean(JmsTemplate.class);
    JmsMessagingTemplate messagingTemplate = loaded.getBean(JmsMessagingTemplate.class);
    assertThat(factory).isEqualTo(jmsTemplate.getConnectionFactory());
    assertThat(messagingTemplate.getJmsTemplate()).isEqualTo(jmsTemplate);
    assertThat(getBrokerUrl(factory)).startsWith("vm://");
    assertThat(loaded.containsBean("jmsListenerContainerFactory")).isTrue();
}
Also used : JmsMessagingTemplate(org.springframework.jms.core.JmsMessagingTemplate) CachingConnectionFactory(org.springframework.jms.connection.CachingConnectionFactory) JmsTemplate(org.springframework.jms.core.JmsTemplate)

Aggregations

CachingConnectionFactory (org.springframework.jms.connection.CachingConnectionFactory)32 Test (org.junit.Test)21 JmsTemplate (org.springframework.jms.core.JmsTemplate)20 TextMessage (javax.jms.TextMessage)15 Message (javax.jms.Message)11 GenericMessage (org.springframework.messaging.support.GenericMessage)11 MessageCreator (org.springframework.jms.core.MessageCreator)10 BeanFactory (org.springframework.beans.factory.BeanFactory)9 Destination (javax.jms.Destination)8 ComponentLog (org.apache.nifi.logging.ComponentLog)7 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)6 JmsChannelFactoryBean (org.springframework.integration.jms.config.JmsChannelFactoryBean)6 ConnectionFactory (javax.jms.ConnectionFactory)5 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)5 ArrayList (java.util.ArrayList)4 ExecutorService (java.util.concurrent.ExecutorService)4 Session (javax.jms.Session)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 Executors (java.util.concurrent.Executors)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3