use of org.springframework.integration.jms.config.JmsChannelFactoryBean in project spring-integration by spring-projects.
the class SubscribableJmsChannelTests method dispatcherHasNoSubscribersTopic.
@Test
public void dispatcherHasNoSubscribersTopic() throws Exception {
JmsChannelFactoryBean factoryBean = new JmsChannelFactoryBean(true);
factoryBean.setConnectionFactory(this.connectionFactory);
factoryBean.setDestinationName("noSubscribersTopic");
factoryBean.setBeanName("noSubscribersChannel");
factoryBean.setPubSubDomain(true);
factoryBean.setBeanFactory(mock(BeanFactory.class));
factoryBean.afterPropertiesSet();
SubscribableJmsChannel channel = (SubscribableJmsChannel) factoryBean.getObject();
channel.afterPropertiesSet();
AbstractMessageListenerContainer container = TestUtils.getPropertyValue(channel, "container", AbstractMessageListenerContainer.class);
MessageListener listener = (MessageListener) container.getMessageListener();
List<String> logList = insertMockLoggerInListener(channel);
listener.onMessage(new StubTextMessage("Hello, world!"));
verifyLogReceived(logList);
}
use of org.springframework.integration.jms.config.JmsChannelFactoryBean in project spring-integration by spring-projects.
the class SubscribableJmsChannelTests method dispatcherHasNoSubscribersQueue.
@Test
public void dispatcherHasNoSubscribersQueue() throws Exception {
JmsChannelFactoryBean factoryBean = new JmsChannelFactoryBean(true);
factoryBean.setConnectionFactory(this.connectionFactory);
factoryBean.setDestinationName("noSubscribersQueue");
factoryBean.setBeanName("noSubscribersChannel");
factoryBean.setBeanFactory(mock(BeanFactory.class));
factoryBean.afterPropertiesSet();
SubscribableJmsChannel channel = (SubscribableJmsChannel) factoryBean.getObject();
channel.afterPropertiesSet();
AbstractMessageListenerContainer container = TestUtils.getPropertyValue(channel, "container", AbstractMessageListenerContainer.class);
MessageListener listener = (MessageListener) container.getMessageListener();
try {
listener.onMessage(new StubTextMessage("Hello, world!"));
fail("Exception expected");
} catch (MessageDeliveryException e) {
assertThat(e.getMessage(), containsString("Dispatcher has no subscribers for jms-channel 'noSubscribersChannel'."));
}
}
use of org.springframework.integration.jms.config.JmsChannelFactoryBean in project spring-integration by spring-projects.
the class SubscribableJmsChannelTests method topicName.
@Test
public void topicName() throws Exception {
final CountDownLatch latch = new CountDownLatch(4);
final List<Message<?>> receivedList1 = Collections.synchronizedList(new ArrayList<Message<?>>());
MessageHandler handler1 = message -> {
receivedList1.add(message);
latch.countDown();
};
final List<Message<?>> receivedList2 = Collections.synchronizedList(new ArrayList<Message<?>>());
MessageHandler handler2 = message -> {
receivedList2.add(message);
latch.countDown();
};
JmsChannelFactoryBean factoryBean = new JmsChannelFactoryBean(true);
factoryBean.setConnectionFactory(this.connectionFactory);
factoryBean.setDestinationName("dynamicTopic");
factoryBean.setPubSubDomain(true);
factoryBean.setBeanFactory(mock(BeanFactory.class));
factoryBean.afterPropertiesSet();
SubscribableJmsChannel channel = (SubscribableJmsChannel) factoryBean.getObject();
channel.afterPropertiesSet();
channel.start();
if (!waitUntilRegisteredWithDestination(channel, 10000)) {
fail("Listener failed to subscribe to topic");
}
channel.subscribe(handler1);
channel.subscribe(handler2);
channel.send(new GenericMessage<String>("foo"));
channel.send(new GenericMessage<String>("bar"));
latch.await(TIMEOUT, TimeUnit.MILLISECONDS);
assertEquals(2, receivedList1.size());
assertEquals("foo", receivedList1.get(0).getPayload());
assertEquals("bar", receivedList1.get(1).getPayload());
assertEquals(2, receivedList2.size());
assertEquals("foo", receivedList2.get(0).getPayload());
assertEquals("bar", receivedList2.get(1).getPayload());
channel.stop();
}
use of org.springframework.integration.jms.config.JmsChannelFactoryBean in project spring-integration by spring-projects.
the class SubscribableJmsChannelTests method queueReference.
@Test
public void queueReference() throws Exception {
final CountDownLatch latch = new CountDownLatch(2);
final List<Message<?>> receivedList1 = Collections.synchronizedList(new ArrayList<Message<?>>());
MessageHandler handler1 = message -> {
receivedList1.add(message);
latch.countDown();
};
final List<Message<?>> receivedList2 = Collections.synchronizedList(new ArrayList<Message<?>>());
MessageHandler handler2 = message -> {
receivedList2.add(message);
latch.countDown();
};
JmsChannelFactoryBean factoryBean = new JmsChannelFactoryBean(true);
factoryBean.setConnectionFactory(this.connectionFactory);
factoryBean.setDestination(this.queue);
factoryBean.setBeanFactory(mock(BeanFactory.class));
factoryBean.afterPropertiesSet();
SubscribableJmsChannel channel = (SubscribableJmsChannel) factoryBean.getObject();
channel.afterPropertiesSet();
channel.start();
channel.subscribe(handler1);
channel.subscribe(handler2);
channel.send(new GenericMessage<String>("foo"));
channel.send(new GenericMessage<String>("bar"));
latch.await(TIMEOUT, TimeUnit.MILLISECONDS);
assertEquals(1, receivedList1.size());
assertNotNull(receivedList1.get(0));
assertEquals("foo", receivedList1.get(0).getPayload());
assertEquals(1, receivedList2.size());
assertNotNull(receivedList2.get(0));
assertEquals("bar", receivedList2.get(0).getPayload());
channel.stop();
}
use of org.springframework.integration.jms.config.JmsChannelFactoryBean in project spring-integration by spring-projects.
the class PollableJmsChannelTests method queueName.
@Test
public void queueName() 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);
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());
}
Aggregations