コード例 #1
0
        public EchoConnection()
        {
            var graph = RunnableGraph.FromGraph(GraphDsl.Create(b =>
            {
                var source = Source.Collect(x => x as Received).Select(x => Signals.Broadcast(x.Data));
                var f1     = Flow.Create <ISignalRResult>().Select(x => x.Data);
                var f2     = Flow.Create <string>().Select(x => new Uri(x)).Recover(exception =>
                {
                    if (exception is System.UriFormatException)
                    {
                        return(new Uri(null));
                    }
                    throw new Exception("error");
                });
                var f3          = Flow.Create <Uri>().Select(x => Signals.Broadcast(x.ToString()));
                var f4          = Flow.Create <string>().Select(x => Signals.Broadcast(x));
                var merge       = b.Add(new Merge <ISignalRResult>(2));
                var crawlerFlow = b.Add(Crawler.MyCrawler());
                var broadcast   = b.Add(new Broadcast <string>(2));
                b.From(source).Via(f1).Via(broadcast).Via(f4).Via(merge).To(this.Sink);
                b.From(broadcast).Via(f2).Via(crawlerFlow).Via(f3).Via(merge);
                return(ClosedShape.Instance);
            }));

            graph.Run(App.Materializer);
        }
コード例 #2
0
 public EchoConnection()
 {
     this.Source
     .Collect(x => x as Received)
     .Select(x => Signals.Broadcast(x.Data))
     .To(this.Sink)
     .Run(App.Materializer);
 }
コード例 #3
0
ファイル: EchoStream.cs プロジェクト: zkdlu/AkkaDotModule
 public EchoStream(IHubClients clients, ConnectionSourceSettings sourceSettings = null, ConnectionSinkSettings sinkSettings = null)
     : base(clients, sourceSettings, sinkSettings)
 {
     Source
     .Collect(x => x as Received)
     // Tell everyone
     .Select(x => Signals.Broadcast(x.Data))
     // Or tell everyone else, except one-self
     // .Select(x => Signals.Broadcast(x.Data, new[] { x.Request.ConnectionId }))
     // Or just send it back to one-self
     // .Select(x => Signals.Send(x.Request.ConnectionId, x.Data.Payload))
     .To(Sink)
     .Run(AkkaLoad.Materializer);
 }
コード例 #4
0
        public async Task Websocket_connection_should_be_able_to_send_data()
        {
            // Arrange
            var tcs = new TaskCompletionSource <object>();

            await ConnectAsync(msg => tcs.SetResult(msg));

            // Act
            _toClient.SendNext(Signals.Broadcast("payload"));

            // Assert
            var result = await tcs.Task;

            result.Should().Be("payload");
        }