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

de.otto.synapse.subscription.SubscriptionInterceptor Maven / Gradle / Ivy

Go to download

A library used at otto.de to implement Spring Boot based event-sourcing microservices.

There is a newer version: 0.33.1
Show newest version
package de.otto.synapse.subscription;

import de.otto.synapse.endpoint.MessageInterceptor;
import de.otto.synapse.endpoint.sender.MessageSenderEndpoint;
import de.otto.synapse.message.TextMessage;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class SubscriptionInterceptor implements MessageInterceptor {
    private final Subscription subscription;
    private final MessageSenderEndpoint targetSenderEndpoint;

    public SubscriptionInterceptor(final Subscription subscription,
                                   final MessageSenderEndpoint targetSenderEndpoint) {
        this.subscription = subscription;
        this.targetSenderEndpoint = targetSenderEndpoint;
    }

    Subscription getSubscription() {
        return subscription;
    }

    @Nullable
    @Override
    public TextMessage intercept(@Nonnull TextMessage message) {
        if (subscription.getSubscribedEntities().contains(message.getKey().partitionKey())) {
            targetSenderEndpoint.send(message);
        }
        return message;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy