Package org.axonframework.commandhandling

Examples of org.axonframework.commandhandling.CommandBus


*/
public class RunAnnotatedAggregate {

    public static void main(String[] args) {
        // let's start with the Command Bus
        CommandBus commandBus = new SimpleCommandBus();

        // the CommandGateway provides a friendlier API to send commands
        CommandGateway commandGateway = new DefaultCommandGateway(commandBus);

        // we'll store Events on the FileSystem, in the "events" folder
View Full Code Here


        } catch (BindException e) {
            System.out.println("Gossip router is already started in another JVM instance.");
        }

        // let's start with the local Command Bus that registers the handlers
        CommandBus localSegment = new SimpleCommandBus();

        // Configure the required components for jgroup, first een channel and serializer
        JChannel channel = new JChannel("tcp_gossip.xml");
        Serializer serializer = new XStreamSerializer();
View Full Code Here

*/
public class RunBasicCommandHandling {

    public static void main(String[] args) {
        // let's start with the Command Bus
        CommandBus commandBus = new SimpleCommandBus();

        // the CommandGateway provides a friendlier API to send commands
        CommandGateway commandGateway = new DefaultCommandGateway(commandBus);

        // we'll store Events on the FileSystem, in the "events" folder
        EventStore eventStore = new FileSystemEventStore(new SimpleEventFileResolver(new File("./events")));

        // a Simple Event Bus will do
        EventBus eventBus = new SimpleEventBus();

        // we need to configure the repository
        EventSourcingRepository<ToDoItem> repository = new EventSourcingRepository<ToDoItem>(ToDoItem.class, eventStore);
        repository.setEventBus(eventBus);

        // Register the Command Handlers with the command bus by subscribing to the name of the command
        commandBus.subscribe(CreateToDoItemCommand.class.getName(),
                new CreateToDoCommandHandler(repository));
        commandBus.subscribe(MarkCompletedCommand.class.getName(),
                new MarkCompletedCommandHandler(repository));

        // We register an event listener to see which events are created
        eventBus.subscribe(new ToDoEventListener());

View Full Code Here

        // first of all, we need an Event Bus
        EventBus eventBus = new SimpleEventBus();

        // Sagas often need to send commands, so let's create a Command Bus
        CommandBus commandBus = new SimpleCommandBus();

        // a CommandGateway has a much nicer API
        CommandGateway commandGateway = new DefaultCommandGateway(commandBus);

        // let's register a Command Handler that writes to System Out so we can see what happens
        commandBus.subscribe(MarkToDoItemOverdueCommand.class.getName(),
                new CommandHandler<MarkToDoItemOverdueCommand>() {
                    @Override
                    public Object handle(CommandMessage<MarkToDoItemOverdueCommand> commandMessage,
                                         UnitOfWork unitOfWork) throws Throwable {
                        System.out.println(String.format("Got command to mark [%s] overdue!",
View Full Code Here

            return mock(CommandBus.class);
        }

        @Bean
        public CommandBus alternateCommandBus() {
            final CommandBus commandBus = mock(CommandBus.class);
            doThrow(new AssertionError("Should not use this command bus")).when(commandBus).subscribe(anyString(),
                                                                                                      any(AnnotationCommandHandlerAdapter.class));
            return commandBus;
        }
View Full Code Here

        list = (ManagedList<?>) dispatchInterceptors.getValue();
        assertTrue(RuntimeBeanReference.class.isInstance(list.get(0)));
        beanReference = (RuntimeBeanReference) list.get(0);
        assertEquals("dispatchInterceptor", beanReference.getBeanName());

        CommandBus commandBus = beanFactory.getBean("commandBus-embedded-ref", CommandBus.class);
        assertNotNull(commandBus);
    }
View Full Code Here

        PropertyValue dispatchInterceptors = commandBusEmbeddedBean.getPropertyValues().getPropertyValue("dispatchInterceptors");
        assertNotNull("No definition for the interceptor", dispatchInterceptors);
        list = (ManagedList<?>) handlerInterceptors.getValue();
        assertTrue(BeanDefinitionHolder.class.isInstance(list.get(0)));

        CommandBus commandBus = beanFactory.getBean("commandBus-embedded-interceptor-bean", CommandBus.class);
        assertNotNull(commandBus);
    }
View Full Code Here

public class CommandHandlingBenchmark {

    private static final UUID aggregateIdentifier = UUID.randomUUID();

    public static void main(String[] args) {
        CommandBus cb = new SimpleCommandBus();

        InMemoryEventStore eventStore = new InMemoryEventStore();
        eventStore.appendInitialEvent("test", new SimpleDomainEventStream(new GenericDomainEventMessage<SomeEvent>(
                aggregateIdentifier, 0, new SomeEvent())));

        final MyAggregate myAggregate = new MyAggregate(aggregateIdentifier);
        Repository<MyAggregate> repository = new Repository<MyAggregate>() {
            @Override
            public MyAggregate load(Object aggregateIdentifier, Long expectedVersion) {
                throw new UnsupportedOperationException("Not implemented yet");
            }

            @Override
            public MyAggregate load(Object aggregateIdentifier) {
                return myAggregate;
            }

            @Override
            public void add(MyAggregate aggregate) {
                throw new UnsupportedOperationException("Not implemented yet");
            }
        };
        cb.subscribe(String.class.getName(), new MyCommandHandler(repository));
//        new AnnotationCommandHandlerAdapter(new MyCommandHandler(repository), cb).subscribe();


        long COMMAND_COUNT = 5 * 1000 * 1000;
        cb.dispatch(GenericCommandMessage.asCommandMessage("ready,"));
        long t1 = System.currentTimeMillis();
        for (int t = 0; t < COMMAND_COUNT; t++) {
            cb.dispatch(GenericCommandMessage.asCommandMessage("go!"));
        }
        long t2 = System.currentTimeMillis();
        System.out.println(String.format("Just did %d commands per second", ((COMMAND_COUNT * 1000) / (t2 - t1))));
    }
View Full Code Here

TOP

Related Classes of org.axonframework.commandhandling.CommandBus

Copyright © 2018 www.massapicom. 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.