Package org.axonframework.commandhandling

Examples of org.axonframework.commandhandling.SimpleCommandBus


        // 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


*/
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

    /**
     * This test should make sure the problem described in issue #91 does not occur anymore
     */
    @Test
    public void testCallbackCalled() {
        SimpleCommandBus scb = new SimpleCommandBus();
        AnnotationCommandHandlerAdapter.subscribe(this, scb);

        scb.dispatch(GenericCommandMessage.asCommandMessage("Hello"), new VoidCallback() {
            @Override
            protected void onSuccess() {
                // what I expected
            }

View Full Code Here

    private SimpleCommandBus commandBus;
    private Repository<StubCommandAnnotatedAggregate> mockRepository;

    @Before
    public void setUp() throws Exception {
        commandBus = spy(new SimpleCommandBus());
        mockRepository = mock(Repository.class);

        ParameterResolverFactory parameterResolverFactory = MultiParameterResolverFactory.ordered(
                ClasspathParameterResolverFactory.forClass(AggregateAnnotationCommandHandler.class),
                new ParameterResolverFactory() {
View Full Code Here

    }

    @Override
    public void afterPropertiesSet() throws Exception {
        if (localSegment == null) {
            SimpleCommandBus bus = new SimpleCommandBus();
            if (interceptors != null && !interceptors.isEmpty()) {
                bus.setHandlerInterceptors(interceptors);
            }
            localSegment = bus;
        }
        if (serializer == null) {
            serializer = applicationContext.getBean(Serializer.class);
View Full Code Here

        BeanDefinition beanDefinition = beanFactory.getBeanDefinition("commandBus-simple");
        assertNotNull("Bean definition not created", beanDefinition);
        assertEquals("Wrong bean class", SimpleCommandBus.class.getName(), beanDefinition.getBeanClassName());
        assertEquals("wrong amount of constructor arguments"
                , 0, beanDefinition.getConstructorArgumentValues().getArgumentCount());
        SimpleCommandBus commandBus = beanFactory.getBean("commandBus-simple", SimpleCommandBus.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

            return new AnnotatedCommandHandler();
        }

        @Bean
        public CommandBus commandBus() {
            return new SimpleCommandBus();
        }
View Full Code Here

TOP

Related Classes of org.axonframework.commandhandling.SimpleCommandBus

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.