145 lines
4.0 KiB
Java
145 lines
4.0 KiB
Java
package com.magamochi.common.config;
|
|
|
|
import com.magamochi.common.model.enumeration.ContentType;
|
|
import org.springframework.amqp.core.Binding;
|
|
import org.springframework.amqp.core.Queue;
|
|
import org.springframework.amqp.core.TopicExchange;
|
|
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
@Configuration
|
|
public class RabbitConfig {
|
|
@Value("${queues.manga-ingest}")
|
|
private String mangaIngestQueue;
|
|
|
|
@Value("${queues.manga-content-ingest}")
|
|
private String mangaContentIngestQueue;
|
|
|
|
@Value("${queues.manga-content-image-ingest}")
|
|
private String mangaContentImageIngestQueue;
|
|
|
|
@Value("${queues.provider-page-ingest}")
|
|
private String providerPageIngestQueue;
|
|
|
|
@Value("${queues.manga-update}")
|
|
private String mangaUpdateQueue;
|
|
|
|
@Value("${queues.manga-cover-update}")
|
|
private String mangaCoverUpdateQueue;
|
|
|
|
@Value("${queues.manga-content-image-update}")
|
|
private String mangaContentImageUpdateQueue;
|
|
|
|
@Value("${queues.image-fetch}")
|
|
private String imageFetchQueue;
|
|
|
|
@Value("${topics.image-updates}")
|
|
private String imageUpdatesTopic;
|
|
|
|
@Value("${routing-key.image-update}")
|
|
private String imageUpdateRoutingKey;
|
|
|
|
@Bean
|
|
public TopicExchange imageUpdatesExchange() {
|
|
return new TopicExchange(imageUpdatesTopic);
|
|
}
|
|
|
|
@Bean
|
|
public Queue imageFetchQueue() {
|
|
return new Queue(imageFetchQueue, false);
|
|
}
|
|
|
|
@Bean
|
|
public Queue mangaUpdateQueue() {
|
|
return new Queue(mangaUpdateQueue, false);
|
|
}
|
|
|
|
@Bean
|
|
public Queue mangaContentImageUpdateQueue() {
|
|
return new Queue(mangaContentImageUpdateQueue, false);
|
|
}
|
|
|
|
@Bean
|
|
public Queue mangaCoverUpdateQueue() {
|
|
return new Queue(mangaCoverUpdateQueue, false);
|
|
}
|
|
|
|
@Bean
|
|
public Binding bindingMangaCoverUpdateQueue(
|
|
Queue mangaCoverUpdateQueue, TopicExchange imageUpdatesExchange) {
|
|
return new Binding(
|
|
mangaCoverUpdateQueue.getName(),
|
|
Binding.DestinationType.QUEUE,
|
|
imageUpdatesExchange.getName(),
|
|
String.format(imageUpdateRoutingKey + ".%s", ContentType.MANGA_COVER.name().toLowerCase()),
|
|
null);
|
|
}
|
|
|
|
@Bean
|
|
public Binding bindingMangaContentImageUpdateQueue(
|
|
Queue mangaContentImageUpdateQueue, TopicExchange imageUpdatesExchange) {
|
|
return new Binding(
|
|
mangaContentImageUpdateQueue.getName(),
|
|
Binding.DestinationType.QUEUE,
|
|
imageUpdatesExchange.getName(),
|
|
String.format(
|
|
imageUpdateRoutingKey + ".%s", ContentType.CONTENT_IMAGE.name().toLowerCase()),
|
|
null);
|
|
}
|
|
|
|
@Bean
|
|
public Queue mangaContentIngestQueue() {
|
|
return new Queue(mangaContentIngestQueue, false);
|
|
}
|
|
|
|
@Bean
|
|
public Queue mangaContentImageIngestQueue() {
|
|
return new Queue(mangaContentImageIngestQueue, false);
|
|
}
|
|
|
|
@Bean
|
|
public Queue mangaIngestQueue() {
|
|
return new Queue(mangaIngestQueue, false);
|
|
}
|
|
|
|
@Bean
|
|
public Queue providerPageIngestQueue() {
|
|
return new Queue(providerPageIngestQueue, false);
|
|
}
|
|
|
|
// TODO: remove unused queues
|
|
|
|
@Value("${rabbit-mq.queues.manga-chapter-download}")
|
|
private String mangaChapterDownloadQueue;
|
|
|
|
@Value("${rabbit-mq.queues.manga-follow-update-chapter}")
|
|
private String mangaFollowUpdateChapterQueue;
|
|
|
|
@Bean
|
|
public Queue mangaChapterDownloadQueue() {
|
|
return new Queue(mangaChapterDownloadQueue, false);
|
|
}
|
|
|
|
@Bean
|
|
public Queue mangaFollowUpdateChapterQueue() {
|
|
return new Queue(mangaFollowUpdateChapterQueue, false);
|
|
}
|
|
|
|
@Bean
|
|
public Jackson2JsonMessageConverter messageConverter() {
|
|
return new Jackson2JsonMessageConverter();
|
|
}
|
|
|
|
@Bean
|
|
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
|
|
var rabbitTemplate = new RabbitTemplate(connectionFactory);
|
|
rabbitTemplate.setMessageConverter(messageConverter());
|
|
|
|
return rabbitTemplate;
|
|
}
|
|
}
|