package com.iailab.module.data.controller; import com.iailab.DataWebApplication; import com.iailab.framework.test.core.ut.BaseMockitoUnitTest; import com.iailab.module.data.mq.consumer.ImageMessage; import org.junit.jupiter.api.Test; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.boot.test.context.SpringBootTest; import javax.annotation.Resource; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; /** * @author Houzhongjian * @Description * @createTime 2024年11月06日 */ @SpringBootTest(classes = DataWebApplication.class) public class RabbitMQTest extends BaseMockitoUnitTest { @Resource private RabbitTemplate rabbitTemplate; @Test public void testProducer() { String createTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); Map imageMap = new HashMap<>(); imageMap.put("messageId", "111111111111111"); imageMap.put("image", "8888888888888888888"); imageMap.put("createTime", createTime); rabbitTemplate.convertAndSend(ImageMessage.EXCHANGE, ImageMessage.ROUTING_KEY, imageMap); } }