I'm trying to create a simple RendezvousChannel
for client-server communication. My applications start both fine, but the message is never send. Why?
client:
@Component
public class Sender {
@Autowired
@Qualifier("clientChannel")
private MessageChannel chan;
@PostConstruct
public void send() {
MessagingTemplate template = new MessagingTemplate();
Message<?> message = new Message<String>() {
@Override
public String getPayload() {
return "TEST";
}
@Override
public MessageHeaders getHeaders() {
return new MessageHeaders(null);
}
};
System.out.println("sending...");
Message<?> result = template.sendAndReceive(chan, message);
System.out.println("send: " + result.getPayload());
}
}
@MessageEndpoint
public class ClientEndpoint {
@Bean
public MessageChannel clientChannel() {
return new RendezvousChannel();
}
@Bean
public TcpConnectionFactoryFactoryBean clientFactory() {
TcpConnectionFactoryFactoryBean fact = new TcpConnectionFactoryFactoryBean();
fact.setType("client");
fact.setHost("localhost");
fact.setPort(5555);
fact.setUsingNio(true);
fact.setSingleUse(true);
return fact;
}
@Bean
public TcpOutboundGateway out(TcpNioClientConnectionFactory factory, @Qualifier("clientChannel") MessageChannel clientChannel) throws Exception {
TcpOutboundGateway gate = new TcpOutboundGateway();
gate.setConnectionFactory(factory);
gate.setReplyChannel(clientChannel);
return gate;
}
}
server:
@Component
public class Receiver {
@ServiceActivator(inputChannel = "serverChannel", poller = @Poller(fixedDelay = "1000", maxMessagesPerPoll = "1"))
public String hello(String input) throws Exception {
System.out.println("Hello: " + input);
return "Hello: " + input;
}
}
@MessageEndpoint
public class ServerEndpoint {
@Bean
public TcpInboundGateway serverGateway(TcpConnectionFactoryFactoryBean factory, @Qualifier("serverChannel") MessageChannel serverChannel) throws Exception {
TcpInboundGateway gate = new TcpInboundGateway();
gate.setConnectionFactory(factory.getObject());
gate.setRequestChannel(serverChannel);
return gate;
}
@Bean
public TcpConnectionFactoryFactoryBean clientFactory() {
TcpConnectionFactoryFactoryBean fact = new TcpConnectionFactoryFactoryBean();
fact.setType("server");
fact.setHost("localhost");
fact.setPort(5555);
fact.setUsingNio(true);
fact.setSingleUse(true);
return fact;
}
@Bean
public MessageChannel serverChannel() {
return new RendezvousChannel();
}
}
First I start the server, then the client. The client keeps ganging at "sending...", and the server never receives a message. Why?
Aucun commentaire:
Enregistrer un commentaire