Exemple #1
0
        public override object Create(MaterializationContext context, out IActorRef materializer)
        {
            var subscriberRef = ActorMaterializer.Downcast(context.Materializer).ActorOf(context, _props);

            materializer = subscriberRef;
            return(ActorSubscriber.Create <TIn>(subscriberRef));
        }
        public void ActorPublisher_should_work_in_a_GraphDsl()
        {
            var materializer = Sys.Materializer();
            var probe1       = CreateTestProbe();
            var probe2       = CreateTestProbe();

            var senderRef1 = ActorOf(Sender.Props);
            var source1    = Source.FromPublisher(ActorPublisher.Create <int>(senderRef1))
                             .MapMaterializedValue(_ => senderRef1);

            var sink1 = Sink.FromSubscriber(ActorSubscriber.Create <string>(ActorOf(Receiver.Props(probe1.Ref))))
                        .MapMaterializedValue(_ => probe1.Ref);
            var sink2 = Sink.ActorSubscriber <string>(Receiver.Props(probe2.Ref))
                        .MapMaterializedValue(_ => probe2.Ref);
            var senderRef2 = RunnableGraph.FromGraph(GraphDsl.Create(
                                                         Source.ActorPublisher <int>(Sender.Props),
                                                         (builder, source2) =>
            {
                var merge = builder.Add(new Merge <int, int>(2));
                var bcast = builder.Add(new Broadcast <string>(2));

                builder.From(source1).To(merge.In(0));
                builder.From(source2.Outlet).To(merge.In(1));

                builder.From(merge.Out).Via(Flow.Create <int>().Select(i => i.ToString())).To(bcast.In);

                builder.From(bcast.Out(0)).Via(Flow.Create <string>().Select(s => s + "mark")).To(sink1);
                builder.From(bcast.Out(1)).To(sink2);

                return(ClosedShape.Instance);
            })).Run(materializer);

            // the scala test is wrong
            const int noOfMessages = 10;

            for (var i = 0; i < noOfMessages; i++)
            {
                senderRef1.Tell(i);
                senderRef2.Tell(i + noOfMessages);
            }

            var probe1Messages = new List <string>(noOfMessages * 2);
            var probe2Messages = new List <string>(noOfMessages * 2);

            for (var i = 0; i < noOfMessages * 2; i++)
            {
                probe1Messages.Add(probe1.ExpectMsg <string>());
                probe2Messages.Add(probe2.ExpectMsg <string>());
            }
            probe1Messages.Should().BeEquivalentTo(Enumerable.Range(0, noOfMessages * 2).Select(i => i + "mark"));
            probe2Messages.Should().BeEquivalentTo(Enumerable.Range(0, noOfMessages * 2).Select(i => i.ToString()));
        }
Exemple #3
0
        public override ISubscriber <int?> CreateSubscriber()
        {
            var props = Props.Create(() => new StrategySubscriber(OneByOneRequestStrategy.Instance));

            return(ActorSubscriber.Create <int?>(System.ActorOf(props.WithDispatcher("akka.test.stream-dispatcher"))));
        }