Exemplo n.º 1
0
 public override IPublisher <ByteString> CreatePublisher(long elements)
 {
     return(StreamConverters.FromInputStream(() => new InputStream())
            .WithAttributes(ActorAttributes.CreateDispatcher("akka.test.stream-dispatcher"))
            .Take(elements)
            .RunWith(Sink.AsPublisher <ByteString>(false), Materializer));
 }
Exemplo n.º 2
0
        //FIXME: overriding dispatcher should be made available with dispatcher alias support in materializer (#17929)
        public void FileSource_should_should_allow_overriding_the_dispather_using_Attributes()
        {
            var sys          = ActorSystem.Create("dispatcher-testing", Utils.UnboundedMailboxConfig);
            var materializer = sys.Materializer();

            try
            {
                var p = FileIO.FromFile(ManyLines())
                        .WithAttributes(ActorAttributes.CreateDispatcher("akka.actor.default-dispatcher"))
                        .RunWith(this.SinkProbe <ByteString>(), materializer);
                (materializer as ActorMaterializerImpl).Supervisor.Tell(StreamSupervisor.GetChildren.Instance, TestActor);

                var actorRef = ExpectMsg <StreamSupervisor.Children>().Refs.First(r => r.Path.ToString().Contains("File"));
                try
                {
                    Utils.AssertDispatcher(actorRef, "akka.actor.default-dispatcher");
                }
                finally
                {
                    p.Cancel();
                }
            }
            finally
            {
                Shutdown(sys);
            }
        }
Exemplo n.º 3
0
        public void SynchronousFileSink_should_allow_overriding_the_dispatcher_using_Attributes()
        {
            this.AssertAllStagesStopped(() =>
            {
                TargetFile(f =>
                {
                    var sys          = ActorSystem.Create("dispatcher_testing", Utils.UnboundedMailboxConfig);
                    var materializer = ActorMaterializer.Create(sys);

                    try
                    {
                        //hack for Iterator.continually
                        Source.FromEnumerator(() => Enumerable.Repeat(_testByteStrings.Head(), Int32.MaxValue).GetEnumerator())
                        .To(FileIO.ToFile(f))
                        .WithAttributes(ActorAttributes.CreateDispatcher("akka.actor.default-dispatcher"));
                        //.Run(materializer);

                        ((ActorMaterializerImpl)materializer).Supervisor.Tell(StreamSupervisor.GetChildren.Instance, TestActor);
                        var actorRef = ExpectMsg <StreamSupervisor.Children>().Refs.First(@ref => @ref.Path.ToString().Contains("File"));
                        Utils.AssertDispatcher(actorRef, "akka.actor.default-dispatcher");
                    }
                    finally
                    {
                        Shutdown(sys);
                    }
                });
            }, _materializer);
        }
Exemplo n.º 4
0
        private async Task <AssociationHandle> StartClient(Address remoteAddress)
        {
            if (InternalTransport != TransportMode.Tcp)
            {
                throw new NotSupportedException("Currently Akka.Streams server supports only TCP transport mode.");
            }

            var addressFamily = Settings.DnsUseIpv6 ? AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork;


            var socketAddress = RemotingAddressHelpers.AddressToSocketAddress(remoteAddress);

            socketAddress = await MapEndpointAsync(socketAddress).ConfigureAwait(false);

            // TODO: socket options
            var clientSource = System.TcpStream().OutgoingConnection(socketAddress, connectionTimeout: Settings.ConnectTimeout)
                               .AddAttributes(ActorAttributes.CreateDispatcher(System.Settings.Config.GetString("akka.remote.use-dispatcher")));

            var joined = clientSource.JoinMaterialized(
                StreamTransportFlows.OutboundConnectionHandler(this, remoteAddress, socketAddress), (connectTask, associate) => (connectTask, associate))
                         .Join(Flow.Create <Google.Protobuf.ByteString>().Where(_ => true))
                         .Run(StreamMaterializer);

            await joined.connectTask.ConfigureAwait(false);

            return(await joined.associate.ConfigureAwait(false));
        }
Exemplo n.º 5
0
 private static Flow <IEnvelope <K, V, TPassThrough>, IResults <K, V, TPassThrough>, NotUsed> FlowWithDispatcher <K, V, TPassThrough>(
     ProducerSettings <K, V> settings,
     Flow <IEnvelope <K, V, TPassThrough>, IResults <K, V, TPassThrough>, NotUsed> flow)
 {
     return(string.IsNullOrEmpty(settings.DispatcherId)
         ? flow
         : flow.WithAttributes(ActorAttributes.CreateDispatcher(settings.DispatcherId)));
 }
