All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.herodotus.stirrup.message.websocket.servlet.properties.StompProperties Maven / Gradle / Ivy

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2020-2030 郑庚伟 ZHENGGENGWEI (码匠君),  Licensed under the AGPL License
 *
 * This file is part of Herodotus Stirrup.
 *
 * Herodotus Stirrup is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Herodotus Stirrup is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see .
 */

package cn.herodotus.stirrup.message.websocket.servlet.properties;

import cn.herodotus.stirrup.core.definition.constants.HerodotusHeaders;
import cn.herodotus.stirrup.core.definition.constants.SymbolConstants;
import cn.herodotus.stirrup.message.core.constants.MessageConstants;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.Collections;
import java.util.List;

/**
 * 

Description: Web Socket 配置

* * @author : gengwei.zheng * @date : 2021/10/24 18:38 */ @ConfigurationProperties(prefix = MessageConstants.PROPERTY_MESSAGE_STOMP) public class StompProperties { /** * 客户端尝试连接端点 */ private String endpoint = "stomp/ws"; /** * 全局使用的消息前缀 */ private List applicationDestinationPrefixes = Collections.singletonList("/app"); /** * 点对点使用的订阅前缀(客户端订阅路径上会体现出来),不设置的话,默认也是/user/ */ private String userDestinationPrefix = "/user"; /** * 集群模式下,信息同步消息队列Topic */ private String topic = "ws"; /** * 请求中传递的用户身份标识属性名 */ private String principalHeader = HerodotusHeaders.X_HERODOTUS_OPEN_ID; private String format(String endpoint) { if (StringUtils.isNotBlank(endpoint) && !StringUtils.startsWith(endpoint, SymbolConstants.FORWARD_SLASH)) { return SymbolConstants.FORWARD_SLASH + endpoint; } else { return endpoint; } } public String getEndpoint() { return format(endpoint); } public void setEndpoint(String endpoint) { this.endpoint = endpoint; } public List getApplicationDestinationPrefixes() { return applicationDestinationPrefixes; } public void setApplicationDestinationPrefixes(List applicationDestinationPrefixes) { this.applicationDestinationPrefixes = applicationDestinationPrefixes; } public String[] getApplicationPrefixes() { List prefixes = this.getApplicationDestinationPrefixes(); if (CollectionUtils.isNotEmpty(prefixes)) { List wellFormed = prefixes.stream().map(this::format).toList(); String[] result = new String[wellFormed.size()]; return wellFormed.toArray(result); } else { return new String[]{}; } } public String getUserDestinationPrefix() { return format(userDestinationPrefix); } public void setUserDestinationPrefix(String userDestinationPrefix) { this.userDestinationPrefix = userDestinationPrefix; } public String getTopic() { return topic; } public void setTopic(String topic) { this.topic = topic; } public String getPrincipalHeader() { return principalHeader; } public void setPrincipalHeader(String principalHeader) { this.principalHeader = principalHeader; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy