com.healthy.common.websocket.config.LocalMessageDistributorConfiguration Maven / Gradle / Ivy
package com.healthy.common.websocket.config;
import com.healthy.common.websocket.WebSocketProperties;
import com.healthy.common.websocket.constant.MessageDistributorTypeConstants;
import com.healthy.common.websocket.distribute.LocalMessageDistributor;
import com.healthy.common.websocket.distribute.MessageDistributor;
import com.healthy.common.websocket.session.WebSocketSessionStore;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* 本地的消息分发器配置
*
* @author xm.z
*/
@ConditionalOnProperty(prefix = WebSocketProperties.PREFIX, name = "message-distributor",
havingValue = MessageDistributorTypeConstants.LOCAL, matchIfMissing = true)
@Configuration(proxyBeanMethods = false)
@RequiredArgsConstructor
public class LocalMessageDistributorConfiguration {
private final WebSocketSessionStore webSocketSessionStore;
/**
* 本地基于内存的消息分发,不支持集群
* @return LocalMessageDistributor
*/
@Bean
@ConditionalOnMissingBean(MessageDistributor.class)
public LocalMessageDistributor messageDistributor() {
return new LocalMessageDistributor(webSocketSessionStore);
}
}