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 rabbitTemplateProvider; public String enqueueExport(String exportType, Map 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; } }