package jnpf.config; import com.baomidou.lock.LockTemplate; import jnpf.consts.ProjectEventConst; import jnpf.handler.ProjectEventMQMessageHandler; import jnpf.handler.ProjectEventMQSender; import jnpf.properties.EventProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.cloud.stream.function.StreamBridge; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.messaging.Message; import java.util.function.Consumer; @Configuration(proxyBeanMethods = false) public class MqAutoConfiguration { @Bean(ProjectEventConst.DEFAULT_TOPIC_NAME) @ConditionalOnProperty(prefix = "event", name = "event-publish-type", havingValue = ProjectEventConst.EVENT_PUBLISH_TYPE_QUEUE) public Consumer> getDefaultMqConsumer(LockTemplate lockTemplate){ return new ProjectEventMQMessageHandler(lockTemplate); } /** * 自定义事件发布渠道为QUEUE */ @Bean @ConditionalOnProperty(prefix = "event", name = "event-publish-type", havingValue = ProjectEventConst.EVENT_PUBLISH_TYPE_QUEUE) public ProjectEventMQSender getProjectEventMQSender(StreamBridge streamBridge, EventProperty eventProperties){ return new ProjectEventMQSender(streamBridge, eventProperties); } /** * 单点用户同步默认空处理器 */ @Bean("ssoEventReceiver") @ConditionalOnMissingBean(name = "ssoEventReceiver") public Consumer> getDefaultSsoConsumer(){ return (message)->{}; } }