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

io.elastic.sailor.impl.SnapshotCallback Maven / Gradle / Ivy

There is a newer version: 4.0.3
Show newest version
package io.elastic.sailor.impl;

import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.name.Named;
import io.elastic.sailor.Constants;
import io.elastic.sailor.ExecutionContext;
import io.elastic.sailor.MessagePublisher;

import javax.json.JsonObject;

public class SnapshotCallback extends CountingCallbackImpl {

    private ExecutionContext executionDetails;
    private MessagePublisher messagePublisher;
    private String routingKey;

    @Inject
    public SnapshotCallback(
            @Assisted ExecutionContext executionDetails,
            MessagePublisher messagePublisher,
            @Named(Constants.ENV_VAR_SNAPSHOT_ROUTING_KEY) String routingKey) {
        this.executionDetails = executionDetails;
        this.messagePublisher = messagePublisher;
        this.routingKey = routingKey;
    }

    @Override
    public void receiveData(Object data) {
        JsonObject snapshot = (JsonObject) data;

        byte[] payload = snapshot.toString().getBytes();

        messagePublisher.publish(routingKey, payload, executionDetails.buildAmqpProperties());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy