Search in sources :

Example 1 with SimpleBrokerMessageHandler

use of org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler in project spring-integration by spring-projects.

the class WebSocketInboundChannelAdapter method onInit.

@Override
protected void onInit() {
    super.onInit();
    this.webSocketContainer.setMessageListener(this);
    if (!CollectionUtils.isEmpty(this.messageConverters)) {
        List<MessageConverter> converters = this.messageConverter.getConverters();
        if (this.mergeWithDefaultConverters) {
            ListIterator<MessageConverter> iterator = this.messageConverters.listIterator(this.messageConverters.size());
            while (iterator.hasPrevious()) {
                MessageConverter converter = iterator.previous();
                converters.add(0, converter);
            }
        } else {
            converters.clear();
            converters.addAll(this.messageConverters);
        }
    }
    if (this.server && this.useBroker) {
        Map<String, AbstractBrokerMessageHandler> brokers = getApplicationContext().getBeansOfType(AbstractBrokerMessageHandler.class);
        for (AbstractBrokerMessageHandler broker : brokers.values()) {
            if (broker instanceof SimpleBrokerMessageHandler || broker instanceof StompBrokerRelayMessageHandler) {
                this.brokerHandler = broker;
                break;
            }
        }
        Assert.state(this.brokerHandler != null, "WebSocket Broker Relay isn't present in the application context; " + "it is required when 'useBroker = true'.");
    }
}
Also used : SimpleBrokerMessageHandler(org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler) StompBrokerRelayMessageHandler(org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler) AbstractBrokerMessageHandler(org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler) CompositeMessageConverter(org.springframework.messaging.converter.CompositeMessageConverter) MessageConverter(org.springframework.messaging.converter.MessageConverter) ByteArrayMessageConverter(org.springframework.messaging.converter.ByteArrayMessageConverter) MappingJackson2MessageConverter(org.springframework.messaging.converter.MappingJackson2MessageConverter) StringMessageConverter(org.springframework.messaging.converter.StringMessageConverter)

Example 2 with SimpleBrokerMessageHandler

use of org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler in project spring-framework by spring-projects.

the class WebSocketMessageBrokerConfigurationSupportTests method taskScheduler.

@Test
void taskScheduler() {
    ApplicationContext context = createContext(TestChannelConfig.class, TestConfigurer.class);
    String name = "messageBrokerSockJsTaskScheduler";
    ThreadPoolTaskScheduler taskScheduler = context.getBean(name, ThreadPoolTaskScheduler.class);
    ScheduledThreadPoolExecutor executor = taskScheduler.getScheduledThreadPoolExecutor();
    assertThat(executor.getCorePoolSize()).isEqualTo(Runtime.getRuntime().availableProcessors());
    assertThat(executor.getRemoveOnCancelPolicy()).isTrue();
    SimpleBrokerMessageHandler handler = context.getBean(SimpleBrokerMessageHandler.class);
    assertThat(handler.getTaskScheduler()).isNotNull();
    assertThat(handler.getHeartbeatValue()).containsExactly(15000, 15000);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) SimpleBrokerMessageHandler(org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler) ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) Test(org.junit.jupiter.api.Test)

Example 3 with SimpleBrokerMessageHandler

use of org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler in project spring-framework by spring-projects.

the class SimpleBrokerRegistration method getMessageHandler.

@Override
protected SimpleBrokerMessageHandler getMessageHandler(SubscribableChannel brokerChannel) {
    SimpleBrokerMessageHandler handler = new SimpleBrokerMessageHandler(getClientInboundChannel(), getClientOutboundChannel(), brokerChannel, getDestinationPrefixes());
    if (this.taskScheduler != null) {
        handler.setTaskScheduler(this.taskScheduler);
    }
    if (this.heartbeat != null) {
        handler.setHeartbeatValue(this.heartbeat);
    }
    handler.setSelectorHeaderName(this.selectorHeaderName);
    return handler;
}
Also used : SimpleBrokerMessageHandler(org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler)

