Reputation: 5453
I've been developing a project using spring framework 4. I'm trying to create a simple TCP client via spring-integration-ip
library. I've adjusted all configurations:
...
<int:channel id="tcpChannel" />
<int-ip:tcp-outbound-channel-adapter id="outboundClient"
channel="tcpChannel"
connection-factory="tcpConnectionFactory"/>
...
@Configuration
public class MyConfiguration{
@Bean
public AbstractClientConnectionFactory tcpConnectionFactory() {
return new TcpNetClientConnectionFactory("localhost", 2345);
}
}
I've read all documentations about spring tcp here.
I guess I must use tcp-outbound-channel-adapter
or gateway
to send messages. but I wonder how to use it; what method should I invoke. I'm not supposed to receive any messages from server.
Upvotes: 1
Views: 1490
Reputation: 5453
I found the solution. I didn't need gateway
. spring messaging gateway
s have been designed to implement the request-response scenario. So the only thing I need to do is that I send message vi channel
. Perhaps there be some better solutions.
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.MessageChannel;
public class MyOwnService{
@Inject
private MessageChannel channel;
public void someMethod(String message){
Message<String> m = MessageBuilder.withPayload(message).build();
channel.send(m);
}
}
Upvotes: 1