SpringRabbitTracing { public SimpleRabbitListenerContainerFactory decorateSimpleRabbitListenerContainerFactory( SimpleRabbitListenerContainerFactory factory ) { Advice[] chain = factory.getAdviceChain(); TracingRabbitListenerAdvice tracingAdvice = new TracingRabbitListenerAdvice(this); if (chain == null) { factory.setAdviceChain(tracingAdvice); return factory; } for (Advice advice : chain) { if (advice instanceof TracingRabbitListenerAdvice) { return factory; } } Advice[] newChain = new Advice[chain.length + 1]; newChain[0] = tracingAdvice; System.arraycopy(chain, 0, newChain, 1, chain.length); factory.setAdviceChain(newChain); return factory; } SpringRabbitTracing(Builder builder); static SpringRabbitTracing create(Tracing tracing); static SpringRabbitTracing create(MessagingTracing messagingTracing); static Builder newBuilder(Tracing tracing); static Builder newBuilder(MessagingTracing messagingTracing); RabbitTemplate newRabbitTemplate(ConnectionFactory connectionFactory); RabbitTemplate decorateRabbitTemplate(RabbitTemplate rabbitTemplate); SimpleRabbitListenerContainerFactory newSimpleRabbitListenerContainerFactory(
    ConnectionFactory connectionFactory
  ); SimpleRabbitListenerContainerFactory decorateSimpleRabbitListenerContainerFactory(
    SimpleRabbitListenerContainerFactory factory
  );  }
@Test public void decorateSimpleRabbitListenerContainerFactory_adds_by_default() { SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); assertThat(rabbitTracing.decorateSimpleRabbitListenerContainerFactory(factory).getAdviceChain()) .allMatch(advice -> advice instanceof TracingRabbitListenerAdvice); }
@Test public void decorateSimpleRabbitListenerContainerFactory_skips_when_present() { SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); factory.setAdviceChain(new TracingRabbitListenerAdvice(rabbitTracing)); assertThat(rabbitTracing.decorateSimpleRabbitListenerContainerFactory(factory).getAdviceChain()) .hasSize(1); }
@Test public void decorateSimpleRabbitListenerContainerFactory_appends_as_first_when_absent() { SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); factory.setAdviceChain(new CacheInterceptor()); assertThat(rabbitTracing.decorateSimpleRabbitListenerContainerFactory(factory).getAdviceChain()) .hasSize(2) .matches(adviceArray -> adviceArray[0] instanceof TracingRabbitListenerAdvice); }