ChannelResolutionException: нет доступных заголовков output-channel или replyChannel — только со многими запросами

Я запускаю клиентскую часть примера Spring Integration TCP Multiplex. Я пытался посмотреть, сколько запросов он может обработать одновременно, и около 1000 я начал получать эту ошибку: ChannelResolutionException: нет доступных выходных каналов или заголовков answerChannel.

Все нормально ниже примерно 1000 звонков.

<beans:description>
        Uses conversion service and collaborating channel adapters.
    </beans:description>

    <context:property-placeholder />

    <converter>
        <beans:bean class="org.springframework.integration.samples.tcpclientserver.ByteArrayToStringConverter" />
    </converter>

    <!-- Fastest Wire Protocol - takes a byte array with its length definied in the first x bytes-->
    <beans:bean id="fastestWireFormatSerializer" class="org.springframework.integration.ip.tcp.serializer.ByteArrayLengthHeaderSerializer">
        <beans:constructor-arg value="1" />
    </beans:bean>

    <!-- Client side -->

    <gateway id="gw"
        service-interface="org.springframework.integration.samples.tcpclientserver.SimpleGateway"
        default-request-channel="input" />

    <ip:tcp-connection-factory id="client"
        type="client"
        host="localhost"
        port="${availableServerSocket}"
        single-use="false"
        serializer="fastestWireFormatSerializer"
        deserializer="fastestWireFormatSerializer"
        so-timeout="10000" />

    <publish-subscribe-channel id="input" />

    <!-- scheduler - Thread used to restablish connection so the other threads aren't starved while waiting to re-establish connection -->
    <!-- client-mode - Automatically re-establishes the connection if lost -->
    <ip:tcp-outbound-channel-adapter id="outAdapter.client"
        order="2"
        channel="input"
        client-mode="true"              
        connection-factory="client" />  <!-- Collaborator -->



    <!-- Also send a copy to the custom aggregator for correlation and
         so this message's replyChannel will be transferred to the
         aggregated message.
         The order ensures this gets to the aggregator first -->
    <bridge input-channel="input" output-channel="toAggregator.client"
            order="1"/>

    <!-- Asynch receive reply -->
    <ip:tcp-inbound-channel-adapter id="inAdapter.client"
        channel="toAggregator.client"
        connection-factory="client" /> <!-- Collaborator -->

    <!-- dataType attribute invokes the conversion service, if necessary -->
    <channel id="toAggregator.client" datatype="java.lang.String" />

    <aggregator input-channel="toAggregator.client"
        output-channel="toTransformer.client"
        correlation-strategy-expression="payload.substring(0,3)"
        release-strategy-expression="size() == 2"
        expire-groups-upon-completion="true" />

    <transformer input-channel="toTransformer.client"
        expression="payload.get(1)"/> <!-- The response is always second -->

    <task:scheduler id="reconnectScheduler" pool-size="10"/>

И код, используемый для тестирования:

        TaskExecutor executor = new SimpleAsyncTaskExecutor();
        final CountDownLatch latch = new CountDownLatch(100);
        final Set<Integer> results = new HashSet<Integer>();
        for (int i = 100; i < 1050; i++) {
            results.add(i);
            final int j = i;
            executor.execute(new Runnable() {
                public void run() {
                    String result = gateway.send(j + "Hello world!"); // first 3 bytes is correlationid
                    System.out.println("Test Result: " + result);
                    results.remove(j);
                    latch.countDown();
                }});
        }

person mad_fox    schedule 16.09.2015    source источник


Ответы (1)


Я не совсем понял, почему вы получаете это исключение, но в вашем тесте есть несколько проблем.

  1. Защелка обратного отсчета должна быть инициализирована на 950
  2. Поскольку вы превышаете 999, нам нужно изменить корреляцию:

    payload.substring(0,4)

С этими изменениями это работает для меня.

Я попытаюсь выяснить, почему мы получаем это исключение, когда у меня будет немного больше времени.

ИЗМЕНИТЬ

Проблема действительно вызвана конфликтующими идентификаторами корреляции.

Все последние 50 сообщений имеют идентификатор корреляции 100, что означает, что сообщения выпускаются неопределенным образом (учитывая, что выпуск зависит от размера). В некоторых случаях выпускаются два входных сообщения (что приводит к неправильному ответу на тестовый пример). Когда выпущено 2 ответа; выходного канала нет.

person Gary Russell    schedule 17.09.2015