MqAutoConfiguration.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package jnpf.config;
  2. import com.baomidou.lock.LockTemplate;
  3. import jnpf.consts.ProjectEventConst;
  4. import jnpf.handler.ProjectEventMQMessageHandler;
  5. import jnpf.handler.ProjectEventMQSender;
  6. import jnpf.properties.EventProperty;
  7. import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
  8. import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  9. import org.springframework.cloud.stream.function.StreamBridge;
  10. import org.springframework.context.annotation.Bean;
  11. import org.springframework.context.annotation.Configuration;
  12. import org.springframework.messaging.Message;
  13. import java.util.function.Consumer;
  14. @Configuration(proxyBeanMethods = false)
  15. public class MqAutoConfiguration {
  16. @Bean(ProjectEventConst.DEFAULT_TOPIC_NAME)
  17. @ConditionalOnProperty(prefix = "event", name = "event-publish-type", havingValue = ProjectEventConst.EVENT_PUBLISH_TYPE_QUEUE)
  18. public Consumer<Message<?>> getDefaultMqConsumer(LockTemplate lockTemplate){
  19. return new ProjectEventMQMessageHandler(lockTemplate);
  20. }
  21. /**
  22. * 自定义事件发布渠道为QUEUE
  23. */
  24. @Bean
  25. @ConditionalOnProperty(prefix = "event", name = "event-publish-type", havingValue = ProjectEventConst.EVENT_PUBLISH_TYPE_QUEUE)
  26. public ProjectEventMQSender getProjectEventMQSender(StreamBridge streamBridge, EventProperty eventProperties){
  27. return new ProjectEventMQSender(streamBridge, eventProperties);
  28. }
  29. /**
  30. * 单点用户同步默认空处理器
  31. */
  32. @Bean("ssoEventReceiver")
  33. @ConditionalOnMissingBean(name = "ssoEventReceiver")
  34. public Consumer<Message<?>> getDefaultSsoConsumer(){
  35. return (message)->{};
  36. }
  37. }