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

com.github.linyuzai.event.kafka.publisher.DefaultKafkaEventPublisher Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
package com.github.linyuzai.event.kafka.publisher;

import com.github.linyuzai.event.core.context.EventContext;
import com.github.linyuzai.event.core.error.EventErrorHandler;
import com.github.linyuzai.event.kafka.endpoint.KafkaEventEndpoint;
import lombok.AllArgsConstructor;
import org.springframework.kafka.support.SendResult;
import org.springframework.lang.NonNull;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.util.concurrent.ListenableFutureCallback;

@AllArgsConstructor
public class DefaultKafkaEventPublisher implements KafkaEventPublisher {

    private EventErrorHandler errorHandler;

    @Override
    public void publish(Object event, KafkaEventEndpoint endpoint, EventContext context) {
        ListenableFuture> send = endpoint.getTemplate().sendDefault(event);
        send.addCallback(new ListenableFutureCallback>() {

            @Override
            public void onFailure(@NonNull Throwable e) {
                onPublishFailure(e, endpoint, context);
            }

            @Override
            public void onSuccess(SendResult result) {
                onPublishSuccess(result, endpoint, context);
            }
        });
    }

    public void onPublishSuccess(SendResult result, KafkaEventEndpoint endpoint, EventContext context) {

    }

    public void onPublishFailure(Throwable e, KafkaEventEndpoint endpoint, EventContext context) {
        errorHandler.onError(e, endpoint, context);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy