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");
}
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());
}
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));
}
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());
}
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();
}
Aggregations