Example usage for org.springframework.integration.amqp.outbound AmqpOutboundEndpoint setBeanFactory

List of usage examples for org.springframework.integration.amqp.outbound AmqpOutboundEndpoint setBeanFactory

Introduction

In this page you can find the example usage for org.springframework.integration.amqp.outbound AmqpOutboundEndpoint setBeanFactory.

Prototype

@Override
    public void setBeanFactory(BeanFactory beanFactory) 

Source Link

Usage

From source file:org.springframework.integration.amqp.config.AmqpOutboundChannelAdapterParserTests.java

@Test
public void testInt3430FailForNotLazyConnect() {
    RabbitTemplate amqpTemplate = spy(new RabbitTemplate());
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    RuntimeException toBeThrown = new RuntimeException("Test Connection Exception");
    doThrow(toBeThrown).when(connectionFactory).createConnection();
    when(amqpTemplate.getConnectionFactory()).thenReturn(connectionFactory);
    AmqpOutboundEndpoint handler = new AmqpOutboundEndpoint(amqpTemplate);
    Log logger = spy(TestUtils.getPropertyValue(handler, "logger", Log.class));
    new DirectFieldAccessor(handler).setPropertyValue("logger", logger);
    doAnswer(new DoesNothing()).when(logger).error("Failed to eagerly establish the connection.", toBeThrown);
    ApplicationContext context = mock(ApplicationContext.class);
    handler.setApplicationContext(context);
    handler.setBeanFactory(context);
    handler.afterPropertiesSet();//from  ww w .  jav  a  2s .c  o  m
    handler.start();
    handler.stop();
    verify(logger, never()).error(anyString(), any(RuntimeException.class));
    handler.setLazyConnect(false);
    handler.start();
    verify(logger).error("Failed to eagerly establish the connection.", toBeThrown);
    handler.stop();
}

From source file:org.springframework.integration.x.rabbit.RabbitMessageBus.java

@Override
public void bindReplier(String name, MessageChannel requests, MessageChannel replies) {
    if (logger.isInfoEnabled()) {
        logger.info("binding replier: " + name);
    }/* w ww  . jav  a 2 s  .c  om*/
    Queue requestQueue = new Queue(name + ".requests");
    this.rabbitAdmin.declareQueue(requestQueue);
    this.doRegisterConsumer(name, requests, requestQueue);

    AmqpOutboundEndpoint replyQueue = new AmqpOutboundEndpoint(rabbitTemplate);
    replyQueue.setBeanFactory(new DefaultListableBeanFactory());
    replyQueue.setRoutingKeyExpression("headers['" + AmqpHeaders.REPLY_TO + "']");
    replyQueue.setHeaderMapper(mapper);
    replyQueue.afterPropertiesSet();
    doRegisterProducer(name, replies, replyQueue);
}

From source file:org.springframework.xd.dirt.integration.rabbit.RabbitMessageBus.java

private void configureOutboundHandler(AmqpOutboundEndpoint handler, RabbitPropertiesAccessor properties) {
    DefaultAmqpHeaderMapper mapper = new DefaultAmqpHeaderMapper();
    mapper.setRequestHeaderNames(properties.getRequestHeaderPattens(this.defaultRequestHeaderPatterns));
    mapper.setReplyHeaderNames(properties.getReplyHeaderPattens(this.defaultReplyHeaderPatterns));
    handler.setHeaderMapper(mapper);//w ww. j  a  va  2 s  .c  om
    handler.setDefaultDeliveryMode(properties.getDeliveryMode(this.defaultDefaultDeliveryMode));
    handler.setBeanFactory(this.getBeanFactory());
    handler.afterPropertiesSet();
}

From source file:org.springframework.xd.dirt.integration.rabbit.RabbitMessageBus.java

@Override
public void bindRequestor(String name, MessageChannel requests, MessageChannel replies, Properties properties) {
    if (logger.isInfoEnabled()) {
        logger.info("binding requestor: " + name);
    }/* ww w  . j  a  v  a 2s  . c  om*/
    validateProducerProperties(name, properties, SUPPORTED_REQUESTING_PRODUCER_PROPERTIES);
    Assert.isInstanceOf(SubscribableChannel.class, requests);
    RabbitPropertiesAccessor accessor = new RabbitPropertiesAccessor(properties);
    String queueName = name + ".requests";
    AmqpOutboundEndpoint queue = this.buildOutboundEndpoint(queueName, accessor, this.rabbitTemplate);
    queue.setBeanFactory(this.getBeanFactory());

    String replyQueueName = accessor.getPrefix(this.defaultPrefix) + name + ".replies."
            + this.getIdGenerator().generateId();
    this.doRegisterProducer(name, requests, queue, replyQueueName, accessor);
    Queue replyQueue = new Queue(replyQueueName, false, false, true); // auto-delete
    declareQueueIfNotPresent(replyQueue);
    // register with context so it will be redeclared after a connection failure
    this.autoDeclareContext.getBeanFactory().registerSingleton(replyQueueName, replyQueue);
    this.doRegisterConsumer(name, replies, replyQueue, accessor, false);
}