0
votes

I am developing an web application which supports TCP connection by Spring Integration. It has two functions.

  1. send messages to Server and receive reply from Server at a time
  2. just receive messages from Server

(The application on server is not developed by Spring Integration.)

In this case, TCP Adapters should be used and I need provide to collaborate TCP Outbound and Inbound Channel Adapters. But, my application has a few restrictions.

  1. this application has no database.
  2. messages' payload format is already specified. (It means I can not add any correlation data such as a transaction id to payload .

So, I think that collaborating TCP Outbound and Inbound Channel Adapters is difficult. Then, I plan to extend TCP Outbound gateway to add just receiving messages function. How should I extend it ? (or do you have other ideas?)

Thanks in advance.

1

1 Answers

0
votes

If you can determine the message type, something like this should work...

public class ExtendedTcpOutpboundGateway extends TcpOutboundGateway {

    private final MessageChannel unsolicitedMessageChannel;


    public ExtendedTcpOutpboundGateway(MessageChannel unsolicitedMessageChannel) {
        this.unsolicitedMessageChannel = unsolicitedMessageChannel;
    }

    @Override
    public boolean onMessage(Message<?> message) {
        if (isUnsolicitedMessage(message)) {
            this.messagingTemplate.send(this.unsolicitedMessageChannel, message);
            return false;
        }
        else {
            return super.onMessage(message);
        }
    }

    private boolean isUnsolicitedMessage(Message<?> message) {
        // TODO Add logic here to determine message type
        return false;
    }

}

If you can't tell the difference, it's not clear how you could implement your requirements.