Package org.axonframework.commandhandling.gateway

Examples of org.axonframework.commandhandling.gateway.DefaultCommandGateway


        // we use the repository to register the command handler
        AggregateAnnotationCommandHandler.subscribe(ToDoItem.class, repository, commandBus);

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

        // and let's send some Commands on the CommandBus.
        CommandGenerator.sendCommands(commandGateway);

        // we need to stop the disruptor command bus, to make sure we release all resources
View Full Code Here


        // 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
View Full Code Here

    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
View Full Code Here

        // Load the amount of times to send the commands from the command line or use default 1
        Integer numberOfCommandLoops = determineNumberOfCommandLoops();

        // and let's send some Commands on the CommandBus.
        CommandGateway gateway = new DefaultCommandGateway(commandBus);
        for (int i = 0; i < numberOfCommandLoops; i++) {
            CommandGenerator.sendCommands(gateway);
        }
    }
View Full Code Here

    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
View Full Code Here

        assertTrue("Failed to connect", connector1.awaitJoined(5, TimeUnit.SECONDS));
        assertTrue("Failed to connect", connector2.awaitJoined(5, TimeUnit.SECONDS));

        DistributedCommandBus bus1 = new DistributedCommandBus(connector1, new AnnotationRoutingStrategy(
                UnresolvedRoutingKeyPolicy.RANDOM_KEY));
        CommandGateway gateway1 = new DefaultCommandGateway(bus1);

        doThrow(new RuntimeException("Mock")).when(serializer).deserialize(argThat(new TypeSafeMatcher<SerializedObject<byte[]>>() {
            @Override
            protected boolean matchesSafely(SerializedObject<byte[]> item) {
                return Arrays.equals("<string>Try this!</string>".getBytes(Charset.forName("UTF-8")), item.getData());
            }

            @Override
            public void describeTo(Description description) {
            }
        }));

        try {
            gateway1.sendAndWait("Try this!");
            fail("Expected exception");
        } catch (RuntimeException e) {
            assertEquals("Mock", e.getMessage());
        }
    }
View Full Code Here

        registeredResources.add(eventBus);
        commandBus = new RecordingCommandBus();
        registeredResources.add(commandBus);
        registeredResources.add(eventScheduler);
        registeredResources.add(new DefaultCommandGateway(commandBus));
        fixtureExecutionResult = new FixtureExecutionResultImpl(sagaRepository, eventScheduler, eventBus, commandBus,
                                                                sagaType);
        FixtureResourceParameterResolverFactory.clear();
        for (Object resource : registeredResources) {
            FixtureResourceParameterResolverFactory.registerResource(resource);
View Full Code Here

    @Test(expected=
        SecurityException.class, // per documentation, an unchecked exception (theoretically
          // the only kind throwable by an interceptor) is returned unwrapped
        timeout=10000) // bug is that the caller waits forever for a CommandCallback.onFailure that never comes...
    public void testCommandDipatchInterceptorExceptionOnRetryThreadIsThrownToCaller() {
    commandGateway = new DefaultCommandGateway(commandBus, retryScheduler);

    // trigger retry
        commandBus.subscribe(String.class.getName(), new CommandHandler<String>() {
            @Override
            public Object handle(CommandMessage<String> commandMessage, UnitOfWork unitOfWork) throws Throwable {
View Full Code Here

   * is not preserved.
   */
    @Test(timeout=10000)
    public void testCommandGatewayDispatchInterceptorMetaDataIsPreservedOnRetry() {
      final Thread testThread = Thread.currentThread();
    commandGateway = new DefaultCommandGateway(commandBus, retryScheduler, new CommandDispatchInterceptor() {
      @Override
      public CommandMessage<?> handle(CommandMessage<?> commandMessage) {
        if (Thread.currentThread() == testThread) {
          return commandMessage.andMetaData(Collections.singletonMap("gatewayMetaData", "myUserSession"));
        } else {
View Full Code Here

   * behaves as designed (if not as "expected").
   */
    @Test(timeout=10000)
    public void testCommandBusDispatchInterceptorMetaDataIsNotPreservedOnRetry() {
      final Thread testThread = Thread.currentThread();
    commandGateway = new DefaultCommandGateway(commandBus, retryScheduler);

      // trigger retry, then return metadata for verification
        commandBus.subscribe(String.class.getName(), new CommandHandler<String>() {
            @Override
            public MetaData handle(CommandMessage<String> commandMessage, UnitOfWork unitOfWork) throws Throwable {
View Full Code Here

TOP

Related Classes of org.axonframework.commandhandling.gateway.DefaultCommandGateway

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.