コード例 #1
0
        private void ReadyForConsumers()
        {
            Receive <IRequestModelConsumer>(requestModel =>
            {
                var model = _conn.CreateModel();

                var rabbitModelConsumerActorRef =
                    Context.System.ActorOf(RabbitModelConsumer.CreateProps(model, requestModel));

                _consumersActorRefs.Add(rabbitModelConsumerActorRef);

                var consumerSupervisedActorRef =
                    Context.System.ActorOf(RabbitActorSupervisor.CreateProps(rabbitModelConsumerActorRef));
                _consumersActorRefs.Add(consumerSupervisedActorRef);

                Sender.Tell(consumerSupervisedActorRef);
            });
            Receive <IRequestModelConsumerWithConcurrencyControl>(requestModel =>
            {
                var model = _conn.CreateModel();

                var rabbitModelConsumerWithConcurrencyControlActorRef =
                    Context.System.ActorOf(RabbitModelConsumerWithConcurrencyControl.CreateProps(model, requestModel));

                _consumersActorRefs.Add(rabbitModelConsumerWithConcurrencyControlActorRef);

                var consumerSupervisedActorRef =
                    Context.System.ActorOf(RabbitActorSupervisor.CreateProps(rabbitModelConsumerWithConcurrencyControlActorRef));
                _consumersActorRefs.Add(consumerSupervisedActorRef);

                Sender.Tell(consumerSupervisedActorRef);
            });
        }
コード例 #2
0
        private void ReadyForPublishers()
        {
            Receive <IRequestModelPublisher>(requestModelPublisher =>
            {
                var model = _conn.CreateModel();

                var rabbitModelPublisherActorRef =
                    Context.System.ActorOf(RabbitModelPublisher.CreateProps(model, requestModelPublisher));

                var supervisedActorRef =
                    Context.System.ActorOf(RabbitActorSupervisor.CreateProps(rabbitModelPublisherActorRef));

                _publishersActorRefs.Add(supervisedActorRef);
                Sender.Tell(supervisedActorRef);
            });
            Receive <IRequestModelPublisherRemoteProcedureCall>(requestModelPublisherRemoteProcedureCall =>
            {
                IActorRef publisherActorRef;
                var model              = _conn.CreateModel();
                var responseQueueName  = Guid.NewGuid().ToString();
                var routingRpcReplyKey = $"{requestModelPublisherRemoteProcedureCall.RoutingKey}###RPCReply";

                if (string.IsNullOrEmpty(requestModelPublisherRemoteProcedureCall.ExchangeName))
                {
                    var modelRemoteProcedureCallPublisherWithDirectQueueConsumer
                        = new ModelRemoteProcedureCallPublisherWithDirectQueueConsumer(
                              requestModelPublisherRemoteProcedureCall, responseQueueName);

                    var rabbitModelRemoteProcedureCallPublisherActorRef = Context.System.ActorOf(
                        RabbitModelRemoteProcedureCallPublisher.CreateProps(model,
                                                                            modelRemoteProcedureCallPublisherWithDirectQueueConsumer));

                    publisherActorRef = rabbitModelRemoteProcedureCallPublisherActorRef;
                }
                else
                {
                    var modelRemoteProcedureCallPublisherWithTopicExchangeConsumer
                        = new ModelRemoteProcedureCallPublisherWithTopicExchangeConsumer(
                              requestModelPublisherRemoteProcedureCall,
                              new PublicationAddress(ExchangeType.Topic,
                                                     requestModelPublisherRemoteProcedureCall.ExchangeName, routingRpcReplyKey));

                    var rabbitModelRemoteProcedureCallPublisherActorRef = Context.System.ActorOf(
                        RabbitModelRemoteProcedureCallPublisher.CreateProps(model,
                                                                            modelRemoteProcedureCallPublisherWithTopicExchangeConsumer));

                    publisherActorRef = rabbitModelRemoteProcedureCallPublisherActorRef;
                }

                var publisherSupervisedActorRef =
                    Context.System.ActorOf(RabbitActorSupervisor.CreateProps(publisherActorRef));

                var requestModelConsumer = new RequestModelConsumer(
                    requestModelPublisherRemoteProcedureCall.ExchangeName,
                    responseQueueName,
                    routingRpcReplyKey,
                    publisherSupervisedActorRef);

                var rabbitModelConsumerActorRef = // TODO need to add supervisor for consumer too
                                                  Context.System.ActorOf(RabbitModelConsumer.CreateProps(model, requestModelConsumer));
                var consumerSupervisedActorRef =
                    Context.System.ActorOf(RabbitActorSupervisor.CreateProps(rabbitModelConsumerActorRef));

                consumerSupervisedActorRef.Tell("start consuming"); // TODO restart consumers on resume

                _consumersActorRefs.Add(consumerSupervisedActorRef);
                _publishersActorRefs.Add(publisherSupervisedActorRef);
                Sender.Tell(publisherSupervisedActorRef);
            });
        }