0

I've encountered some problem when build a IoT service.

My architecture is shown as below:

UserBrowser<------>WebServer<---->NettyServer<----->Client(IoT device, auto response)

Here netty server act as a passthrough proxy which convert Userbrowser message and web server message to binary stream to remote IoT device, and then IoT device return back some message to user.

I use RocketMQ to communicate between WebServer and NettyServer

My question is since http request of UserBrowser is a sync operation, Netty is a async architecture, how to convert an async operation in Netty to sync HTTP request ?

Should I cache the requests and wait for response from IoT , and then return back? in this situation WebServer is a sync call

Or should I use async always, the UserBrowser poll result from WebServer ?

Alex Chan
  • 1,116
  • 3
  • 15
  • 33
  • You have a couple options here. Either you can block the web request until you've asynchronously completed a result from the IoT device (`CompletableFuture` is very nice for this), or you can add support in your protocol for a later/separate response object. I'm personally a fan of the latter but it can depend on the hardware in use. Opinion-wise I feel blocking for something widely used doesn't scale as well. – Rogue Sep 13 '18 at 13:01
  • `My protocol` you mean the protocol between `NettyServer` and `IoT device`? this channel runs a standard protocol that doesn't allowed to be modified – Alex Chan Sep 14 '18 at 02:08

0 Answers0