2014-11-21 30 views
2

我的應用程序使用Spring Framework 4中包含的Spring消息模塊(具有Spring集成項目的關鍵抽象,如Message,MessageChannel,MessageHandler和其他可用作這樣的消息架構的基礎。)將彈簧反應器集成到現有的Spring Framework 4中STOMP Over WebSocket應用程序

我的應用程序使用WebSocket & STOMP。它與大量的java websocket客戶端保持連接(websocket會話)&其中一個要求是使用akka或反應器。

我想春天反應器RingBufferAsyncTaskExecutor到位ThreadPoolTask​​Executor類的整合clientInboundChannelExecutor & clientOutboundChannelExecutor 以獲得更好的吞吐量。至少我已經確定這種方法是將彈簧反應堆集成到我現有的應用程序中的方法 - 這可能不是正確的方法。

我在看reactor-si-quickstart,因爲它演示瞭如何使用reactor與Spring集成&,因爲Spring Framework 4中的Spring消息傳遞包含Spring Integration項目的關鍵抽象。我認爲這將是最接近的參考。

我對web套接字的工作java配置有以下類聲明 公共類WebSocketConfig擴展WebSocketMessageBrokerConfigurationSupport實現WebSocketMessageBrokerConfigurer。 WebSocketMessageBrokerConfigurationSupport擴展AbstractMessageBrokerConfiguration。

在org.springframework.messaging.simp.config.AbstractMessageBrokerConfiguration我想嘗試配置RingBufferAsyncTaskExecutor到位ThreadPoolTask​​Executor類

@Bean 
public ThreadPoolTaskExecutor clientInboundChannelExecutor() { 
    TaskExecutorRegistration reg = getClientInboundChannelRegistration().getOrCreateTaskExecRegistration(); 
    ThreadPoolTaskExecutor executor = reg.getTaskExecutor(); 
    executor.setThreadNamePrefix("clientInboundChannel-"); 
    return executor; 
} 

的當我嘗試從類型覆蓋WebSocketConfig這種方法「的方法getOrCreateTaskExecRegistration() ChannelRegistration是不可見的」,因爲在 AbstractMessageBrokerConfiguration它的保護....

protected final ChannelRegistration getClientInboundChannelRegistration() { 
    if (this.clientInboundChannelRegistration == null) { 
     ChannelRegistration registration = new ChannelRegistration(); 
     configureClientInboundChannel(registration); 
     this.clientInboundChannelRegistration = registration; 
    } 
    return this.clientInboundChannelRegistration; 
} 

我不完全理解的網搜cketMessageBrokerConfigurationSupport層次結構或我的WebSocketConfig中的WebSocketMessageBrokerConfigurer接口。我只是爲了讓自定義工作而重寫所需的東西。

不確定它是否相關,但我不需要外部代理,因爲我的應用程序目前不會向任何連接的訂戶發送任何數據,並且不太可能出現問題。與守護進程類型的java websocket客戶端的通信是點對點的,但瀏覽器中的web ui websocket確實使用訂閱來獲得實時數據,因此它是一個方便的設置(而不是彈簧整合直接通道)如何設置它 - 仍然不確定它是最高效的應用程序設計。 Spring框架參考文檔中描述的WebSocket消息傳遞體系結構中的STOMP是最全面的方法,因爲這是我的第一個春天項目。

將彈簧反應堆集成到我現有的應用程序中可以提高性能嗎?

或者我應該嘗試使用spring集成來代替,就我所知,這將需要進行很多修改 - 假設Spring Framework 4包含Spring消息傳遞模塊是必需的,這似乎是不合邏輯的春天融合。

如何將彈簧反應器集成到我的標準彈簧框架中4 STOMP Over WebSocket Messaging Architecture?

如果clientInboundChannelExecutor & clientOutboundChannelExecutor到位ThreadPoolTask​​Executor類的配置RingBufferAsyncTaskExecutor是正確的方法,我應該如何去這樣做?

回答

2

其實RingBufferAsyncTaskExecutor不是ThreadPoolTaskExecutor,所以你不能這樣使用它。

您可以簡單地從你的AbstractWebSocketMessageBrokerConfigurer IMPL覆蓋clientInbound(Outbound)Channel豆,只是使用@EnableWebSocketMessageBroker

@Configuration 
@EnableWebSocketMessageBroker 
@EnableReactor 
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer { 

    @autowired 
    Environment reactorEnv; 

    @Override 
    public void registerStompEndpoints(StompEndpointRegistry registry) { 
     registry.addEndpoint("/ws").withSockJS(); 
    } 

    @Override 
    public void configureMessageBroker(MessageBrokerRegistry configurer) { 
     configurer.setApplicationDestinationPrefixes("/app"); 
     configurer.enableSimpleBroker("/topic", "/queue"); 
    } 

    @Bean 
    public AbstractSubscribableChannel clientInboundChannel() { 
     ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(new RingBufferAsyncTaskExecutor(this.reactorEnv)); 
     ChannelRegistration reg = getClientOutboundChannelRegistration(); 
     channel.setInterceptors(reg.getInterceptors()); 
     return channel; 
    } 

} 

而且要注意,請在Spring Integration WebSocket的支持。

順便說一句:請指出我的意見,以鏈接爲reactor-si-quickstart

+0

我發佈此問題後,我發佈了問題https://github.com/reactor/reactor/wiki/AsyncTaskExecutor它似乎是說你應該使用反應堆AsyncTaskExecutor來代替ThreadPoolExecutor以獲得最高的吞吐量 - 必須仔細閱讀所有這些接口如何與某個時間相關。感謝這個例子會給你一個嘗試。鏈接是https://github.com/reactor/reactor-si-quickstart – justify 2014-11-22 08:17:39

相關問題