private MqttPublisherActor(final MqttConnectionFactory factory, final ActorRef mqttClientActor, final boolean dryRun) { this.mqttClientActor = mqttClientActor; this.dryRun = dryRun; final Sink<MqttMessage, CompletionStage<Done>> mqttSink = factory.newSink(); final Pair<ActorRef, CompletionStage<Done>> materializedValues = Source.<MqttMessage>actorRef(100, OverflowStrategy.dropHead()) .map(this::countPublishedMqttMessage) .toMat(mqttSink, Keep.both()) .run(ActorMaterializer.create(getContext())); materializedValues.second().handle(this::reportReadiness); sourceActor = materializedValues.first(); addressMetric = ConnectivityModelFactory.newAddressMetric(ConnectionStatus.OPEN, "Started at " + Instant.now(), 0, null); }
private MqttPublisherActor(final MqttConnectionFactory factory, final ActorRef mqttClientActor, final boolean dryRun) { this.mqttClientActor = mqttClientActor; this.dryRun = dryRun; final Sink<MqttMessage, CompletionStage<Done>> mqttSink = factory.newSink(); final Pair<ActorRef, CompletionStage<Done>> materializedValues = Source.<MqttMessage>actorRef(100, OverflowStrategy.dropHead()) .map(this::countPublishedMqttMessage) .toMat(mqttSink, Keep.both()) .run(ActorMaterializer.create(getContext())); materializedValues.second().handle(this::reportReadiness); sourceActor = materializedValues.first(); addressMetric = ConnectivityModelFactory.newAddressMetric(ConnectionStatus.OPEN, "Started at " + Instant.now(), 0, null); }
public AkkaHubProxy(ActorMaterializer mat) { this.mat = mat; // Obtain a Sink and Source which will publish and receive from the "bus" respectively. Pair<Sink<Object, NotUsed>, Source<Object, NotUsed>> sinkAndSource = MergeHub.of(Object.class, 16) .toMat(BroadcastHub.of(Object.class, 256), Keep.both()) .run(mat); Sink<Object, NotUsed> sink = sinkAndSource.first(); source = sinkAndSource.second().takeWhile((Predicate<Object>) o -> o != Done.getInstance()); //source.runWith(Sink.ignore(), mat); busFlow = Flow.fromSinkAndSource(sink, source) .joinMat(KillSwitches.singleBidi(), Keep.right()); }