use of org.springframework.integration.jms.config.JmsChannelFactoryBean in project spring-integration by spring-projects.
the class PollableJmsChannelTests method qos.
@Test
public void qos() throws Exception {
this.queue = new ActiveMQQueue("pollableJmsChannelTestQueue");
CachingConnectionFactory ccf = new CachingConnectionFactory(connectionFactory);
ccf.setCacheConsumers(false);
JmsChannelFactoryBean factoryBean = new JmsChannelFactoryBean(false);
factoryBean.setConnectionFactory(ccf);
factoryBean.setDestination(this.queue);
factoryBean.setExplicitQosEnabled(true);
factoryBean.setPriority(5);
int ttl = 10000;
factoryBean.setTimeToLive(ttl);
factoryBean.setDeliveryPersistent(false);
factoryBean.setBeanFactory(mock(BeanFactory.class));
factoryBean.afterPropertiesSet();
PollableJmsChannel channel = (PollableJmsChannel) factoryBean.getObject();
final JmsTemplate receiver = new JmsTemplate(this.connectionFactory);
boolean sent1 = channel.send(new GenericMessage<String>("foo"));
assertTrue(sent1);
final AtomicReference<javax.jms.Message> message = new AtomicReference<javax.jms.Message>();
final CountDownLatch latch1 = new CountDownLatch(1);
ExecutorService exec = Executors.newSingleThreadExecutor();
exec.execute(() -> {
message.set(receiver.receive(queue));
latch1.countDown();
});
assertTrue(latch1.await(10, TimeUnit.SECONDS));
assertNotNull(message.get());
assertEquals(5, message.get().getJMSPriority());
assertTrue(message.get().getJMSExpiration() <= System.currentTimeMillis() + ttl);
assertTrue(message.get().toString().contains("persistent = false"));
message.set(null);
final CountDownLatch latch2 = new CountDownLatch(1);
boolean sent2 = channel.send(MessageBuilder.withPayload("foo").setPriority(6).build());
assertTrue(sent2);
exec.execute(() -> {
message.set(receiver.receive(queue));
latch2.countDown();
});
assertTrue(latch2.await(10, TimeUnit.SECONDS));
assertNotNull(message.get());
assertEquals(6, message.get().getJMSPriority());
assertTrue(message.get().getJMSExpiration() <= System.currentTimeMillis() + ttl);
assertTrue(message.get().toString().contains("persistent = false"));
exec.shutdownNow();
}
use of org.springframework.integration.jms.config.JmsChannelFactoryBean in project spring-integration by spring-projects.
the class PollableJmsChannelTests method queueNameWithTruePreReceiveInterceptors.
@Test
public void queueNameWithTruePreReceiveInterceptors() 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(true));
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);
assertNotNull(result1);
verify(interceptor, times(1)).preReceive(Mockito.any(MessageChannel.class));
verify(interceptor, times(1)).postReceive(Mockito.any(Message.class), Mockito.any(MessageChannel.class));
}
Aggregations