Skip to content

Instantly share code, notes, and snippets.

@jstrachan
Created February 6, 2013 09:27
Show Gist options
  • Save jstrachan/4721399 to your computer and use it in GitHub Desktop.
Save jstrachan/4721399 to your computer and use it in GitHub Desktop.
little example of a RX API to vertx event bus along with some user code using it
/**
* RX Facade for EventBus
*/
interface ReactiveEventBus {
/** Subscribe to events on the event bus */
<T> Obserable<T> subscribe(String address);
/** Make a request/reply */
<In,Out> Obserable<Message<Out>> request(String address, In inMessage);
// TODO one way send / publish methods which don't require any RX Obserable stuff
}
/**
* An example of a custom API used by application code
*/
interface Waiter {
@Address("waiter.placeOrder")
Observable<Message<Wine>> orderWine(WineRequirement likes);
..
}
// in application code....
tastyWine = waiter.orderWine(new DrinkAnything()).filter(m -> w.body.isTasty());
mouth.drink(tastyWine);
// implementation detail could be generated
// using APT code generation or via reflection etc
class WaiterImpl implements Waiter {
private ReactiveEventBus bus;
public Observable<Message<Wine>> orderWine(WineRequirement likes) {
return bus.request("waiter.placeOrder", likes);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment