2017-12-01 27 views
0

나는 sprin 클라우드 설정과 RabbitMQ를 연결합니다사용 봄 클라우드 봄 서비스 RabbitMQ와 커넥터 및 시작 게시자 설정 기능

@Bean 
public ConnectionFactory rabbitConnectionFactory() { 
    Map<String, Object> properties = new HashMap<String, Object>(); 
    properties.put("publisherConfirms", true); 
    RabbitConnectionFactoryConfig rabbitConfig = new RabbitConnectionFactoryConfig(properties); 
    return connectionFactory().rabbitConnectionFactory(rabbitConfig); 
} 

삭제 2. rabbitTemplate.setMandatory (사실)와 setConfirmCallback을() :

@Bean 
public RabbitTemplate rabbitTemplate() { 
    RabbitTemplate template = new RabbitTemplate(connectionFactory); 
    template.setMandatory(true); 
    template.setMessageConverter(new Jackson2JsonMessageConverter()); 
    template.setConfirmCallback((correlationData, ack, cause) -> { 
     if (!ack) { 
      System.out.println("send message failed: " + cause + correlationData.toString()); 
     } else { 
      System.out.println("Publisher Confirm" + correlationData.toString()); 
     } 
    }); 
    return template; 
} 

3. publisherConfirm 및 인쇄 로그를 호출하기 위해 대기열에 메시지를 보냅니다.

@Component 
public class TestSender { 

@Autowired 
private RabbitTemplate rabbitTemplate; 

@Scheduled(cron = "0/5 * * * * ? ") 
public void send() { 
    this.rabbitTemplate.convertAndSend(EXCHANGE, "routingkey", "hello world", 
     (Message m) -> { 
      m.getMessageProperties().setHeader("tenant", "aaaaa"); 
      return m; 
     }, new CorrelationData(UUID.randomUUID().toString())); 
    Date date = new Date(); 
    System.out.println("Sender Msg Successfully - " + date); 
} 
} 

게시자 확인이 작동하지 않았습니다. 로그가 인쇄되지 않았습니다. true 또는 false로 설정하면 로그가 없어지지 않습니다.

답변

1

필수 사항은 필수 사항이 아니므로 반품 만하십시오.

어떤 것들은

는 시도 : DEBUG 로깅에

  1. 를 켜고는이 도움을보기 위해; 확인과 관련하여 생성 된 로그가 있습니다.
  2. 는 일부 코드

를 추가합니다.

template.execute(channel -> { 
    system.out.println(channel.getClass()); 
    return null; 
} 

당신이 PublisherCallbackChannelImpl이 표시되지 않는 경우는 다음 구성은 어떤 이유로 작동하지 않았 음을 의미합니다. 다시 DEBUG 로깅은 구성 디버깅에 도움이됩니다.

여전히 문제를 파악할 수없는 경우 문제를 나타내는 최소 수준으로 응용 프로그램을 제거하고 전체 응용 프로그램을 게시하십시오.

+0

로컬에서이 스 니펫을 실행하므로이 문제를 발견했다고 생각합니다. 클라우드 구성의 ConnectionFactory는 사용되지 않습니다. 따라서 publisherConfrims는 활성화되어 있지 않습니다. 고맙습니다. – Maxwell