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

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

Introduction

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

Prototype

public AmqpOutboundEndpoint(AmqpTemplate amqpTemplate) 

Source Link

Usage

From source file:io.spring.batch.configuration.JobConfiguration.java

@Bean
@ServiceActivator(inputChannel = "outboundRequests")
public AmqpOutboundEndpoint amqpOutboundEndpoint(AmqpTemplate template) {
    AmqpOutboundEndpoint endpoint = new AmqpOutboundEndpoint(template);

    endpoint.setExpectReply(true);/*ww  w  . j  a v a2  s .  c o  m*/
    endpoint.setOutputChannel(inboundRequests());

    endpoint.setRoutingKey("partition.requests");

    return endpoint;
}

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);//  w w w  . j  av  a 2  s. c o  m
    handler.afterPropertiesSet();
    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

private AmqpOutboundEndpoint buildOutboundEndpoint(final String name) {
    rabbitAdmin.declareQueue(new Queue(name));
    AmqpOutboundEndpoint queue = new AmqpOutboundEndpoint(rabbitTemplate);
    queue.setRoutingKey(name); // uses default exchange
    queue.setHeaderMapper(mapper);/*from w ww.  j  av a2 s. co  m*/
    queue.afterPropertiesSet();
    return queue;
}

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

@Override
public void bindPubSubProducer(String name, MessageChannel moduleOutputChannel) {
    rabbitAdmin.declareExchange(new FanoutExchange("topic." + name));
    AmqpOutboundEndpoint fanout = new AmqpOutboundEndpoint(rabbitTemplate);
    fanout.setExchangeName("topic." + name);
    fanout.setHeaderMapper(mapper);/*from  w  w  w . j  a v  a2s. c o m*/
    fanout.afterPropertiesSet();
    doRegisterProducer(name, moduleOutputChannel, fanout);
}

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);
    }//  ww  w .j a va  2  s . c o  m
    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 AmqpOutboundEndpoint buildOutboundEndpoint(final String name, RabbitPropertiesAccessor properties,
        RabbitTemplate rabbitTemplate) {
    String queueName = properties.getPrefix(this.defaultPrefix) + name;
    String partitionKeyExtractorClass = properties.getPartitionKeyExtractorClass();
    Expression partitionKeyExpression = properties.getPartitionKeyExpression();
    AmqpOutboundEndpoint queue = new AmqpOutboundEndpoint(rabbitTemplate);
    if (partitionKeyExpression == null && !StringUtils.hasText(partitionKeyExtractorClass)) {
        declareQueueIfNotPresent(new Queue(queueName));
        queue.setRoutingKey(queueName); // uses default exchange
    } else {/* w w  w  . j  a v  a 2 s .  c o m*/
        queue.setRoutingKeyExpression(buildPartitionRoutingExpression(queueName));
        for (int i = 0; i < properties.getPartitionCount(); i++) {
            this.rabbitAdmin.declareQueue(new Queue(queueName + "-" + i));
        }
    }
    configureOutboundHandler(queue, properties);
    return queue;
}

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

@Override
public void bindPubSubProducer(String name, MessageChannel moduleOutputChannel, Properties properties) {
    validateProducerProperties(name, properties, SUPPORTED_PUBSUB_PRODUCER_PROPERTIES);
    RabbitPropertiesAccessor accessor = new RabbitPropertiesAccessor(properties);
    String exchangeName = accessor.getPrefix(this.defaultPrefix) + "topic." + name;
    declareExchangeIfNotPresent(new FanoutExchange(exchangeName));
    AmqpOutboundEndpoint fanout = new AmqpOutboundEndpoint(determineRabbitTemplate(accessor));
    fanout.setExchangeName(exchangeName);
    configureOutboundHandler(fanout, accessor);
    doRegisterProducer(name, moduleOutputChannel, fanout, accessor);
}

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

@Override
public void bindReplier(String name, MessageChannel requests, MessageChannel replies, Properties properties) {
    if (logger.isInfoEnabled()) {
        logger.info("binding replier: " + name);
    }//from  ww  w  . j  av  a  2 s.  c  o  m
    validateConsumerProperties(name, properties, SUPPORTED_REPLYING_CONSUMER_PROPERTIES);
    RabbitPropertiesAccessor accessor = new RabbitPropertiesAccessor(properties);
    Queue requestQueue = new Queue(accessor.getPrefix(this.defaultPrefix) + name + ".requests");
    declareQueueIfNotPresent(requestQueue);
    this.doRegisterConsumer(name, requests, requestQueue, accessor, false);

    AmqpOutboundEndpoint replyQueue = new AmqpOutboundEndpoint(rabbitTemplate);
    replyQueue.setRoutingKeyExpression("headers['" + AmqpHeaders.REPLY_TO + "']");
    configureOutboundHandler(replyQueue, accessor);
    doRegisterProducer(name, replies, replyQueue, accessor);
}