AmqpAdmin springboot 메시지 관리 구성 요소의 사용

패키지 com.gong.springbootrabbitmq을; 

수입 com.gong.springbootrabbitmq.bean.Book;
수입 org.junit.After;
수입 org.junit.Test;
수입 org.junit.runner.RunWith;
수입 org.springframework.amqp.core.AmqpAdmin;
수입 org.springframework.amqp.core.Binding;
수입 org.springframework.amqp.core.DirectExchange;
수입 org.springframework.amqp.core.Queue;
수입 org.springframework.amqp.rabbit.core.RabbitTemplate;
수입 org.springframework.beans.factory.annotation.Autowired;
수입 org.springframework.boot.test.context.SpringBootTest;
가져 오기 org.springframework.test.context.junit4.SpringRunner, 

가져 오기 java.util.Arrays;
 가져 오기 되는 java.util.HashMap;
 수입 되고있는 java.util.Map; 

@RunWith (. SpringRunner의 클래스 ) 
@SpringBootTest 
공공  클래스 SpringbootRabbitmqApplicationTests { 

    @Autowired 
    RabbitTemplate rabbitTemplate,    @Autowired 
    amqpAdmin amqpAdmin, 
    @Test 
    
 

    공공  무효 contextLoads () {
         // 포인트 메시지
         // rabbitTemplate.send (교환, routeKey, 메시지) 메시지 헤더와 메시지 내용을 사용자 정의 메시지가 필요
         //rabbitTemplate.convertAndSend (교환, routeKey, 객체) ; 주 들어오는 물체의 요구가 RabbitMQ의 순서로 자동으로 전송되는,
         // 같은 개체의 기본 메시지 본문 
        지도 <문자열, 개체> =지도 새로운 새로운 HashMap의 <> (); 
        map.put ( "MSG"는, "이것은 첫번째 메시지 인" ) 
        map.put ( "데이터"Arrays.asList ( "안녕하세요"(123) 에 해당하는 )); 
        rabbitTemplate.convertAndSend ( "exchange.direct" "gong.news" ,
                 새로운 새 책 ( "왕의 영광", "얼음" )); 

    } 

    @Test 
    공공  무효 testRecieve () { 
        에서 개체 receiveAndConvert는 = rabbitTemplate.receiveAndConvert는 ( "gong.news" );
        에서 System.out.println (receiveAndConvert.getClass ()); 
        에서 System.out.println (에서 receiveAndConvert는); 
    } 

    @Test 
    공공  무효 testMsg () { 
        rabbitTemplate.convertAndSend ( "exchange.fanout", "" ,
                 새 새 책 ( "영광의 왕 ","아이스크림 " )) 
    } 
    
    @Test 
    공개  공극 testAmqpAdmin () {
         // 기 생성 
        (amqpAdmin.declareExchange 새로운 새 amqpAdmin.exchange DirectExchange를 (" " ));
         //는 큐 생성 
        amqpAdmin.declareQueue ( 새로운 새로운 큐 (" amqpAdmin.queue "진실));
        // 绑定 
        amqpAdmin.declareBinding (  ( "amqpAdmin.queue을"바인딩 , Binding.DestinationType.QUEUE,
                 "amqpAdmin.exchange", "amqp.news", 널 (null) )); 
        
    } 
}

 

추천

출처www.cnblogs.com/xiximayou/p/12294764.html