Examples of ReplayingCluster


Examples of org.axonframework.eventhandling.replay.ReplayingCluster

        //we create a ReplayingCluster, which wraps that actual cluster that listeners will be subscribed to
        // since we don't need transactions in this in-memory sample, we use a NoTransactionManager
        // the 0 means we do not need any "intermediate commit" during the replay.
        // The BackloggingIncomingMessageHandler will make sure any events published while replaying are backlogged
        // and postponed until the replay is done.
        ReplayingCluster replayingCluster = new ReplayingCluster(new SimpleCluster("simple"), eventStore,
                                                                 new NoTransactionManager(), 0,
                                                                 new BackloggingIncomingMessageHandler());

        // we initialize an event bus that contains our replaying cluster
        EventBus eventBus = new ClusteringEventBus(new DefaultClusterSelector(replayingCluster));

        // we subscribe our two listeners to the Event Bus
        AnnotationEventListenerAdapter.subscribe(new ThreadPrintingEventListener(), eventBus);
        AnnotationEventListenerAdapter.subscribe(new AnotherThreadPrintingEventListener(), eventBus);

        // we append some events to simulate a full event store
        final DomainEventMessage[] domainEventMessages = {
                new GenericDomainEventMessage<ToDoItemCreatedEvent>(
                        "todo1", 0, new ToDoItemCreatedEvent("todo1", "Need to do something")),
                new GenericDomainEventMessage<ToDoItemCreatedEvent>(
                        "todo2", 0, new ToDoItemCreatedEvent("todo2", "Another thing to do")),
                new GenericDomainEventMessage<ToDoItemCompletedEvent>("todo2", 0, new ToDoItemCompletedEvent("todo2"))
        };
        eventStore.appendEvents("mock", new SimpleDomainEventStream(domainEventMessages));

        // we create an executor service with a single thread and start the replay as an asynchronous process
        ExecutorService executor = Executors.newSingleThreadExecutor();
        Future<Void> future = replayingCluster.startReplay(executor);

        // we want to wait for the cluster to have switched to replay mode, so we can send some messages to it.
        // if we were to publish events right away, there is a big chance the Cluster didn't switch to replay mode, yet.
        waitForReplayToHaveStarted(replayingCluster);
View Full Code Here

Examples of org.axonframework.eventhandling.replay.ReplayingCluster

        RunEventReplay.StubEventStore eventStore = applicationContext.getBean("eventStore", RunEventReplay.StubEventStore.class);
        EventBus eventBus = applicationContext.getBean(EventBus.class);
        ExecutorService executor = applicationContext.getBean(ExecutorService.class);
        // and finally, the ReplayingCluster. As you can see the bean is an instance of ReplayingCluster, because we
        // added replay configuration to it.
        ReplayingCluster replayingCluster = applicationContext.getBean("cluster", ReplayingCluster.class);

        // we append some events to simulate a full event store
        final DomainEventMessage[] domainEventMessages = {
                new GenericDomainEventMessage<ToDoItemCreatedEvent>(
                        "todo1", 0, new ToDoItemCreatedEvent("todo1", "Need to do something")),
                new GenericDomainEventMessage<ToDoItemCreatedEvent>(
                        "todo2", 0, new ToDoItemCreatedEvent("todo2", "Another thing to do")),
                new GenericDomainEventMessage<ToDoItemCompletedEvent>("todo2", 0, new ToDoItemCompletedEvent("todo2"))
        };
        eventStore.appendEvents("mock", new SimpleDomainEventStream(domainEventMessages));

        // we get the executor service from the application context and start the replay as an asynchronous process
        Future<Void> future = replayingCluster.startReplay(executor);

        // we want to wait for the cluster to have switched to replay mode, so we can send some messages to it.
        // if we were to publish events right away, there is a big chance the Cluster didn't switch to replay mode, yet.
        waitForReplayToHaveStarted(replayingCluster);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.