Я пытаюсь создать TCP-сервер и клиент, читая файлы свойств, которые содержат подробную информацию о соединениях. Я использую динамические потоки интеграции и потоки интеграции во время выполнения с помощью следующих справочный документ ( 9.20 Динамические потоки интеграции и интеграции во время выполнения)
Код работает нормально при создании клиента, но когда я создаю сервер, используя то же самое с изменениями в коде, как показано ниже:
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-сервера отсутствует (любой ресурс или ссылка, где я могу взять идею создания динамического сервера).




Вы смешиваете ответственность. Tcp.inboundAdapter() должен быть первым в цепочке IntegrationFlow. Подумайте о том, чтобы использовать это вместо этого:
IntegrationFlow flow =
IntegrationFlows.from(Tcp.inboundAdapter(Tcp.netServer(2221)
.serializer(TcpCodecs.crlf())
.deserializer(TcpCodecs.lengthHeader1())
.id("server")))
.transform(Transformers.objectToString())
.get();
Ваш запрос полностью выглядит как отдельный поток, даже если есть какой-то контекст, связанный с этим вопросом. Пожалуйста, поднимите новый вопрос SO, и мы вместе посмотрим, что и как там сделать, чтобы помочь вам.
ну я создал этот вопрос
Я нахожусь в той же ситуации, что и в вопросе, из-за кода, который я получил, мне нужно создать динамический реестр tcp с TcpNetClientConnectionFactory и TcpReceivingChannelAdapter. не могли бы вы еще немного расширить свой ответ @Artem_Bilan