springboot与mq(2)

 <dependency>
            <groupId>org.springframework.amqp</groupId>
            <artifactId>spring-rabbit</artifactId>
            <version>2.1.6.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-messaging</artifactId>
            <version>5.1.7.RELEASE</version>
        </dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>5.7.1</version>
</dependency>

  

@Autowired
RabbitTemplate rabbitTemplate;
private final static String Exchange_NAME ="hello";
String routingKey ="goods.delete";
private final static String QUEUE_NAME ="hello1";
@Test
public void send() throws Exception{
   Map<String,Object> map = new HashMap<>();
   map.put("1","haha");
    rabbitTemplate.convertAndSend("hello","goods.delete",map);
}
@Test
public void receive(){
    rabbitTemplate.receiveAndConvert(QUEUE_NAME);
}
spring:
  rabbitmq:
    host: 127.0.0.1
    username: mm
    password: 123
    port: 5672
    virtual-host: /test

猜你喜欢

转载自www.cnblogs.com/mm163/p/10981109.html
MQ
今日推荐