>

TCP를 통해 간단한 메시지를 보내려고하는데 스프링 통합을 사용하여 관리 할 수조차 없습니다 ... 나는 정말로 지루해합니다 ...

그래서 클라이언트 모드에서 TcpOutboundGateway와 TcpInboudGateway를 사용해 보았지만 MessageDeliveryException이 발생합니다.

내 코드는 다음과 같습니다 :

@EnableIntegration
@IntegrationComponentScan
@Configuration
public class TcpClientConfiguration {
    @Bean
    public TcpNetClientConnectionFactory clientConnectionFactory() {
        TcpNetClientConnectionFactory factory = new TcpNetClientConnectionFactory("localhost", 7015);
        return factory;
    }
    @Bean
    public DirectChannel outputChannel() {
        return new DirectChannel();
    }
    @Bean
    public MessageChannel replyChannel() {
        return new DirectChannel();
    }
//    @Bean
//    public TcpOutboundGateway tcpOutGateway(AbstractClientConnectionFactory clientConnectionFactory) {
//        TcpOutboundGateway outGateway = new TcpOutboundGateway();
//        outGateway.setConnectionFactory(clientConnectionFactory);
//        outGateway.setOutputChannel(outputChannel());
//        return outGateway;
//    }
    @Bean
    public TcpInboundGateway tcpInboundGateway(AbstractClientConnectionFactory clientConnectionFactory) {
        TcpInboundGateway inGateway = new TcpInboundGateway();
        inGateway.setConnectionFactory(clientConnectionFactory);
        inGateway.setClientMode(true);
        inGateway.setRequestChannel(outputChannel());
        inGateway.setReplyChannel(replyChannel());
        return inGateway;
    }
}

메시지를 보내는 예약 된 방법 :

@Component
public class SimulatorTask {
    @Autowired
    DirectChannel outputChannel;
    @Scheduled( fixedDelay = 3000 )
    public void sendMsg() {
        outputChannel.send(new GenericMessage<>("Hello world!"));
    }
}

내 오류 :

2018-05-03 13:42:44.578 ERROR 11144 --- [ask-scheduler-7] o.s.integration.handler.LoggingHandler   : org.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'application.outputChannel'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers, failedMessage=GenericMessage [payload=Hello world!, headers={id=ed173189-b102-6f85-5fe5-d901f4585140, timestamp=1525347764578}], failedMessage=GenericMessage [payload=Hello world!, headers={id=ed173189-b102-6f85-5fe5-d901f4585140, timestamp=1525347764578}]
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:445)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:394)
    at be.thingsplay.fmb920simulator.tcp.SimulatorTask.sendMsg(SimulatorTask.java:20)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers, failedMessage=GenericMessage [payload=Hello world!, headers={id=ed173189-b102-6f85-5fe5-d901f4585140, timestamp=1525347764578}]
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:138)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:105)
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:73)
    ... 16 more

봄이 정말 지루해 ...

  • 답변 # 1

    따라서 메시지를 성공적으로 보내고 있습니다. 메시지가 성공적으로 outputChannel 에 도착합니다  DirectChannel로 선택했습니다. DirectChannel의 정의에는 가입자가 필요하지만 구성에 표시되지 않는 가입자 (예 : @Transformer )  또는 @ServiceActivator  또는 다른 유형의 MessageHandler ), 예외가 바로 그 사실을 말해줍니다. 따라서 메시지가 전송되었는지 확인하려면 다른 채널 구현을 선택할 수 있습니다. 예를 들어, QueueChannel 를 선택할 수 있습니다  메시지가 폴링 될 때까지 또는 PublishSubscribeChannel 에서 메시지를 버퍼링합니다.  구독자가 없으면 메시지가 삭제됩니다. 또는 가입자를 추가하십시오.

    @ServiceActivator(inputChannel="outputChannel", outputChannel="replyChannel")
    public Message echo(Message message) {
        return message;
    }
    
    

  • 이전 java - 스윙 - jtable 열
  • 다음 javascript - 변수를 감시/청취하고"onChange"이벤트를 트리거하는 방법 (모듈 식 JS)