Java Code Examples for org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory#setAdviceChain()

The following examples show how to use org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory#setAdviceChain() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RabbitMQRouterConfig.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
@Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(ConnectionFactory connectionFactory) {
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    factory.setConnectionFactory(connectionFactory);
    factory.setAcknowledgeMode(AcknowledgeMode.AUTO);
    factory.setConcurrentConsumers(1);
    factory.setMaxConcurrentConsumers(20);

    Advice[] adviceChain = new Advice[] { interceptor() };
    factory.setAdviceChain(adviceChain);
    return factory;
}
 
Example 2
Source File: RabbitConfiguration.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public SimpleRabbitListenerContainerFactory retryContainerFactory(ConnectionFactory connectionFactory, RetryOperationsInterceptor retryInterceptor) {
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    factory.setConnectionFactory(connectionFactory);

    Advice[] adviceChain = { retryInterceptor };
    factory.setAdviceChain(adviceChain);

    return factory;
}
 
Example 3
Source File: RabbitConfiguration.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public SimpleRabbitListenerContainerFactory retryQueuesContainerFactory(ConnectionFactory connectionFactory, RetryQueuesInterceptor retryInterceptor) {
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    factory.setConnectionFactory(connectionFactory);

    Advice[] adviceChain = { retryInterceptor };
    factory.setAdviceChain(adviceChain);

    return factory;
}
 
Example 4
Source File: SpringRabbitTracing.java    From brave with Apache License 2.0 5 votes vote down vote up
/** Creates an instrumented {@linkplain SimpleRabbitListenerContainerFactory} */
public SimpleRabbitListenerContainerFactory newSimpleRabbitListenerContainerFactory(
  ConnectionFactory connectionFactory
) {
  SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
  factory.setConnectionFactory(connectionFactory);
  factory.setAdviceChain(new TracingRabbitListenerAdvice(this));
  return factory;
}
 
Example 5
Source File: SpringRabbitTracing.java    From brave with Apache License 2.0 5 votes vote down vote up
/** Instruments an existing {@linkplain SimpleRabbitListenerContainerFactory} */
public SimpleRabbitListenerContainerFactory decorateSimpleRabbitListenerContainerFactory(
  SimpleRabbitListenerContainerFactory factory
) {
  Advice[] chain = factory.getAdviceChain();

  TracingRabbitListenerAdvice tracingAdvice = new TracingRabbitListenerAdvice(this);
  // If there are no existing advice, return only the tracing one
  if (chain == null) {
    factory.setAdviceChain(tracingAdvice);
    return factory;
  }

  // If there is an existing tracing advice return
  for (Advice advice : chain) {
    if (advice instanceof TracingRabbitListenerAdvice) {
      return factory;
    }
  }

  // Otherwise, add ours and return
  Advice[] newChain = new Advice[chain.length + 1];
  newChain[0] = tracingAdvice;
  System.arraycopy(chain, 0, newChain, 1, chain.length);
  factory.setAdviceChain(newChain);
  return factory;
}
 
Example 6
Source File: SpringRabbitTracingTest.java    From brave with Apache License 2.0 5 votes vote down vote up
@Test public void decorateSimpleRabbitListenerContainerFactory_skips_when_present() {
  SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
  factory.setAdviceChain(new TracingRabbitListenerAdvice(rabbitTracing));

  assertThat(rabbitTracing.decorateSimpleRabbitListenerContainerFactory(factory).getAdviceChain())
    .hasSize(1);
}
 
Example 7
Source File: SpringRabbitTracingTest.java    From brave with Apache License 2.0 5 votes vote down vote up
@Test public void decorateSimpleRabbitListenerContainerFactory_appends_as_first_when_absent() {
  SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
  factory.setAdviceChain(new CacheInterceptor());

  // the order of advices is important for the downstream interceptor to see the tracing context
  assertThat(rabbitTracing.decorateSimpleRabbitListenerContainerFactory(factory).getAdviceChain())
    .hasSize(2)
    .matches(adviceArray -> adviceArray[0] instanceof TracingRabbitListenerAdvice);
}