Serveur TCP dynamique avec intégration Spring à l'aide de Java DSL


J'essaie de créer un serveur TCP et un client en lisant les fichiers de propriétés qui contiennent le détail des connexions. J'utilise des flux d'intégration dynamiques et d'exécution à l'aide du document de référence suivant ( 9.20 Flux d'intégration dynamique et d'exécution)

Le code fonctionne correctement lors de la création du client {[8] } mais lorsque je crée le serveur en utilisant le même avec des modifications dans le code comme suit:

    IntegrationFlow flow = f -> f
            .handle(Tcp.inboundAdapter(Tcp.netServer(2221)
                    .serializer(TcpCodecs.crlf())
                    .deserializer(TcpCodecs.lengthHeader1())
                    .id("server")))
            .transform(Transformers.objectToString());

    IntegrationFlowRegistration theFlow = this.flowContext.registration(flow).register();

Je reçois ce qui suit erreur:

Caused by: java.lang.IllegalArgumentException: Found ambiguous parameter type [class java.lang.String] for method match: [public java.lang.Class<?> org.springframework.integration.dsl.IntegrationComponentSpec.getObjectType(), public S org.springframework.integration.dsl.MessageProducerSpec.outputChannel(java.lang.String), public S org.springframework.integration.dsl.MessageProducerSpec.outputChannel(org.springframework.messaging.MessageChannel), public org.springframework.integration.ip.dsl.TcpInboundChannelAdapterSpec org.springframework.integration.ip.dsl.TcpInboundChannelAdapterSpec.taskScheduler(org.springframework.scheduling.TaskScheduler), public S org.springframework.integration.dsl.MessageProducerSpec.errorMessageStrategy(org.springframework.integration.support.ErrorMessageStrategy), public S org.springframework.integration.dsl.MessageProducerSpec.phase(int), public S org.springframework.integration.dsl.MessageProducerSpec.autoStartup(boolean), public S org.springframework.integration.dsl.MessageProducerSpec.sendTimeout(long)]
    at org.springframework.util.Assert.isNull(Assert.java:155)
    at org.springframework.integration.util.MessagingMethodInvokerHelper.findHandlerMethodsForTarget(MessagingMethodInvokerHelper.java:843)
    at org.springframework.integration.util.MessagingMethodInvokerHelper.<init>(MessagingMethodInvokerHelper.java:362)
    at org.springframework.integration.util.MessagingMethodInvokerHelper.<init>(MessagingMethodInvokerHelper.java:231)
    at org.springframework.integration.util.MessagingMethodInvokerHelper.<init>(MessagingMethodInvokerHelper.java:225)
    at org.springframework.integration.handler.MethodInvokingMessageProcessor.<init>(MethodInvokingMessageProcessor.java:60)
    at org.springframework.integration.handler.ServiceActivatingHandler.<init>(ServiceActivatingHandler.java:38)
    at org.springframework.integration.dsl.IntegrationFlowDefinition.handle(IntegrationFlowDefinition.java:924)
    at org.springframework.integration.dsl.IntegrationFlowDefinition.handle(IntegrationFlowDefinition.java:904)
    at org.springframework.integration.dsl.IntegrationFlowDefinition.handle(IntegrationFlowDefinition.java:891)
    at org.springframework.integration.samples.dynamictcp.DynamicTcpClientApplication.lambda$1(DynamicTcpClientApplication.java:194)
    at org.springframework.integration.config.dsl.IntegrationFlowBeanPostProcessor.processIntegrationFlowImpl(IntegrationFlowBeanPostProcessor.java:268)
    at org.springframework.integration.config.dsl.IntegrationFlowBeanPostProcessor.postProcessBeforeInitialization(IntegrationFlowBeanPostProcessor.java:96)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:423)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1702)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:583)
    ... 16 common frames omitted

Veuillez m'aider avec le problème ci-dessus. J'ai également trouvé le code pour dynamic tcp client mais aucun code n'est présent pour dynamic tcp server(toute ressource ou lien où je peux prendre une idée pour créer dynamic server).

Author: sirandy, 2018-04-11

1 answers

Vous mélangez la responsabilité. Le Tcp.inboundAdapter() doit être un premier dans la chaîne IntegrationFlow. Pensez à utiliser ceci à la place:

IntegrationFlow flow =  
   IntegrationFlows.from(Tcp.inboundAdapter(Tcp.netServer(2221)
                .serializer(TcpCodecs.crlf())
                .deserializer(TcpCodecs.lengthHeader1())
                .id("server")))
        .transform(Transformers.objectToString())
        .get();
 2
Author: Artem Bilan, 2018-04-11 15:22:15