Reactor,无法加载类“org.slf4j.impl.StaticLoggerBinder”

时间:2014-09-13 12:19:30

标签: java reactor project-reactor

我已经开始玩Reactor,但我遇到了第一次事件的麻烦:D

在github中example之后,我试着写一个“你好世界”,但没有成功......

有什么问题?

代码:

package reactor;

import static reactor.event.selector.Selectors.$;
import reactor.core.Environment;
import reactor.core.Reactor;
import reactor.core.spec.Reactors;
import reactor.event.Event;
import reactor.function.Consumer;

public class Main {

    public static void main(String[] args) {

        final Environment env = new Environment();

        final Reactor reactor = Reactors.reactor(env);

        String topic = "event.message";

        reactor.on($(topic), new Consumer<Event<Message>>(){

            @Override
            public void accept(Event<Message> t) {
                System.out.println("Hello World");
            }

        });

        final Message event = new Message();
        reactor.notify(topic, Event.wrap(event));
        System.out.println("ends");
    }

    public static class Message{

    }
}

输出:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
ends

1 个答案:

答案 0 :(得分:2)

不要忘记ReactorReactive Streams范例的实现,其中的所有内容都是async

因此,您的reactor.notify(topic, Event.wrap(event));是在EventRouter内的某些handler发布给Thread的事件。

因此,您的main thead应该等待,直到完成所有下游工作。

或者在Thread.sleep(1000);和[{1}}中添加main或使用CoutDownLatch等待来自该Reactor线程的事件(com.lmax.disruptor.RingBuffer通过defult):

final CountDownLatch stopLatch = new CountDownLatch(1);

reactor.on($(topic), new Consumer<Event<Message>>(){

    @Override
    public void accept(Event<Message> t) {
        System.out.println("Hello World");
        stopLatch.countDown();
    }

});
....
stopLatch.await();