Exemplo n.º 6
0
        public void A_Flow_can_have_an_op_with_a_different_dispatcher()
        {
            var flow = Flow.Create <int>()
                       .Select(x => SentThreadNameTo(TestActor, x))
                       .WithAttributes(ActorAttributes.CreateDispatcher("my-dispatcher1"));

            Source.Single(1).Via(flow).To(Sink.Ignore <int>()).Run(Materializer);

            ExpectMsg <string>().Should().Contain("my-dispatcher1");
        }
Exemplo n.º 7
0
        public void ActorPublisher_should_use_dispatcher_from_props()
        {
            var materializer = Sys.Materializer();
            var s            = this.CreateManualSubscriberProbe <string>();
            var actorRef     = Source.ActorPublisher <string>(TestPublisher.Props(TestActor, useTestDispatcher: false).WithDispatcher("my-dispatcher1"))
                               .WithAttributes(ActorAttributes.CreateDispatcher("my-dispatcher2"))
                               .To(Sink.FromSubscriber(s))
                               .Run(materializer);

            actorRef.Tell(ThreadName.Instance);
            ExpectMsg <string>().Should().Contain("my-dispatcher1");
        }
Exemplo n.º 8
0
        /// <summary>
        /// Publish records to Kafka topics and then continue the flow. Possibility to pass through a message, which
        /// can for example be a <see cref="CommitableOffset"/> that can be committed later in the flow.
        /// </summary>
        public static Flow <MessageAndMeta <TKey, TValue>, DeliveryReport <TKey, TValue>, NotUsed> PlainFlow <TKey, TValue>(ProducerSettings <TKey, TValue> settings, IProducer <TKey, TValue> producer)
        {
            var flow = Flow.FromGraph(new ProducerStage <TKey, TValue>(
                                          settings,
                                          closeProducerOnStop: false,
                                          producerProvider: () => producer))
                       .SelectAsync(settings.Parallelism, x => x);

            return(string.IsNullOrEmpty(settings.DispatcherId)
                ? flow
                : flow.WithAttributes(ActorAttributes.CreateDispatcher(settings.DispatcherId)));
        }
Exemplo n.º 9
0
        private void StartServer()
        {
            if (InternalTransport != TransportMode.Tcp)
            {
                throw new NotSupportedException("Currently Akka.Streams server supports only TCP transport mode.");
            }

            var addressFamily = Settings.DnsUseIpv6 ? AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork;

            var serverSource = System.TcpStream().Bind(Settings.Hostname, Settings.Port, Settings.Backlog)
                               .AddAttributes(ActorAttributes.CreateDispatcher(System.Settings.Config.GetString("akka.remote.use-dispatcher")));

            serverSource.RunForeach(connection =>
            {
                connection.Flow.Join(StreamTransportFlows.OutboundConnectionHandler(Settings, connection.));
            });
        }
Exemplo n.º 10
0
        public void A_Flow_can_have_multiple_levels_of_nesting()
        {
            var probe1 = CreateTestProbe();
            var probe2 = CreateTestProbe();

            var flow1 =
                Flow.Create <int>()
                .Select(x => SentThreadNameTo(probe1.Ref, x))
                .WithAttributes(ActorAttributes.CreateDispatcher("my-dispatcher1"));

            var flow2 = flow1
                        .Via(Flow.Create <int>().Select(x => SentThreadNameTo(probe2.Ref, x)))
                        .WithAttributes(ActorAttributes.CreateDispatcher("my-dispatcher2"));

            Source.Single(1).Via(flow2).To(Sink.Ignore <int>()).Run(Materializer);

            probe1.ExpectMsg <string>().Should().Contain("my-dispatcher1");
            probe2.ExpectMsg <string>().Should().Contain("my-dispatcher2");
        }
Exemplo n.º 11
0
        public void A_Flow_can_have_an_op_section_with_different_dispatcher_and_name()
        {
            var defaultDispatcher = CreateTestProbe();
            var customDispatcher  = CreateTestProbe();

            var f1 = Flow.Create <int>().Select(x => SentThreadNameTo(defaultDispatcher.Ref, x));
            var f2 =
                Flow.Create <int>()
                .Select(x => SentThreadNameTo(defaultDispatcher.Ref, x))
                .Select(x => x)
                .WithAttributes(
                    ActorAttributes.CreateDispatcher("my-dispatcher")
                    .And(Attributes.CreateName("seperate-dispatcher")));

            Source.From(new[] { 0, 1, 2 }).Via(f1).Via(f2).RunWith(Sink.Ignore <int>(), Materializer);

            defaultDispatcher.ReceiveN(3).ForEach(o => o.ToString().Should().Contain("akka.test.stream-dispatcher"));

            customDispatcher.ReceiveN(3).ForEach(o => o.ToString().Should().Contain("my-dispatcher"));
        }