使用Java DSL进行Spring集成的动态TCP服务器 [英] Dynamic TCP Server with Spring Integration using Java DSL

查看:290
本文介绍了使用Java DSL进行Spring集成的动态TCP服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过读取包含连接详细信息的属性文件来创建TCP服务器和客户端。
我在以下参考文档(
9.20动态和运行时集成流程)

I am trying to create a TCP server and client by reading the property files which contains the detail of the connections. I am using Dynamic and runtime Integration Flows with the help of following reference document ( 9.20 Dynamic and runtime Integration Flows)

创建客户端时代码工作正常但是当我使用相同代码中的更改创建服务器时,如下所示:

The code is working fine while creating the client but when I am creating the server using the same with changes in the code as follow:

    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();

我收到以下错误:

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

请帮忙我有上述问题。
我也找到了动态tcp客户端但动态tcp服务器没有代码(我可以创建动态服务器的任何资源或链接)。

Please help me with above issue. Also I have found the code for dynamic tcp client but no code is present for dynamic tcp server(any resource or link where I can take an idea to create dynamic server).

推荐答案

你正在混合责任。 Tcp.inboundAdapter()必须是 IntegrationFlow 链中的第一个。请考虑使用它:

You are mixing responsibility. The Tcp.inboundAdapter() must be a first in the IntegrationFlow chain. Consider to use this instead:

IntegrationFlow flow =  
   IntegrationFlows.from(Tcp.inboundAdapter(Tcp.netServer(2221)
                .serializer(TcpCodecs.crlf())
                .deserializer(TcpCodecs.lengthHeader1())
                .id("server")))
        .transform(Transformers.objectToString())
        .get();

这篇关于使用Java DSL进行Spring集成的动态TCP服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