Giter VIP home page Giter VIP logo

Comments (2)

duhenglucky avatar duhenglucky commented on May 21, 2024

IMO, the lambda expression is only syntactic sugar, and we shouldn't binding with a certain Java version so users can write code in a way they like.

from openmessaging-java.

liyue2008 avatar liyue2008 commented on May 21, 2024

Binding the API to java 8 is not a must to support lambda style.
To achive this propose, only a sinlge method message interceptor interface will be introduced.

/**
 * A {@code Interceptor} is used to intercept send or consume operations.
 * <p>
 * The interceptor is able to view or modify the message being transmitted and collect
 * the send record.
 *
 * @version OMS 1.0.0
 * @since OMS 1.0.0
 */
public interface MessageInterceptor {
    /**
     * Invoked during send or consume operations.
     *
     * @param message the message is actually processing.
     * @param attributes the extensible attributes delivered to the intercept thread.
     */
    void onMessage(Message message, Context attributes);
}

For java versions before 8, The old way of creating an implementation class is still available.
Code chould be like this:

MessageInterceptor preSendInterceptor;
producer.addPreSendInterceptor(preSendInterceptor = new MessageInterceptor() {
    @Override
    public void onMessage(Message message, Context attributes) {
        System.out.println("PreSend message: " + message);
    }
});
producer.removeInterceptor(preSendInterceptor);

from openmessaging-java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.