Last active
August 29, 2015 14:01
-
-
Save obazoud/5765e6bc8ecab63eb594 to your computer and use it in GitHub Desktop.
Reactor questions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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