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

org.jetlinks.rule.engine.defaults.EventBusEventOutput Maven / Gradle / Ivy

There is a newer version: 1.2.2
Show newest version
package org.jetlinks.rule.engine.defaults;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.jetlinks.rule.engine.api.EventBus;
import org.jetlinks.rule.engine.api.RuleConstants;
import org.jetlinks.rule.engine.api.RuleData;
import org.jetlinks.rule.engine.api.task.Output;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono;

@Slf4j
@AllArgsConstructor
public class EventBusEventOutput implements Output {

    private final String instanceId;

    private final EventBus eventBus;

    @Getter
    private final String event;

    private final String sourceNode;

    @Override
    public Mono write(Publisher dataStream) {
        return eventBus.publish(createTopic(sourceNode), dataStream)
                .thenReturn(true);
    }

    @Override
    public Mono write(String nodeId, Publisher data) {
        return eventBus.publish(createTopic(nodeId), data).then();
    }

    private String createTopic(String node) {
        return RuleConstants.Topics.input(instanceId, node);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy