意外消息 - 没有使用连接拦截器注册的端点

时间:2017-11-20 16:07:59

标签: java spring sockets tcp spring-integration

我最近正在测试与Spring的tcp ip通信。我收到来自ip i连接的数据包时发生的问题。

以下是应用程序(与DynamicTcpClientApplication非常相似,但由于测试原因我自己做了一些更改。

我做错了什么,我有一个接收消息的适配器,但似乎只有从我的服务器发送的消息不会到达它们。如果我的客户有问题,请告诉我。

这让我很头疼......

@SpringBootApplication
@EnableMessageHistory
public class ClientApplication {

    public static ConfigurableApplicationContext context;


    public static void main(String[] args) throws IOException, InterruptedException {
        SpringApplicationBuilder builder = new SpringApplicationBuilder(ClientApplication.class);
        builder.headless(false);
        context = builder.run(args);
        new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
    }

    @Bean
    public ClientConfiguration config() {
        File file = new File(Paths.getInstallationFolder() + File.separator + "client.properties");
        if (!file.exists())
            try {
                if (file.createNewFile()) {
                    Logger.getLogger("Client").warning("Properties not found! New properties created." +
                            "Please restart the application!");
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        try {
            return new ClientConfiguration(Paths.getInstallationFolder().getAbsolutePath());
        } catch (ConfigurationException | IOException e) {
            e.printStackTrace();
            return null;
        }
    }


    @Bean(name = PollerMetadata.DEFAULT_POLLER)
    public PollerMetadata defaultPoller() {
        PollerMetadata pollerMetadata = new PollerMetadata();
        pollerMetadata.setTrigger(new PeriodicTrigger(10));
        return pollerMetadata;
    }

    // Client side

    @MessagingGateway(defaultRequestChannel = "toTcp.input")
    public interface ToTCP {

        void send(String data, @Header("host") String host, @Header("port") int port);
    }

    @Bean
    public IntegrationFlow toTcp() {
        return f -> f.route(new TcpRouter());
    }

    @Bean
    public TcpNetServerConnectionFactory cf() {
        TcpNetServerConnectionFactory factory = new TcpNetServerConnectionFactory(6666);
        factory.setSingleUse(false);
        ByteArrayCrLfSerializer serializer = (ByteArrayCrLfSerializer) factory.getSerializer();
        serializer.setMaxMessageSize(20480);
        ByteArrayCrLfSerializer deserializer = (ByteArrayCrLfSerializer) factory.getDeserializer();
        deserializer.setMaxMessageSize(20480);
        return factory;
    }

    @Bean
    public TcpReceivingChannelAdapter inbound(AbstractServerConnectionFactory cf) {
        TcpReceivingChannelAdapter messageHandler = new TcpReceivingChannelAdapter();
        messageHandler.setConnectionFactory(cf);
        messageHandler.setOutputChannel(outputChannel());
        messageHandler.setAutoStartup(true);
        messageHandler.start();
        return messageHandler;
    }

    @Bean
    public QueueChannel outputChannel() {
        return new QueueChannel();
    }

    @Transformer(inputChannel = "outputChannel", outputChannel = "serviceChannel")
    @Bean
    public ObjectToStringTransformer transformer() {
        return new ObjectToStringTransformer();
    }


    public static class TcpRouter extends AbstractMessageRouter {


        @SuppressWarnings("SpringJavaAutowiringInspection")
        @Autowired
        private IntegrationFlowContext flowContext;

        private final static int MAX_CACHED = 10; // When this is exceeded, we remove the LRU.

        @SuppressWarnings("serial")
        private final LinkedHashMap<String, MessageChannel> subFlows =
                new LinkedHashMap<String, MessageChannel>(MAX_CACHED, .75f, true) {

                    @Override
                    protected boolean removeEldestEntry(Map.Entry<String, MessageChannel> eldest) {
                        if (size() > MAX_CACHED) {
                            removeSubFlow(eldest);
                            return true;
                        } else {
                            return false;
                        }
                    }

                };

        private MessageChannel createNewSubflow(Message<?> message) {
            String host = (String) message.getHeaders().get("host");
            Integer port = (Integer) message.getHeaders().get("port");
            Assert.state(host != null && port != null, "host and/or port header missing");
            String hostPort = host + port;

            TcpNetClientConnectionFactory cf = new TcpNetClientConnectionFactory(host, port);
            TcpSendingMessageHandler handler = new TcpSendingMessageHandler();
            handler.setConnectionFactory(cf);
            IntegrationFlow flow = f -> f.handle(handler);
            IntegrationFlowRegistration flowRegistration =
                    this.flowContext.registration(flow)
                            .addBean(cf)
                            .id(hostPort + ".flow")
                            .register();
            MessageChannel inputChannel = flowRegistration.getInputChannel();
            this.subFlows.put(hostPort, inputChannel);
            return inputChannel;
        }

        private void removeSubFlow(Map.Entry<String, MessageChannel> eldest) {
            String hostPort = eldest.getKey();
            this.flowContext.remove(hostPort + ".flow");
        }

        @Override
        protected Collection<MessageChannel> determineTargetChannels(Message<?> message) {
            MessageChannel channel = this.subFlows
                    .get(message.getHeaders().get("host", String.class) + message.getHeaders().get("port"));
            if (channel == null) {
                channel = createNewSubflow(message);
            }
            return Collections.singletonList(channel);
        }
    }
}

错误:

    2017-11-20 16:54:10.712  WARN 6816 --- [pool-2-thread-1] o.s.i.i.tcp.connection.TcpNetConnection  : Unexpected message - no endpoint registered with connection interceptor: 192.168.200.107:6666:46707:a02d3f05-8e32-4215-8130-29c56d25ab36 - GenericMessage [payload=byte[40], headers={ip_tcp_remotePort=6666, ip_connectionId=192.168.200.107:6666:46707:a02d3f05-8e32-4215-8130-29c56d25ab36, ip_localInetAddress=/192.168.200.88, ip_address=192.168.200.107, id=9031c426-438d-535d-affa-09caa09b9e22, ip_hostname=192.168.200.107, timestamp=1511193250712}]
    2017-11-20 16:54:10.712  WARN 6816 --- [pool-2-thread-1] o.s.i.i.tcp.connection.TcpNetConnection  : Unexpected message - no endpoint registered with connection interceptor: 192.168.200.107:6666:46707:a02d3f05-8e32-4215-8130-29c56d25ab36 - GenericMessage [payload=byte[0], headers={ip_tcp_remotePort=6666, ip_connectionId=192.168.200.107:6666:46707:a02d3f05-8e32-4215-8130-29c56d25ab36, ip_localInetAddress=/192.168.200.88, ip_address=192.168.200.107, id=63ff31e2-8f25-8282-fec4-f3c4cfc38cd6, ip_hostname=192.168.200.107, timestamp=1511193250712}]

DEBUG-LOG:客户端

19:00:35.878 [main] INFO  o.s.i.config.IntegrationRegistrar - No bean named 'integrationHeaderChannelRegistry' has been explicitly defined. Therefore, a default DefaultHeaderChannelRegistry will be created.
19:00:35.879 [main] DEBUG o.s.i.config.IntegrationRegistrar - The '#jsonPath' SpEL function cannot be registered: there is no jayway json-path.jar on the classpath.
19:00:35.879 [main] DEBUG o.s.i.config.IntegrationRegistrar - SpEL function '#xpath' isn't registered: there is no spring-integration-xml.jar on the classpath.
19:00:35.949 [main] INFO  o.s.i.c.DefaultConfiguringBeanFactoryPostProcessor - No bean named 'errorChannel' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created.
19:00:35.950 [main] INFO  o.s.i.c.DefaultConfiguringBeanFactoryPostProcessor - No bean named 'taskScheduler' has been explicitly defined. Therefore, a default ThreadPoolTaskScheduler will be created.
C:\Users\Sebas\<myApp>\client.properties
19:00:36.088 [main] DEBUG o.s.i.h.ServiceActivatingHandler - Unable to attempt conversion of Message payload types. Component 'fileManager.service.serviceActivator.handler' has no explicit ConversionService reference, and there is no 'integrationConversionService' bean within the context.
19:00:36.132 [main] INFO  o.s.i.i.t.c.TcpNetServerConnectionFactory - started cf, port=6666
19:00:36.132 [main] INFO  o.s.i.i.t.TcpReceivingChannelAdapter - started org.springframework.integration.ip.tcp.TcpReceivingChannelAdapter@2dd29a59
19:00:36.133 [pool-1-thread-1] INFO  o.s.i.i.t.c.TcpNetServerConnectionFactory - cf, port=6666 Listening
19:00:36.282 [main] DEBUG o.s.i.c.GlobalChannelInterceptorProcessor - No global channel interceptors.
19:00:36.283 [main] INFO  o.s.i.h.MessageHistoryConfigurer - Enabling MessageHistory tracking for component 'inbound'
19:00:36.283 [main] INFO  o.s.i.h.MessageHistoryConfigurer - Enabling MessageHistory tracking for component 'outputChannel'
19:00:36.283 [main] INFO  o.s.i.h.MessageHistoryConfigurer - Enabling MessageHistory tracking for component '<myApp>ClientApplication$ToTCP'
19:00:36.283 [main] INFO  o.s.i.h.MessageHistoryConfigurer - Enabling MessageHistory tracking for component 'errorChannel'
19:00:36.283 [main] INFO  o.s.i.h.MessageHistoryConfigurer - Enabling MessageHistory tracking for component '_org.springframework.integration.errorLogger'
19:00:36.283 [main] INFO  o.s.i.h.MessageHistoryConfigurer - Enabling MessageHistory tracking for component '<myApp>ClientApplication.transformer.transformer.handler'
19:00:36.283 [main] INFO  o.s.i.h.MessageHistoryConfigurer - Enabling MessageHistory tracking for component 'fileManager.service.serviceActivator.handler'
19:00:36.283 [main] INFO  o.s.i.h.MessageHistoryConfigurer - Enabling MessageHistory tracking for component 'serviceChannel'
19:00:36.283 [main] INFO  o.s.i.h.MessageHistoryConfigurer - Enabling MessageHistory tracking for component 'toTcp.input'
19:00:36.283 [main] INFO  o.s.i.h.MessageHistoryConfigurer - Enabling MessageHistory tracking for component 'de.iutp.<myApp>.<myApp>client.<myApp>ClientApplication$TcpRouter#0'
19:00:36.283 [main] INFO  o.s.i.endpoint.EventDrivenConsumer - Adding {service-activator:fileManager.service.serviceActivator} as a subscriber to the 'serviceChannel' channel
19:00:36.283 [main] INFO  o.s.i.channel.DirectChannel - Channel 'application.serviceChannel' has 1 subscriber(s).
19:00:36.283 [main] INFO  o.s.i.endpoint.EventDrivenConsumer - started fileManager.service.serviceActivator
19:00:36.283 [main] INFO  o.s.i.g.GatewayProxyFactoryBean$MethodInvocationGateway - started <myApp>ClientApplication$ToTCP
19:00:36.283 [main] INFO  o.s.i.g.GatewayCompletableFutureProxyFactoryBean - started <myApp>ClientApplication$ToTCP
19:00:36.283 [main] INFO  o.s.i.endpoint.EventDrivenConsumer - Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
19:00:36.283 [main] INFO  o.s.i.c.PublishSubscribeChannel - Channel 'application.errorChannel' has 1 subscriber(s).
19:00:36.283 [main] INFO  o.s.i.endpoint.EventDrivenConsumer - started _org.springframework.integration.errorLogger
19:00:36.283 [main] INFO  o.s.i.endpoint.EventDrivenConsumer - Adding {router} as a subscriber to the 'toTcp.input' channel
19:00:36.283 [main] INFO  o.s.i.channel.DirectChannel - Channel 'application.toTcp.input' has 1 subscriber(s).
19:00:36.283 [main] INFO  o.s.i.endpoint.EventDrivenConsumer - started org.springframework.integration.config.ConsumerEndpointFactoryBean#0
19:00:36.284 [main] INFO  o.s.i.endpoint.PollingConsumer - started <myApp>ClientApplication.transformer.transformer
19:00:37.285 [task-scheduler-1] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:00:38.296 [task-scheduler-2] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:00:39.307 [task-scheduler-1] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:00:40.318 [task-scheduler-3] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:00:41.329 [task-scheduler-2] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:00:42.341 [task-scheduler-4] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:00:43.352 [task-scheduler-1] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:00:44.363 [task-scheduler-5] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:00:45.374 [task-scheduler-3] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:00:46.385 [task-scheduler-3] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:00:47.396 [task-scheduler-3] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:00:48.407 [task-scheduler-3] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:00:49.419 [task-scheduler-3] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:00:50.430 [task-scheduler-3] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:00:51.441 [task-scheduler-3] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:00:52.453 [task-scheduler-3] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:00:53.297 [Timer-0] DEBUG o.s.i.channel.DirectChannel - preSend on channel 'toTcp.input', message: GenericMessage [payload=64198e68-c701-44ae-856a-f5bf9a765e11::7d670b67-3605-4faa-908f-b9843e227b26::01717546021         ,R-Muehle            D_M72.7 keine Silovorwahl   
, headers={host=192.168.200.107, history=<myApp>ClientApplication$ToTCP,toTcp.input, id=f70a3c7b-e419-eea5-945b-0531d4acf2e0, port=6666, timestamp=1511200853297}]
19:00:53.302 [Timer-0] INFO  o.s.i.endpoint.EventDrivenConsumer - Adding {ip:tcp-outbound-channel-adapter} as a subscriber to the '192.168.200.1076666.flow.input' channel
19:00:53.302 [Timer-0] INFO  o.s.i.channel.DirectChannel - Channel 'application.192.168.200.1076666.flow.input' has 1 subscriber(s).
19:00:53.302 [Timer-0] INFO  o.s.i.i.t.c.TcpNetClientConnectionFactory - started 192.168.200.1076666.floworg.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory#0, host=192.168.200.107, port=6666
19:00:53.302 [Timer-0] INFO  o.s.i.endpoint.EventDrivenConsumer - started org.springframework.integration.config.ConsumerEndpointFactoryBean#1
19:00:53.302 [Timer-0] DEBUG o.s.i.channel.DirectChannel - preSend on channel '192.168.200.1076666.flow.input', message: GenericMessage [payload=64198e68-c701-44ae-856a-f5bf9a765e11::7d670b67-3605-4faa-908f-b9843e227b26::01717546021         ,R-Muehle            D_M72.7 keine Silovorwahl   
, headers={host=192.168.200.107, history=<myApp>ClientApplication$ToTCP,toTcp.input,de.iutp.<myApp>.<myApp>client.<myApp>ClientApplication$TcpRouter#0, id=0e1ead22-e947-6ae4-bb5c-13b8fa80c5e1, port=6666, timestamp=1511200853297}]
19:00:53.302 [Timer-0] DEBUG o.s.i.i.tcp.TcpSendingMessageHandler - org.springframework.integration.ip.tcp.TcpSendingMessageHandler#0 received message: GenericMessage [payload=64198e68-c701-44ae-856a-f5bf9a765e11::7d670b67-3605-4faa-908f-b9843e227b26::01717546021         ,R-Muehle            D_M72.7 keine Silovorwahl   
, headers={host=192.168.200.107, history=<myApp>ClientApplication$ToTCP,toTcp.input,de.iutp.<myApp>.<myApp>client.<myApp>ClientApplication$TcpRouter#0, id=0e1ead22-e947-6ae4-bb5c-13b8fa80c5e1, port=6666, timestamp=1511200853297}]
19:00:53.302 [Timer-0] DEBUG o.s.i.i.t.c.TcpNetClientConnectionFactory - Opening new socket connection to 192.168.200.107:6666
19:00:53.464 [task-scheduler-3] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:00:54.475 [task-scheduler-3] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:00:55.486 [task-scheduler-3] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:00:56.497 [task-scheduler-3] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:00:57.509 [task-scheduler-3] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:00:58.520 [task-scheduler-3] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:00:58.961 [Timer-0] DEBUG o.s.i.i.t.c.TcpNetConnection - New connection 192.168.200.107:6666:51251:94af931e-65e3-498d-a88b-b7389b1df65a
19:00:58.961 [Timer-0] DEBUG o.s.i.i.t.c.TcpNetClientConnectionFactory - 192.168.200.1076666.floworg.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory#0: Added new connection: 192.168.200.107:6666:51251:94af931e-65e3-498d-a88b-b7389b1df65a
19:00:58.962 [pool-2-thread-1] DEBUG o.s.i.i.t.c.TcpNetConnection - 192.168.200.107:6666:51251:94af931e-65e3-498d-a88b-b7389b1df65a Reading...
19:00:58.962 [pool-2-thread-1] DEBUG o.s.i.i.t.s.ByteArrayCrLfSerializer - Available to read: 0
19:00:58.962 [Timer-0] DEBUG o.s.i.i.tcp.TcpSendingMessageHandler - Got Connection 192.168.200.107:6666:51251:94af931e-65e3-498d-a88b-b7389b1df65a
19:00:58.963 [Timer-0] DEBUG o.s.i.i.t.c.TcpNetConnection - 192.168.200.107:6666:51251:94af931e-65e3-498d-a88b-b7389b1df65a Message sent GenericMessage [payload=64198e68-c701-44ae-856a-f5bf9a765e11::7d670b67-3605-4faa-908f-b9843e227b26::01717546021         ,R-Muehle            D_M72.7 keine Silovorwahl   
, headers={host=192.168.200.107, history=<myApp>ClientApplication$ToTCP,toTcp.input,de.iutp.<myApp>.<myApp>client.<myApp>ClientApplication$TcpRouter#0, id=0e1ead22-e947-6ae4-bb5c-13b8fa80c5e1, port=6666, timestamp=1511200853297}]
19:00:58.963 [Timer-0] DEBUG o.s.i.channel.DirectChannel - postSend (sent=true) on channel '192.168.200.1076666.flow.input', message: GenericMessage [payload=64198e68-c701-44ae-856a-f5bf9a765e11::7d670b67-3605-4faa-908f-b9843e227b26::01717546021         ,R-Muehle            D_M72.7 keine Silovorwahl   
, headers={host=192.168.200.107, history=<myApp>ClientApplication$ToTCP,toTcp.input,de.iutp.<myApp>.<myApp>client.<myApp>ClientApplication$TcpRouter#0, id=0e1ead22-e947-6ae4-bb5c-13b8fa80c5e1, port=6666, timestamp=1511200853297}]
19:00:58.963 [Timer-0] DEBUG o.s.i.channel.DirectChannel - postSend (sent=true) on channel 'toTcp.input', message: GenericMessage [payload=64198e68-c701-44ae-856a-f5bf9a765e11::7d670b67-3605-4faa-908f-b9843e227b26::01717546021         ,R-Muehle            D_M72.7 keine Silovorwahl   
, headers={host=192.168.200.107, history=<myApp>ClientApplication$ToTCP,toTcp.input, id=f70a3c7b-e419-eea5-945b-0531d4acf2e0, port=6666, timestamp=1511200853297}]
19:00:59.214 [pool-2-thread-1] DEBUG o.s.i.i.t.c.TcpNetConnection - Message received GenericMessage [payload=byte[40], headers={ip_tcp_remotePort=6666, ip_connectionId=192.168.200.107:6666:51251:94af931e-65e3-498d-a88b-b7389b1df65a, ip_localInetAddress=/10.0.8.2, ip_address=192.168.200.107, id=efd1d331-7289-5074-e6e4-d85458d0abae, ip_hostname=192.168.200.107, timestamp=1511200859214}]
19:00:59.215 [pool-2-thread-1] WARN  o.s.i.i.t.c.TcpNetConnection - Unexpected message - no endpoint registered with connection interceptor: 192.168.200.107:6666:51251:94af931e-65e3-498d-a88b-b7389b1df65a - GenericMessage [payload=byte[40], headers={ip_tcp_remotePort=6666, ip_connectionId=192.168.200.107:6666:51251:94af931e-65e3-498d-a88b-b7389b1df65a, ip_localInetAddress=/10.0.8.2, ip_address=192.168.200.107, id=efd1d331-7289-5074-e6e4-d85458d0abae, ip_hostname=192.168.200.107, timestamp=1511200859214}]
19:00:59.215 [pool-2-thread-1] DEBUG o.s.i.i.t.s.ByteArrayCrLfSerializer - Available to read: 2
19:00:59.215 [pool-2-thread-1] DEBUG o.s.i.i.t.c.TcpNetConnection - Message received GenericMessage [payload=byte[0], headers={ip_tcp_remotePort=6666, ip_connectionId=192.168.200.107:6666:51251:94af931e-65e3-498d-a88b-b7389b1df65a, ip_localInetAddress=/10.0.8.2, ip_address=192.168.200.107, id=a6807249-9f8f-16f1-53e2-e4c1b7076483, ip_hostname=192.168.200.107, timestamp=1511200859215}]
19:00:59.215 [pool-2-thread-1] WARN  o.s.i.i.t.c.TcpNetConnection - Unexpected message - no endpoint registered with connection interceptor: 192.168.200.107:6666:51251:94af931e-65e3-498d-a88b-b7389b1df65a - GenericMessage [payload=byte[0], headers={ip_tcp_remotePort=6666, ip_connectionId=192.168.200.107:6666:51251:94af931e-65e3-498d-a88b-b7389b1df65a, ip_localInetAddress=/10.0.8.2, ip_address=192.168.200.107, id=a6807249-9f8f-16f1-53e2-e4c1b7076483, ip_hostname=192.168.200.107, timestamp=1511200859215}]
19:00:59.215 [pool-2-thread-1] DEBUG o.s.i.i.t.s.ByteArrayCrLfSerializer - Available to read: 0
19:00:59.531 [task-scheduler-3] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:01:00.542 [task-scheduler-3] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:01:01.553 [task-scheduler-3] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:01:02.565 [task-scheduler-3] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:01:03.577 [task-scheduler-3] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:01:04.588 [task-scheduler-3] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'
19:01:05.599 [task-scheduler-3] DEBUG o.s.i.endpoint.PollingConsumer - Received no Message during the poll, returning 'false'

2 个答案:

答案 0 :(得分:1)

错误表示其中一个连接工厂正在接收数据但没有TcpListener

请编辑问题以附上显示双方的DEBUG日志。

修改

19:00:59.214 [pool-2-thread-1] DEBUG o.s.i.i.t.c.TcpNetConnection - Message received GenericMessage [payload=byte[40], headers={ip_tcp_remotePort=6666, ip_connectionId=192.168.200.107:6666:51251:94af931e-65e3-498d-a88b-b7389b1df65a, ip_localInetAddress=/10.0.8.2, ip_address=192.168.200.107, id=efd1d331-7289-5074-e6e4-d85458d0abae, ip_hostname=192.168.200.107, timestamp=1511200859214}]
19:00:59.215 [pool-2-thread-1] WARN  o.s.i.i.t.c.TcpNetConnection - Unexpected message - no endpoint registered with connection interceptor: 192.168.200.107:6666:51251:94af931e-65e3-498d-a88b-b7389b1df65a - GenericMessage [payload=byte[40], headers={ip_tcp_remotePort=6666, ip_connectionId=192.168.200.107:6666:51251:94af931e-65e3-498d-a88b-b7389b1df65a, ip_localInetAddress=/10.0.8.2, ip_address=192.168.200.107, id=efd1d331-7289-5074-e6e4-d85458d0abae, ip_hostname=192.168.200.107, timestamp=1511200859214}]

您的客户端未配置为处理回复。

如果您处于请求/回复方案中,则需要使用TcpOutboundGateway而不是发送通道适配器。

如果要处理任意入站/出站邮件,则需要在客户端中使用接收通道适配器。

答案 1 :(得分:0)

感谢@Gary Russell和@Artem Bilan - 请参阅他们的答案:

这就是我所做的:

    private MessageChannel createNewSubflow(Message<?> message) {
        String host = (String) message.getHeaders().get("host");
        Integer port = (Integer) message.getHeaders().get("port");
        Assert.state(host != null && port != null, "host and/or port header missing");
        String hostPort = host + port;

        TcpNetClientConnectionFactory cf = new TcpNetClientConnectionFactory(host, port);
        TcpReceivingChannelAdapter messageHandler = new TcpReceivingChannelAdapter();
        messageHandler.setConnectionFactory(cf);
        messageHandler.setOutputChannel(outputChannel);
        TcpSendingMessageHandler handler = new TcpSendingMessageHandler();
        handler.setConnectionFactory(cf);
        IntegrationFlow flow = f -> f.handle(handler);
        IntegrationFlowRegistration flowRegistration =
                this.flowContext.registration(flow)
                        .addBean(cf)
                        .id(hostPort + ".flow")
                        .register();
        MessageChannel inputChannel = flowRegistration.getInputChannel();
        this.subFlows.put(hostPort, inputChannel);
        return inputChannel;
    }

谢谢:)