Search in sources :

Example 1 with SubscribableJmsChannel

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

the class JmsChannelFactoryBean method createInstance.

@Override
protected AbstractJmsChannel createInstance() throws Exception {
    this.initializeJmsTemplate();
    if (this.messageDriven) {
        this.container = createContainer();
        SubscribableJmsChannel subscribableJmsChannel = new SubscribableJmsChannel(this.container, this.jmsTemplate);
        subscribableJmsChannel.setMaxSubscribers(this.maxSubscribers);
        this.channel = subscribableJmsChannel;
    } else {
        Assert.isTrue(!Boolean.TRUE.equals(this.pubSubDomain), "A JMS Topic-backed 'publish-subscribe-channel' must be message-driven.");
        PollableJmsChannel pollableJmschannel = new PollableJmsChannel(this.jmsTemplate);
        if (this.messageSelector != null) {
            pollableJmschannel.setMessageSelector(this.messageSelector);
        }
        this.channel = pollableJmschannel;
    }
    if (!CollectionUtils.isEmpty(this.interceptors)) {
        this.channel.setInterceptors(this.interceptors);
    }
    this.channel.setBeanName(this.beanName);
    if (this.getBeanFactory() != null) {
        this.channel.setBeanFactory(this.getBeanFactory());
    }
    this.channel.afterPropertiesSet();
    return this.channel;
}
Also used : SubscribableJmsChannel(org.springframework.integration.jms.SubscribableJmsChannel) PollableJmsChannel(org.springframework.integration.jms.PollableJmsChannel)

Example 2 with SubscribableJmsChannel

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

the class JmsChannelParserTests method channelWithConcurrencySettings.

@Test
public void channelWithConcurrencySettings() {
    assertEquals(SubscribableJmsChannel.class, channelWithConcurrencySettings.getClass());
    SubscribableJmsChannel channel = (SubscribableJmsChannel) channelWithConcurrencySettings;
    DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
    DefaultMessageListenerContainer container = (DefaultMessageListenerContainer) accessor.getPropertyValue("container");
    assertEquals(11, container.getConcurrentConsumers());
    assertEquals(55, container.getMaxConcurrentConsumers());
}
Also used : DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) SubscribableJmsChannel(org.springframework.integration.jms.SubscribableJmsChannel) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 3 with SubscribableJmsChannel

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

the class JmsChannelParserTests method queueNameWithResolverChannel.

@Test
public void queueNameWithResolverChannel() {
    assertEquals(SubscribableJmsChannel.class, queueNameWithResolverChannel.getClass());
    SubscribableJmsChannel channel = (SubscribableJmsChannel) queueNameWithResolverChannel;
    DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
    JmsTemplate jmsTemplate = (JmsTemplate) accessor.getPropertyValue("jmsTemplate");
    AbstractMessageListenerContainer container = (AbstractMessageListenerContainer) accessor.getPropertyValue("container");
    assertEquals("foo", jmsTemplate.getDefaultDestinationName());
    assertEquals("foo", container.getDestinationName());
}
Also used : SubscribableJmsChannel(org.springframework.integration.jms.SubscribableJmsChannel) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) JmsTemplate(org.springframework.jms.core.JmsTemplate) AbstractMessageListenerContainer(org.springframework.jms.listener.AbstractMessageListenerContainer) Test(org.junit.Test)

Example 4 with SubscribableJmsChannel

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

the class JmsChannelParserTests method queueReferenceChannel.

@Test
public void queueReferenceChannel() {
    assertEquals(SubscribableJmsChannel.class, queueReferenceChannel.getClass());
    SubscribableJmsChannel channel = (SubscribableJmsChannel) queueReferenceChannel;
    DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
    JmsTemplate jmsTemplate = (JmsTemplate) accessor.getPropertyValue("jmsTemplate");
    AbstractMessageListenerContainer container = (AbstractMessageListenerContainer) accessor.getPropertyValue("container");
    assertEquals(queue, jmsTemplate.getDefaultDestination());
    assertEquals(queue, container.getDestination());
    assertEquals(true, TestUtils.getPropertyValue(jmsTemplate, "explicitQosEnabled"));
    assertEquals(DeliveryMode.PERSISTENT, TestUtils.getPropertyValue(jmsTemplate, "deliveryMode"));
    assertEquals(123L, TestUtils.getPropertyValue(jmsTemplate, "timeToLive"));
    assertEquals(12, TestUtils.getPropertyValue(jmsTemplate, "priority"));
    assertEquals(Integer.MAX_VALUE, TestUtils.getPropertyValue(TestUtils.getPropertyValue(channel, "dispatcher"), "maxSubscribers", Integer.class).intValue());
}
Also used : SubscribableJmsChannel(org.springframework.integration.jms.SubscribableJmsChannel) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) JmsTemplate(org.springframework.jms.core.JmsTemplate) AbstractMessageListenerContainer(org.springframework.jms.listener.AbstractMessageListenerContainer) Test(org.junit.Test)

Example 5 with SubscribableJmsChannel

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

the class JmsChannelHistoryTests method testMessageHistory.

@Test
public void testMessageHistory() throws Exception {
    AbstractMessageListenerContainer mlContainer = mock(AbstractMessageListenerContainer.class);
    JmsTemplate template = mock(JmsTemplate.class);
    SubscribableJmsChannel channel = new SubscribableJmsChannel(mlContainer, template);
    channel.setShouldTrack(true);
    channel.setBeanName("jmsChannel");
    Message<String> message = new GenericMessage<String>("hello");
    doAnswer(invocation -> {
        @SuppressWarnings("unchecked") Message<String> msg = invocation.getArgument(0);
        MessageHistory history = MessageHistory.read(msg);
        assertTrue(history.get(0).contains("jmsChannel"));
        return null;
    }).when(template).convertAndSend(Mockito.any(Message.class));
    channel.send(message);
    verify(template, times(1)).convertAndSend(Mockito.any(Message.class));
    channel.stop();
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageHistory(org.springframework.integration.history.MessageHistory) SubscribableJmsChannel(org.springframework.integration.jms.SubscribableJmsChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) JmsTemplate(org.springframework.jms.core.JmsTemplate) AbstractMessageListenerContainer(org.springframework.jms.listener.AbstractMessageListenerContainer) Test(org.junit.Test)

Aggregations

SubscribableJmsChannel (org.springframework.integration.jms.SubscribableJmsChannel)11 Test (org.junit.Test)10 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)9 JmsTemplate (org.springframework.jms.core.JmsTemplate)7 AbstractMessageListenerContainer (org.springframework.jms.listener.AbstractMessageListenerContainer)7 List (java.util.List)2 ChannelInterceptor (org.springframework.messaging.support.ChannelInterceptor)2 MessageHistory (org.springframework.integration.history.MessageHistory)1 PollableJmsChannel (org.springframework.integration.jms.PollableJmsChannel)1 DefaultMessageListenerContainer (org.springframework.jms.listener.DefaultMessageListenerContainer)1 Message (org.springframework.messaging.Message)1 GenericMessage (org.springframework.messaging.support.GenericMessage)1