longz
2026-04-21 58c73134fb1ce10c1ea1d95ee66d8c89557d7dee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.sinata.appointment.service;
 
import com.sinata.appointment.constants.IntegrationConstant;
import java.util.Map;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.stereotype.Service;
 
@Slf4j
@Service
@RequiredArgsConstructor
public class ExportApplicationService {
 
    private final ObjectProvider<RabbitTemplate> rabbitTemplateProvider;
 
    public String enqueueExport(String exportType, Map<String, Object> criteria) {
        String taskId = UUID.randomUUID().toString().replace("-", "");
        RabbitTemplate rabbitTemplate = rabbitTemplateProvider.getIfAvailable();
        if (rabbitTemplate == null) {
            log.warn(
                    "RabbitMQ not configured, export task accepted locally only taskId={} type={}",
                    taskId,
                    exportType);
            return taskId;
        }
        log.info("Enqueue export taskId={} type={}", taskId, exportType);
        rabbitTemplate.convertAndSend(
                IntegrationConstant.EXPORT_TASK_QUEUE,
                Map.of("taskId", taskId, "type", exportType, "criteria", criteria));
        return taskId;
    }
}