【问题标题】:Reactor, failed to load class "org.slf4j.impl.StaticLoggerBinder"反应堆,无法加载类“org.slf4j.impl.StaticLoggerBinder”
【发布时间】:2014-09-13 12:19:30
【问题描述】:

我已经开始玩 Reactor,但我的第一个活动遇到了麻烦:D

按照github中的example,我尝试写一个“hello world”但没有成功...

有什么问题?

代码:

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

【问题讨论】:

    标签: java reactor project-reactor


    【解决方案1】:

    别忘了ReactorReactive Streams 范式的一个实现,所有的一切都是async

    因此,您的 reactor.notify(topic, Event.wrap(event)); 是一个事件,在单独的 Thread 中发布到 EventRouter 的某些 handler

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

    或在main 的and 中添加Thread.sleep(1000); 或使用CoutDownLatch 等待来自该Reactor 线程的事件(默认为com.lmax.disruptor.RingBuffer):

    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();
    

    【讨论】:

    • 非常感谢,我认为没有任何配置它是反应器的同步版本(我在某处读过它)。现在可以了!
    猜你喜欢
    • 2011-12-18
    • 2011-11-17
    • 2017-02-19
    • 1970-01-01
    • 2012-08-08
    • 2016-10-04
    相关资源
    最近更新 更多