io.vertx.reactivex.core.eventbus.EventBus Java Examples

The following examples show how to use io.vertx.reactivex.core.eventbus.EventBus. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServiceVerticle.java    From festival with Apache License 2.0 6 votes vote down vote up
@Override
public Completable rxStart() {
    return Completable.fromAction(() -> {
        EventBus eventBus = vertx.eventBus();
        Class<?> targetClass = AopUtils.getTargetClass(serviceBean);
        String address = EventBusUtils.getAddress(targetClass);
        eventBus.consumer(address).handler(msg -> {
                    try {
                        MethodInvocation invocation = (MethodInvocation) msg.body();
                        String methodName = invocation.getMethodName();
                        Class<?>[] argumentClasses = invocation.getArgumentClasses();
                        Method method = serviceBean.getClass().getMethod(methodName, argumentClasses);
                        Object result = ReflectUtils.invokeMethod(serviceBean, method, invocation.getArguments());
                        msg.reply(result, options);
                    } catch (Exception e) {
                        msg.reply(e.getCause(), options);
                    }
                });
    });
}
 
Example #2
Source File: VerticleProxyHandler.java    From festival with Apache License 2.0 5 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    MethodInvocation methodInvocation = new MethodInvocation(method, args);
    EventBus eventBus = EventBus.newInstance(vertx.eventBus());
    String address = EventBusUtils.getAddress(targetClass);
    return eventBus.rxRequest(address, methodInvocation, options)
            .toFlowable()
            .flatMap(msg -> {
                Object result = msg.body();
                if (result instanceof Throwable) {
                    throw new IllegalStateException((Throwable) result);
                }
                return (Flowable<?>) result;
            });
}
 
Example #3
Source File: VertxChannel.java    From ocraft-s2client with MIT License 5 votes vote down vote up
private VertxChannel(EventBus eventBus) {
    outputStream = initOutputStream(eventBus);
    inputStream = initInputStream(eventBus);

    outputMessageProducer = eventBus
            .<byte[]>publisher(OUTPUT_STREAM)
            .setWriteQueueMaxSize(cfg().getInt(CLIENT_BUFFER_SIZE_RESPONSE_EVENT_BUS));

    inputMessageProducer = eventBus
            .<byte[]>sender(INPUT_STREAM)
            .setWriteQueueMaxSize(cfg().getInt(CLIENT_BUFFER_SIZE_REQUEST_EVENT_BUS));
}
 
Example #4
Source File: VertxChannel.java    From ocraft-s2client with MIT License 5 votes vote down vote up
private Observable<byte[]> initOutputStream(EventBus eventBus) {
    log.debug("registering event bus consumer [{}] for output stream", OUTPUT_STREAM);
    return eventBus
            .<byte[]>consumer(OUTPUT_STREAM)
            .toObservable()
            .map(Message::body)
            .doOnComplete(errorStream::onComplete);
}
 
Example #5
Source File: RxifiedExamples.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
public void eventBusMessages(Vertx vertx) {
  EventBus eb = vertx.eventBus();
  MessageConsumer<String> consumer = eb.<String>consumer("the-address");
  Observable<Message<String>> observable = consumer.toObservable();
  Disposable sub = observable.subscribe(msg -> {
    // Got message
  });

  // Unregisters the stream after 10 seconds
  vertx.setTimer(10000, id -> {
    sub.dispose();
  });
}
 
Example #6
Source File: CdiGlobalProvider.java    From redpipe with Apache License 2.0 4 votes vote down vote up
@Produces
public EventBus bus() {
	return AppGlobals.get().getVertx().eventBus();
}
 
Example #7
Source File: VertxChannel.java    From ocraft-s2client with MIT License 4 votes vote down vote up
static VertxChannel from(EventBus eventBus) {
    return new VertxChannel(eventBus);
}
 
Example #8
Source File: VertxChannel.java    From ocraft-s2client with MIT License 4 votes vote down vote up
private Observable<byte[]> initInputStream(EventBus eventBus) {
    log.debug("registering event bus consumer [{}] for input stream", INPUT_STREAM);
    return eventBus.<byte[]>consumer(INPUT_STREAM).toObservable().map(Message::body);
}
 
Example #9
Source File: RxifiedExamples.java    From vertx-rx with Apache License 2.0 4 votes vote down vote up
public void eventBusBodies(Vertx vertx) {
  EventBus eb = vertx.eventBus();
  MessageConsumer<String> consumer = eb.<String>consumer("the-address");
  Observable<String> observable = consumer.bodyStream().toObservable();
}