spring integrationflow没有在receivercontainer

时间:2018-05-25 05:31:11

标签: spring integration amqp dispatcher subscriber

我们使用spring-integration(4.3.12)和spring-amqp(1.7.4)在微服务之间发送和接收消息。 为了避免微服务中的集成/ amqp配置,我们希望使用包含integration / amqp工厂的库来创建所需的对象。

我的期望:

我使用messageHandler / messageHandler方法(参见下面的代码)和SimpleMessageHandlerContainer创建IntegrationFlow实例。当我向绑定的交换发送消息时,IO期望使用消息调用messageHandler。

我得到了什么:

异常:“MessageDispatchingException:Dispatcher没有订阅者”

如果我直接使用MessageListenerContainer(在容器上直接设置messageHandler),那么我会按预期获得消息。 我想,问题在于IntegrationFlow的编程初始化,但我找不到任何信息我做错了。 任何人都可以给我一个提示吗? 感谢名单

现在使用的代码:

public IntegrationFlow createMessageNotifierIntegrationFlow(//
        String brokerNameSpace, String messageHandlerNameSpace, //
        Object messageHandler, String methodName) {
    ConnectionFactory cf = createConnectionFactory(brokerNameSpace);
    AmqpAdmin amqpAdmin = createAmqpAdmin(brokerNameSpace, cf);
    Inbound inbound = createInbound(messageHandlerNameSpace);
    Queue queue = createQueue(messageHandlerNameSpace, amqpAdmin, inbound);

    MessageNotifierIntegrationFlowBuilder builder = MessageNotifierIntegrationFlowBuilder
            .newBuilder(messageHandlerNameSpace, this);
    IntegrationFlow integrationFlow = builder//
            .withConnectionFactory(cf)//
            .withMessageHandler(messageHandler)//
            .withMessageHandlerMethod(methodName)//
            .withFlowExceptionHandler(new FlowExceptionHandler())//
            .withInbound(inbound)//
            .withAmqpAdmin(amqpAdmin)//
            .withInboundQueue(queue)//
            .build();
    String beanName = brokerNameSpace + "-" + messageHandlerNameSpace + "-" + inbound.getQueue();

    return integrationFlow;
}

 public IntegrationFlow build() {
        LOGGER.info("creating IntegrationFlow for {}", inbound.getQueue());
        validateBuilder();
        SimpleMessageListenerContainer receiverContainer = amqpObjectFactory.createMessageListenerContainer(//
                inbound, connectionFactory, //
                flowExceptionHandler, inboundQueue, messageHandlerNameSpace);
        final AmqpInboundChannelAdapterSpec adapter = (AmqpInboundChannelAdapterSpec) Amqp.inboundAdapter(receiverContainer);

        StandardIntegrationFlow flow = IntegrationFlows //
                .from(adapter) //
                .log("receiveData")//
                .transform(TO_STRING_TRANSFORMER) //
                .handle(messageHandler, messageHandlerMethod) //
                .log("to message handler").get();
        // flow.start() maybe later?
        flow.start();
        return flow;
    }

       public SimpleMessageListenerContainer createMessageListenerContainer(//
            final Inbound inbound, //
            final ConnectionFactory connectionFactory, //
            final FlowExceptionHandler flowExceptionHandler, //
            final Queue inboundQueue, String messageHandlerNameSpace) {
        final String beanName = messageHandlerNameSpace + "-container-" + inbound.getQueue();
        SimpleMessageListenerContainer container = null;
        container = new SimpleMessageListenerContainer(connectionFactory);
        container.setMaxConcurrentConsumers(inbound.getMaxconsumers());
        container.setConcurrentConsumers(inbound.getMinconsumers());
        container.setStartConsumerMinInterval(inbound.getMininterval());
        container.addQueues(inboundQueue);
        container.setAcknowledgeMode(inbound.getAckmode());
        container.setDefaultRequeueRejected(inbound.getRequeueRejected());
        container.setErrorHandler(flowExceptionHandler);
        container.setRecoveryInterval(RECOVERY_INTERVAL);
        container.setAutoStartup(false);

        return container;
    }

0 个答案:

没有答案