rabbitMq/src/test/java/com/example/rabbitmq/SendMessageTest.java

28 lines
804 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.example.rabbitmq;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Queue;
@SpringBootTest
public class SendMessageTest {
@Autowired
private RabbitTemplate rabbitTemplate;
// 声明使用JSON否咋在消息队列中会有很长一段字符串
@Test
void testSendObject() {
Map<String, Object> map = new HashMap<>(2);
map.put("name","test");
map.put("age", 21);
rabbitTemplate.convertAndSend("object,queue", map);
}
}