Ejemplo n.º 1
0
        private void CreateDocumentOnEachNode(SubscriptionMessage subscription)
        {
            foreach (var member in cluster.ReadView.Members)
            {
                var props =
                    Props.Create(
                        () =>
                            new EventSubscribingAtomDocumentActor(new AtomDocumentSettings()));

                var nameOfActorToDeployOnNode = $"atomActor_{member.Address.GetHashCode()}_{subscriptionMessage.SubscriptionId.Id}";

                LogTraceInfo($"About to deploy actor with name {nameOfActorToDeployOnNode} onto node {member.Address}");

                var atomDocument =
                     Context.ActorOf(
                         props
                         .WithDeploy(
                             new Deploy(
                                 new RemoteScope(member.Address))), nameOfActorToDeployOnNode);

                atomDocument.Tell(
                    new CreateAtomDocumentCommand(
                        "", "", headDocumentIdForFeed, Context.Self));

                documentActors.Add(atomDocument);

                LogTraceInfo($"Subscription Actor deployed with address {atomDocument.Path} ");
            }
        }
        public HttpResponseMessage Put(SubscribeMessage subscribeMessage)
        {
            var subscriptionMessage = new SubscriptionMessage(new AtomNotificationChannel(), new SubscriptionId(subscribeMessage.SubscriptionId), new AllEventMatcher());
            eventShardedSubscriber.CreateSubscription(subscriptionMessage);

            var response = new HttpResponseMessage(HttpStatusCode.Accepted);
            response.Content = new StringContent(JsonConvert.SerializeObject(string.Empty, jsonSerializerSettings), Encoding.UTF8, "application/vnd.tesco.eventSubscription+json");
            return response;
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            var akkaSystemName = GetValueFromCommandLine("akkaSystemName", args);
            var seedNodes = GetValueFromCommandLine("seedNodes", args);
            var akkaPortNumber = GetIntFromCommandLine(args, "portNumber");
            var entriesPerDocument = GetIntFromCommandLine(args, "entriesPerDocument");
            var persistence = GetValueFromCommandLine("persistence", args);

            var eventSystemHost = new BurstingEventSystemHost(akkaPortNumber, akkaSystemName, persistence, seedNodes, 3601, entriesPerDocument);
            var EventRaisingController = eventSystemHost.Get<EventRaisingController>();
            eventSystemHost.Start();

            Console.Title = string.Join(" ", args);
            Thread.Sleep(TimeSpan.FromSeconds(5));

            var subscriptionId = new SubscriptionId(GetValueFromCommandLine("subscriptionId", args));

            if (!string.IsNullOrEmpty(subscriptionId.Id))
            {
                Console.WriteLine("Getting subscriptionId");
                ISubscriptionManager shardedSubscriptionManager = eventSystemHost.Get<ISubscriptionManager>();
                
                var currentSubscription =
                    shardedSubscriptionManager.GetSubscriptionDetails(new SubscriptionQuery(subscriptionId)).Result;

                if (currentSubscription is NullSubscription)
                {
                    _subscriptionMessage = new SubscriptionMessage(
                        new AtomNotificationChannel(),
                        subscriptionId,
                        new AllEventMatcher());

                    shardedSubscriptionManager.CreateSubscription(_subscriptionMessage);
                    Thread.Sleep(1000);

                }

                Thread.Sleep(1000);

                IEventPublisher notifier = eventSystemHost.Get<IEventPublisher>();

                var i = 0;
                while (true)
                {
                    notifier.PublishMessage(new DummyDomainEvent(akkaPortNumber + ":" + (++i).ToString()));
                    LogManager.GetLogger("").Info("Raising event with id" + i);
                }
            }

            while (true)
            {
                Thread.Sleep(TimeSpan.FromSeconds(5));
            }
        }
        public async Task CreateANewSubscriptionIfTheSubscriptionDoesntExist()
        {
            var subscriptionMessage = new SubscriptionMessage(
                new LocalEventNotificationChannel(), 
                new SubscriptionId(Guid.NewGuid().ToString()),
                new AllEventMatcher());

            _shardedSubscriptionManager.CreateSubscription(subscriptionMessage);

            var queryMessage = new SubscriptionQuery(subscriptionMessage.SubscriptionId);
            var result = await _shardedSubscriptionManager.GetSubscriptionDetails(queryMessage);
            Assert.AreEqual(subscriptionMessage, result);
        }
Ejemplo n.º 5
0
        private void Process(SubscriptionMessage subscription)
        {
            LoggingAdapter.Debug("Creating a subscription with id " + subscription.SubscriptionId.Id);

            if (subscriptionMessage != null)
            {
                LoggingAdapter.Debug("Dumping out of subscription for " + subscription.SubscriptionId.Id +
                    " as subscription Id wasn't null ");

                return;
            }

            LoggingAdapter.Debug("Creating docs for " + subscription.SubscriptionId.Id);

            var notifier = notifierFactory.GetNotifierFor(subscription.NotificationChannel.GetType());
            notifier.Create(subscription);

            LoggingAdapter.Debug("Persisting " + subscription.SubscriptionId.Id);
            Persist(subscription, MutateInternalState);
        }
Ejemplo n.º 6
0
 private void CreateFeedActor(SubscriptionMessage subscription)
 {
     LogTraceInfo($"Creating atom subscription actor");
     CreateDocumentOnEachNode(subscription);
     LogTraceInfo("Created atom subscription actor");
 }
Ejemplo n.º 7
0
 private void Process(SubscriptionMessage subscription)
 {
     Persist(subscription, MutateInternalState);
 }
Ejemplo n.º 8
0
        private void MutateInternalState(SubscriptionMessage subscription)
        {
            this.subscriptionMessage = subscription;

            headDocumentIdForFeed = new DocumentId(subscription.SubscriptionId.Id, 0);

            CreateFeedActor(subscription);
        }
Ejemplo n.º 9
0
 public void Create(SubscriptionMessage message)
 {
 }
Ejemplo n.º 10
0
 public void Notify(SubscriptionMessage message, DomainEvent eventToNotify)
 {
     EventNotifiedWith = eventToNotify;
     EventReceived.Set();
 }
Ejemplo n.º 11
0
 public void CreateSubscription(SubscriptionMessage subscriptionMessage)
 {
     SubscriptionActorRef.Tell(subscriptionMessage);
 }
Ejemplo n.º 12
0
        private void MutateInternalState(SubscriptionMessage message)
        {
            this.subscriptionMessage = message;
            LoggingAdapter.Debug("Persist finished " + subscriptionMessage.SubscriptionId.Id);

            SubscribeToClusterWideBroadcastDomainEvent();
        }
Ejemplo n.º 13
0
 public void Create(SubscriptionMessage message)
 {
     factory.GetActorRef().Tell(new AtomFeedCreationCommand("Title", "Author", new FeedId(message.SubscriptionId.Id), null));
 }
Ejemplo n.º 14
0
 public void Notify(SubscriptionMessage message, DomainEvent eventToNotify)
 {
     factory.GetActorRef().Tell(new EventWithSubscriptionNotificationMessage(message.SubscriptionId, eventToNotify));
 }