Is this Java small pubsub memory implementation correct and effective? We want to provide a simple Redis pub/sub alternative in memory for our software. So we implemented this :
public class MemoryDataBus implements DataBus {
    private final Map&lt;Consumer&lt;Message&gt;, MessageListener&gt; subscribers = new ConcurrentHashMap&lt;&gt;();

    @Override
    public void publish(final Channel channel, final Message message) {
        Message nonNullMessage = requireNonNull(message, &quot;cannot publish a null message&quot;);
        subscribers.values().stream().filter(l -&gt; l.hasSubscribedTo(channel)).forEach(l -&gt; l.accept(nonNullMessage));
    }

    @Override
    public void subscribe(final Consumer&lt;Message&gt; subscriber, final Channel... channels) throws InterruptedException {
        MessageListener listener = new MessageListener(subscriber, channels);
        subscribers.put(subscriber, listener);
        listener.loopUntilShutdown();
    }

    @Override
    public void unsubscribe(Consumer&lt;Message&gt; subscriber) {
        ofNullable(subscribers.remove(subscriber)).ifPresent(l -&gt; {
            l.accept(new ShutdownMessage());
        });
    }

    private static class MessageListener implements Consumer&lt;Message&gt; {
        private final Consumer&lt;Message&gt; subscriber;
        private final LinkedHashSet&lt;Channel&gt; channels;
        final AtomicReference&lt;Message&gt; message = new AtomicReference&lt;&gt;();

        public MessageListener(Consumer&lt;Message&gt; subscriber, Channel... channels) {
            this.subscriber = subscriber;
            this.channels = asSet(channels);
        }

        boolean hasSubscribedTo(Channel channel) {
            return channels.contains(channel);
        }

        @Override
        public void accept(Message message) {
            subscriber.accept(message);
            synchronized (this.message) {
                this.message.set(message);
                this.message.notify();
            }
        }

        boolean shutdownAsked() {
            Message message = this.message.get();
            return message != null &amp;&amp; message.type == Message.Type.SHUTDOWN;
        }

        void loopUntilShutdown() throws InterruptedException {
            synchronized (message) {
                while (!shutdownAsked()) {
                    message.wait();
                }
            }
        }
    }
}

I've removed unnecessary code that brings some noise (logs, couters) the source code is here.
Our unit tests are green, and manual testing shows no regression compared to redis. But as we also know how difficult it is to make a correct thread safe implementation we want to verify with threading experts :

the correctness of it (for example the value returned by shutdownAsked)
if the contention could be improved
if there could be a better implementation of it

PS : must add that the question has been originally posted on SO.
Assuming requireNonNull(...) is java.util.Objects.requireNonNull(...) which throws an exception if null, then there is no need to have a separate local variable for the return value.
Assuming ofNullable(...) is java.util.Optional.ofNullable(...), then I would recommend removing the usage here because the code can be simplified:
// ofNullable(...).ifPresent(l -&gt; ...);
// Simplified:
MyClass result = ...
if (result != null) {
    ...
}

It looks like your locking in MessageListener will cause a deadlock:

MemoryDataBus.subscribe(...) calls loopUntilShutdown which synchronizes on message
MemoryDataBus.publish(...) calls accept which has to wait because lock on message is still held, preventing it from updating message

Edit: No deadlock occurs because Object.wait() is used which releases ownership of the monitor (here field message).