【问题标题】:Equivalent Java Config for spring messaging xml configspring 消息传递 xml 配置的等效 Java 配置
【发布时间】:2017-11-15 11:49:04
【问题描述】:

我正在尝试使用rabbitMQ 实现spring 批量远程分块。我关注这个link

什么是等效的 java 配置

<int:channel id="requests"/>
<int:channel id="replies"/>

<int-jms:message-driven-channel-adapter id="jmsIn"
    destination-name="requests"
    channel="requests"/>

<int-jms:outbound-channel-adapter id="outgoingReplies"
    destination-name="replies"
    channel="replies">
</int-jms:outbound-channel-adapter>

【问题讨论】:

    标签: java spring spring-batch spring-integration-amqp


    【解决方案1】:

    对于入站:

    @Bean(AMQP_INPUT_CHANNEL)
    public MessageChannel amqpInputChannel() {
        return new DirectChannel();
    }
    
    @Bean
    public AmqpInboundChannelAdapter inbound(SimpleMessageListenerContainer listenerContainer,  
                                             @Qualifier(AMQP_INPUT_CHANNEL) MessageChannel channel,
                                             Jackson2JsonMessageConverter messageConverter) {
        AmqpInboundChannelAdapter adapter = new AmqpInboundChannelAdapter(listenerContainer);   
        adapter.setMessageConverter(messageConverter);      
        adapter.setOutputChannel(channel);
        return adapter;
    }
    
    @Bean
    public SimpleMessageListenerContainer container(ConnectionFactory connectionFactory) {
        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);   
        container.setConcurrentConsumers(5);        
        container.setQueueNames("Queue_Name");          
        return container;
    }
    

    出站:

    @Bean
    public MessageChannel amqpOutboundChannel() {
        return new DirectChannel();
    }
    
    @Bean
    @ServiceActivator(inputChannel = "amqpOutboundChannel")
    public AmqpOutboundEndpoint amqpOutbound(AmqpTemplate amqpTemplate) {
        AmqpOutboundEndpoint outbound = new AmqpOutboundEndpoint(amqpTemplate);
        outbound.setRoutingKey("ERROR-QUEUE");
        return outbound;
    }
    
    @MessagingGateway(defaultRequestChannel = "amqpOutboundChannel")
    public interface BatchServiceMessagingGateway {
        void sendMessage(String data);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-21
      • 2013-10-24
      • 2016-10-24
      • 2012-10-19
      • 1970-01-01
      • 2015-11-19
      • 2017-06-21
      • 1970-01-01
      相关资源
      最近更新 更多