Пример #1
0
 public LogsSourceActor()
 {
     Receive <RequestLogs>(req =>
     {
         var streamLogs = Source.From(Enumerable.Range(1, 5)).Select(i => i.ToString());
         streamLogs.ToMaterialized(StreamRefs.SourceRef <string>(), Keep.Right)
         .Run(Context.System.Materializer())
         .PipeTo(Sender, success: sourceRef => new LogsOffer(req.StreamId, sourceRef));
     });
 }
Пример #2
0
 public DataSource()
 {
     Receive <RequestLogs>(request =>
     {
         // create a source
         StreamLogs(request.StreamId)
         // materialize it using stream refs
         .RunWith(StreamRefs.SourceRef <string>(), Context.System.Materializer())
         // and send to sender
         .PipeTo(Sender, success: sourceRef => new LogsOffer(request.StreamId, sourceRef));
     });
 }
Пример #3
0
        public ProducerActor(string data)
        {
            _data = data;
            Receive <RequestStream>(request =>
            {
                // create a source
                StreamLogs()
                // materialize it using stream refs
                .RunWith(StreamRefs.SourceRef <string>(), Context.System.Materializer())
                // and send to sender
                .PipeTo(Sender, success: sourceRef => new EnvelopedStream(sourceRef));
            });

            Receive <string>(_ => Sender.Tell("pong"));
        }
Пример #4
0
        public async Task StreamRefThrowsSubscriptionTimeout()
        {
            var ex = await Assert.ThrowsAsync <RemoteStreamRefActorTerminatedException>(async delegate
            {
                TimeSpan subscriptionTimeout = TimeSpan.FromSeconds(3);

                var sourceRef = await Source
                                .Single("NeverConsumedMsg")
                                .RunWith(StreamRefs.SourceRef <string>()
                                         .AddAttributes(StreamRefAttributes.CreateSubscriptionTimeout(subscriptionTimeout)),
                                         Sys.Materializer());

                Task.Delay(subscriptionTimeout + TimeSpan.FromSeconds(1)).Wait();

                await sourceRef.Source.RunWith(Sink.Ignore <string>(), Sys.Materializer());
            });

            // ex.InnerException.Should().BeOfType<StreamRefSubscriptionTimeoutException>(); // null inside
        }
Пример #5
0
        public DataSource()
        {
            TimeSpan throttle = TimeSpan.FromMilliseconds(1);

            string RegistryConnectionString = "akka.tcp://ReceiverActorSystem@" + serverURL + ":" + serverPort + "/user/DataReceiverActor";

            ColourConsole.WriteLineMagenta("Sending ConnectMessage");
            ConnectMessage requestAccess = Context.ActorSelection(RegistryConnectionString).Ask <ConnectMessage>(new ConnectMessage(Self)).Result;//Changes

            DataReceiverActorRef = requestAccess.ActorRef;

            Receive <RequestLogs>(request =>
            {
                ColourConsole.WriteLineMagenta("Sending RequestLogs");
                // create a source
                StreamLogs(request.StreamId)
                //Throttle outbound stream
                .Throttle(1, throttle, 1, ThrottleMode.Shaping)
                // materialize it using stream refs
                .RunWith(StreamRefs.SourceRef <string>(), Context.System.Materializer())
                // and send to sink
                .PipeTo(DataReceiverActorRef, success: sourceRef => new LogsOffer(request.StreamId, sourceRef));    //DataReceiverActorRef was Sender
            });
        }
Пример #6
0
        protected override bool Receive(object message)
        {
            switch (message)
            {
            case "give":
            {
                /*
                 * Here we're able to send a source to a remote recipient
                 * For them it's a Source; for us it is a Sink we run data "into"
                 */
                var source = Source.From(new[] { "hello", "world" });
                var aref   = source.RunWith(StreamRefs.SourceRef <string>(), _materializer);
                aref.PipeTo(Sender);
                return(true);
            }

            case "give-infinite":
            {
                var source = Source.From(Enumerable.Range(1, int.MaxValue).Select(i => "ping-" + i));
                var t      = source.ToMaterialized(StreamRefs.SourceRef <string>(), Keep.Right).Run(_materializer);
                t.PipeTo(Sender);
                return(true);
            }

            case "give-fail":
            {
                var r = Source.Failed <string>(new Exception("Boom!"))
                        .RunWith(StreamRefs.SourceRef <string>(), _materializer);
                r.PipeTo(Sender);
                return(true);
            }

            case "give-complete-asap":
            {
                var r = Source.Empty <string>().RunWith(StreamRefs.SourceRef <string>(), _materializer);
                r.PipeTo(Sender);
                return(true);
            }

            case "give-subscribe-timeout":
            {
                var r = Source.Repeat("is anyone there?")
                        .ToMaterialized(StreamRefs.SourceRef <string>(), Keep.Right)
                        .WithAttributes(StreamRefAttributes.CreateSubscriptionTimeout(TimeSpan.FromMilliseconds(500)))
                        .Run(_materializer);
                r.PipeTo(Sender);
                return(true);
            }

            case "receive":
            {
                /*
                 * We write out code, knowing that the other side will stream the data into it.
                 * For them it's a Sink; for us it's a Source.
                 */
                var sink = StreamRefs.SinkRef <string>().To(Sink.ActorRef <string>(_probe, "<COMPLETE>"))
                           .Run(_materializer);
                sink.PipeTo(Sender);
                return(true);
            }

            case "receive-ignore":
            {
                var sink = StreamRefs.SinkRef <string>().To(Sink.Ignore <string>()).Run(_materializer);
                sink.PipeTo(Sender);
                return(true);
            }

            case "receive-subscribe-timeout":
            {
                var sink = StreamRefs.SinkRef <string>()
                           .WithAttributes(StreamRefAttributes.CreateSubscriptionTimeout(TimeSpan.FromMilliseconds(500)))
                           .To(Sink.ActorRef <string>(_probe, "<COMPLETE>"))
                           .Run(_materializer);
                sink.PipeTo(Sender);
                return(true);
            }

            case "receive-32":
            {
                //                    var t = StreamRefs.SinkRef<string>()
                //                        .ToMaterialized(TestSink.SinkProbe<string>(Context.System), Keep.Both)
                //                        .Run(_materializer);
                //
                //                    var sink = t.Item1;
                //                    var driver = t.Item2;
                //                    Task.Run(() =>
                //                    {
                //                        driver.EnsureSubscription();
                //                        driver.Request(2);
                //                        driver.ExpectNext();
                //                        driver.ExpectNext();
                //                        driver.ExpectNoMsg(TimeSpan.FromMilliseconds(100));
                //                        driver.Request(30);
                //                        driver.ExpectNextN(30);
                //
                //                        return "<COMPLETED>";
                //                    }).PipeTo(_probe);

                return(true);
            }

            default: return(false);
            }
        }