All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.pipservices4.messaging.queues.CallbackMessageReceiver Maven / Gradle / Ivy

The newest version!
package org.pipservices4.messaging.queues;

/**
 * Wraps message callback into IMessageReceiver
 */
public class CallbackMessageReceiver implements IMessageReceiver {
    @FunctionalInterface
    private interface Callback {
        void apply(MessageEnvelope envelope, IMessageQueue queue);
    }

    private final Callback _callback;

    public CallbackMessageReceiver(Callback callback) {
        if (callback == null) {
            throw new Error("Callback cannot be null");
        }

        this._callback = callback;
    }


    /**
     * Receives incoming message from the queue.
     *
     * @param envelope an incoming message
     * @param queue    a queue where the message comes from
     * @see MessageEnvelope
     * @see IMessageQueue
     */
    @Override
    public void receiveMessage(MessageEnvelope envelope, IMessageQueue queue) {
        this._callback.apply(envelope, queue);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy