Skip to content

Improve Interceptor APIs to supprt java8 lambda style #35

@liyue2008

Description

@liyue2008

For the intercepter APIs .

io.openmessaging.interceptor.ProducerInterceptor
io.openmessaging.interceptor.ConsumerInterceptor

It would be convenient for user to support java8 lambda style, that also make code more elegant.
Separating the preSend and the postSend method gives user more chorices.

Take a look the following example code:

Before:

        ProducerInterceptor interceptor = new ProducerInterceptor() {
            @Override
            public void preSend(Message message, Context attributes) {
                System.out.println("PreSend message: " + message);
            }

            @Override
            public void postSend(Message message, Context attributes) {
                System.out.println("PostSend message: " + message);
            }
        };
        producer.addInterceptor(interceptor);

After:

        producer.addPreSendInterceptor((message, attributes) ->
                System.out.println("PreSend message: " + message));

        producer.addPostSendInterceptor((message, attributes) ->
                System.out.println("PostSend message: " + message));

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions