/* * Copyright 2020 Sonu Kumar * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.github.sonus21.rqueue.spring.boot; import com.github.sonus21.rqueue.config.RqueueConfig; import com.github.sonus21.rqueue.config.RqueueListenerBaseConfig; import com.github.sonus21.rqueue.core.RqueueMessageSender; import com.github.sonus21.rqueue.core.RqueueMessageSenderImpl; import com.github.sonus21.rqueue.core.RqueueMessageTemplate; import com.github.sonus21.rqueue.listener.RqueueMessageHandler; import com.github.sonus21.rqueue.listener.RqueueMessageListenerContainer; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.DependsOn; @Configuration @AutoConfigureAfter(RedisAutoConfiguration.class) @ComponentScan("com.github.sonus21.rqueue.web") public class RqueueListenerAutoConfig extends RqueueListenerBaseConfig { @Bean @ConditionalOnMissingBean public RqueueMessageHandler rqueueMessageHandler() { if (simpleRqueueListenerContainerFactory.getRqueueMessageHandler() != null) { return simpleRqueueListenerContainerFactory.getRqueueMessageHandler(); } if (simpleRqueueListenerContainerFactory.getMessageConverters() != null) { return new RqueueMessageHandler(simpleRqueueListenerContainerFactory.getMessageConverters()); } return new RqueueMessageHandler(); } @Bean @DependsOn("rqueueConfig") @ConditionalOnMissingBean public RqueueMessageListenerContainer rqueueMessageListenerContainer( RqueueMessageHandler rqueueMessageHandler) { if (simpleRqueueListenerContainerFactory.getRqueueMessageHandler() == null) { simpleRqueueListenerContainerFactory.setRqueueMessageHandler(rqueueMessageHandler); } return simpleRqueueListenerContainerFactory.createMessageListenerContainer(); } @Bean @ConditionalOnMissingBean public RqueueMessageTemplate rqueueMessageTemplate(RqueueConfig rqueueConfig) { return getMessageTemplate(rqueueConfig); } @Bean @ConditionalOnMissingBean public RqueueMessageSender rqueueMessageSender(RqueueMessageTemplate rqueueMessageTemplate) { if (simpleRqueueListenerContainerFactory.getMessageConverters() != null) { return new RqueueMessageSenderImpl( rqueueMessageTemplate, simpleRqueueListenerContainerFactory.getMessageConverters()); } return new RqueueMessageSenderImpl(rqueueMessageTemplate); } }