Example 4 with SimpleBrokerMessageHandler

use of org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler in project spring-framework by spring-projects.

the class MessageBrokerConfigurationTests method clientOutboundChannelCustomized.

@Test
public void clientOutboundChannelCustomized() {
    ApplicationContext context = loadConfig(CustomConfig.class);
    AbstractSubscribableChannel channel = context.getBean("clientOutboundChannel", AbstractSubscribableChannel.class);
    assertThat(channel.getInterceptors().size()).isEqualTo(4);
    ThreadPoolTaskExecutor taskExecutor = context.getBean("clientOutboundChannelExecutor", ThreadPoolTaskExecutor.class);
    assertThat(taskExecutor.getCorePoolSize()).isEqualTo(21);
    assertThat(taskExecutor.getMaxPoolSize()).isEqualTo(22);
    assertThat(taskExecutor.getKeepAliveSeconds()).isEqualTo(23);
    SimpleBrokerMessageHandler broker = context.getBean("simpleBrokerMessageHandler", SimpleBrokerMessageHandler.class);
    assertThat(broker.isPreservePublishOrder()).isTrue();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) AbstractSubscribableChannel(org.springframework.messaging.support.AbstractSubscribableChannel) SimpleBrokerMessageHandler(org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Test(org.junit.jupiter.api.Test)

Example 5 with SimpleBrokerMessageHandler

use of org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler in project spring-framework by spring-projects.

the class MessageBrokerConfigurationTests method customPathMatcher.

@Test
public void customPathMatcher() {
    ApplicationContext context = loadConfig(CustomConfig.class);
    SimpleBrokerMessageHandler broker = context.getBean(SimpleBrokerMessageHandler.class);
    DefaultSubscriptionRegistry registry = (DefaultSubscriptionRegistry) broker.getSubscriptionRegistry();
    assertThat(registry.getPathMatcher().combine("a", "a")).isEqualTo("a.a");
    PathMatcher pathMatcher = context.getBean(SimpAnnotationMethodMessageHandler.class).getPathMatcher();
    assertThat(pathMatcher.combine("a", "a")).isEqualTo("a.a");
    DefaultUserDestinationResolver resolver = context.getBean(DefaultUserDestinationResolver.class);
    assertThat(resolver).isNotNull();
    assertThat(resolver.isRemoveLeadingSlash()).isFalse();
}
Also used : DefaultSubscriptionRegistry(org.springframework.messaging.simp.broker.DefaultSubscriptionRegistry) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) AntPathMatcher(org.springframework.util.AntPathMatcher) PathMatcher(org.springframework.util.PathMatcher) SimpleBrokerMessageHandler(org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler) SimpAnnotationMethodMessageHandler(org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler) DefaultUserDestinationResolver(org.springframework.messaging.simp.user.DefaultUserDestinationResolver) Test(org.junit.jupiter.api.Test)

Aggregations

SimpleBrokerMessageHandler (org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler)13 Test (org.junit.jupiter.api.Test)6 ApplicationContext (org.springframework.context.ApplicationContext)5 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)5 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)4 DefaultSubscriptionRegistry (org.springframework.messaging.simp.broker.DefaultSubscriptionRegistry)3 SubscriptionRegistry (org.springframework.messaging.simp.broker.SubscriptionRegistry)3 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)2 Nullable (org.springframework.lang.Nullable)2 SimpAnnotationMethodMessageHandler (org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler)2 StompBrokerRelayMessageHandler (org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler)2 DefaultUserDestinationResolver (org.springframework.messaging.simp.user.DefaultUserDestinationResolver)2 ThreadPoolTaskExecutor (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)2 ThreadPoolTaskScheduler (org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler)2 ArrayList (java.util.ArrayList)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1 Bean (org.springframework.context.annotation.Bean)1 MessageHandler (org.springframework.messaging.MessageHandler)1 ByteArrayMessageConverter (org.springframework.messaging.converter.ByteArrayMessageConverter)1