1

When I tried to define TcpOutboundGateway bean, I found that class doesn't have requestChannel and replyChannelName setters. How can I correctly define that bean in my Java class configuration?

Which Java class configuration is equal to the XML configuration presented below?

<int-ip:tcp-outbound-gateway id="outGateway"
        request-channel="input"
        reply-channel="clientBytes2StringChannel"
        connection-factory="client"
        request-timeout="10000"
        reply-timeout="10000"/>
Borodin
  • 126,100
  • 9
  • 70
  • 144
Meiblorn
  • 2,522
  • 2
  • 18
  • 23

1 Answers1

1

This code is equal to client xml configuration presented by the link.

public static final String STRING_TO_BYTES_CHANNEL = "stringToBytesChannel";
public static final String REQUEST_CHANNEL = "requestChannel";

private String host = "localhost";
private int port = 2020;

@Bean
public TcpNetClientConnectionFactory connectionFactory() {
    TcpNetClientConnectionFactory factory = new TcpNetClientConnectionFactory(host, port);
    factory.setSingleUse(true);
    factory.setSoTimeout(10000);
    return factory;
}

@Bean
public MessageChannel requestChannel() {
    return new DirectChannel();
}

@Bean
public MessageChannel stringToBytesChannel() {
    return new DirectChannel();
}

@Bean
@Transformer(inputChannel = STRING_TO_BYTES_CHANNEL)
public ObjectToStringTransformer objectToStringTransformer() {
    return new ObjectToStringTransformer();
}

@Bean
@ServiceActivator(inputChannel = REQUEST_CHANNEL)
public TcpOutboundGateway outboundGateway() {
    TcpOutboundGateway gateway = new TcpOutboundGateway();
    gateway.setConnectionFactory(connectionFactory());
    gateway.setReplyChannel(stringToBytesChannel());
    gateway.setRequestTimeout(10000);
    gateway.setRemoteTimeout(10000);
    return gateway;
}

@MessagingGateway(defaultRequestChannel = REQUEST_CHANNEL)
public interface RequestGateway {
    String send(String message);
}
Meiblorn
  • 2,522
  • 2
  • 18
  • 23