Skip to content

Instantly share code, notes, and snippets.

@obazoud
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save obazoud/5765e6bc8ecab63eb594 to your computer and use it in GitHub Desktop.
Save obazoud/5765e6bc8ecab63eb594 to your computer and use it in GitHub Desktop.
Reactor questions
public class Gateway {
TcpClient<String, String> client = null;
NetChannel<String, String> channel;
public Gateway(String host, int port) {
client = new TcpClientSpec<String, String>(NettyTcpClient.class)
.env(env)
.codec(StandardCodecs.STRING_CODEC)
.connect(host, port)
.get();
channel = client.open().await();
}
public String send(String message) throws Exception {
return channel.sendAndReceive(message).await(100, TimeUnit.MILLISECONDS);
}
}
@RestController
@RequestMapping("/api")
public class GatewayResource {
@Autowired
private Gateway gateway;
@RequestMapping(value = "/gateway/{message}", method = RequestMethod.GET, produces = "application/json")
public Map<?, ?> gateway(@PathVariable String message) throws Exception {
return new ImmutableMap.Builder<String, Object>()
.put("result", gateway.send(message))
.build();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment