org.axonframework.commandhandling.gateway.CommandGateway Java Examples

The following examples show how to use org.axonframework.commandhandling.gateway.CommandGateway. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TraderAggregateDataInitializer.java    From ESarch with Apache License 2.0 5 votes vote down vote up
public TraderAggregateDataInitializer(CommandGateway commandGateway,
                                      EventStore eventStore,
                                      QueryGateway queryGateway,
                                      CommandRouter commandRouter) {
  this.commandGateway = commandGateway;
  this.eventStore = eventStore;
  this.queryGateway = queryGateway;
  this.commandRouter = commandRouter;
}
 
Example #2
Source File: CommandController.java    From ESarch with Apache License 2.0 5 votes vote down vote up
public CommandController(CommandGateway commandGateway,
                         ObjectMapper objectMapper,
                         JsonSchemaGenerator jsonSchemaGenerator) {
    this.commandGateway = commandGateway;
    this.objectMapper = objectMapper;
    this.jsonSchemaGenerator = jsonSchemaGenerator;
}
 
Example #3
Source File: CommandContractTest.java    From ESarch with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    final CommandGateway commandGateway = mock(CommandGateway.class);

    when(commandGateway.send(any())).thenReturn(completedFuture(null));
    when(commandGateway.send(any(CreateCompanyCommand.class)))
            .thenReturn(completedFuture(COMPANY_ID));
    when(commandGateway.send(any(CreateOrderBookCommand.class)))
            .thenReturn(completedFuture(ORDER_BOOK_ID));
    when(commandGateway.send(any(CreatePortfolioCommand.class)))
            .thenReturn(completedFuture(PORTFOLIO_ID));
    when(commandGateway.send(any(CreateUserCommand.class)))
            .thenReturn(completedFuture(USER_ID));
    when(commandGateway.send(any(StartBuyTransactionCommand.class)))
            .thenReturn(completedFuture(BUY_TRANSACTION_ID));
    when(commandGateway.send(any(StartSellTransactionCommand.class)))
            .thenReturn(completedFuture(SELL_TRANSACTION_ID));

    final ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerModule(new KotlinModule());
    final JsonSchemaGenerator jsonSchemaGenerator = new JsonSchemaGenerator(objectMapper);

    final CommandController commandController =
            new CommandController(commandGateway, objectMapper, jsonSchemaGenerator);
    commandController.setBeanClassLoader(this.getClass().getClassLoader());

    RestAssuredMockMvc.standaloneSetup(commandController);
}
 
Example #4
Source File: BulkIssuer.java    From giftcard-demo with Apache License 2.0 5 votes vote down vote up
public BulkIssuer(CommandGateway commandGateway, int number, int amount, Consumer<BulkIssuer> callback) {
    remaining.set(number);
    new Thread(() -> {
        for(int i = 0; i < number; i++) {
            String id = UUID.randomUUID().toString().substring(0, 11).toUpperCase();
            commandGateway
                    .send(new IssueCmd(id, amount))
                    .whenComplete((Object o, Throwable throwable) -> {
                        if(throwable == null) {
                            success.incrementAndGet();
                        } else {
                            error.incrementAndGet();
                            log.error("Error handling command", throwable);
                        }
                        remaining.decrementAndGet();
                    });
        }
    }).start();
    new Thread(() -> {
        try {
            while (remaining.get() > 0) {
                callback.accept(this);
                Thread.sleep(1000);
            }
            callback.accept(this);
        } catch(InterruptedException ex) {
            log.error("Interrupted", ex);
        }
    }).start();
}
 
Example #5
Source File: OrderRestEndpoint.java    From tutorials with MIT License 4 votes vote down vote up
public OrderRestEndpoint(CommandGateway commandGateway, QueryGateway queryGateway) {
    this.commandGateway = commandGateway;
    this.queryGateway = queryGateway;
}
 
Example #6
Source File: ToDoItemRunner.java    From bearchoke with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
                SchedulerConfig.class,
                RabbitMQLocalConfig.class,
                AxonCQRSConfig.class,
                ToDoConfig.class
        );

        try {
            // let's start with the Command Bus
//        CommandBus commandBus = new SimpleCommandBus();
            CommandBus commandBus = ctx.getBean(CommandBus.class);

            // the CommandGateway provides a friendlier API
//        CommandGateway commandGateway = new DefaultCommandGateway(commandBus);
            CommandGateway commandGateway = ctx.getBean(CommandGateway.class);

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

            // a Simple Event Bus will do
//        EventBus eventBus = new SimpleEventBus();
            EventBus eventBus = ctx.getBean(EventBus.class);

            // we need to configure the repository
//        EventSourcingRepository repository = new EventSourcingRepository(ToDoItem.class, eventStore);
//        repository.setEventBus(eventBus);
            EventSourcingRepository repository = ctx.getBean("toDoItemRepository", EventSourcingRepository.class);

            // Axon needs to know that our ToDoItem Aggregate can handle commands
//            AggregateAnnotationCommandHandler.subscribe(ToDoItem.class, repository, commandBus);
//            AnnotationEventListenerAdapter.subscribe(new ToDoEventHandler(), eventBus);

            // and let's send some Commands on the CommandBus.
            final ToDoIdentifier id = new ToDoIdentifier();
            commandGateway.send(new CreateToDoItemCommand(id, "Need to do this", "user"));
            commandGateway.send(new MarkToDoItemAsCompleteCommand(id, "user"));
        } finally {
            ctx.destroy();
        }

    }
 
Example #7
Source File: TechnoCommands.java    From hesperides with GNU General Public License v3.0 4 votes vote down vote up
@Autowired
public TechnoCommands(CommandGateway commandGateway) {
    this.commandGateway = commandGateway;
}
 
Example #8
Source File: PlatformCommands.java    From hesperides with GNU General Public License v3.0 4 votes vote down vote up
@Autowired
public PlatformCommands(CommandGateway commandGateway) {
    this.commandGateway = commandGateway;
}
 
Example #9
Source File: ModuleCommands.java    From hesperides with GNU General Public License v3.0 4 votes vote down vote up
@Autowired
public ModuleCommands(CommandGateway commandGateway) {
    this.commandGateway = commandGateway;
}
 
Example #10
Source File: ApplicationDirectoryGroupsCommands.java    From hesperides with GNU General Public License v3.0 4 votes vote down vote up
@Autowired
public ApplicationDirectoryGroupsCommands(CommandGateway commandGateway) {
    this.commandGateway = commandGateway;
}
 
Example #11
Source File: BankAccountController.java    From AxonBank with Apache License 2.0 4 votes vote down vote up
public BankAccountController(CommandGateway commandGateway, BankAccountRepository bankAccountRepository) {
    this.commandGateway = commandGateway;
    this.bankAccountRepository = bankAccountRepository;
}
 
Example #12
Source File: BankTransferController.java    From AxonBank with Apache License 2.0 4 votes vote down vote up
public BankTransferController(CommandGateway commandGateway, BankTransferRepository bankTransferRepository) {
    this.commandGateway = commandGateway;
    this.bankTransferRepository = bankTransferRepository;
}
 
Example #13
Source File: CatalogService.java    From pcf-axon-cqrs-demo with GNU General Public License v3.0 4 votes vote down vote up
public CatalogService(CommandGateway commandGateway) {
    this.commandGateway = commandGateway;
}
 
Example #14
Source File: AxonDefaultConfiguration.java    From cdi with Apache License 2.0 4 votes vote down vote up
@Produces
@ApplicationScoped
public CommandGateway commandGateway(Configuration configuration) {
    return configuration.commandGateway();
}
 
Example #15
Source File: GiftcardUI.java    From giftcard-demo with Apache License 2.0 4 votes vote down vote up
public GiftcardUI(CommandGateway commandGateway, QueryGateway queryGateway) {
    this.commandGateway = commandGateway;
    this.queryGateway = queryGateway;
}
 
Example #16
Source File: SellTradeManagerSaga.java    From ESarch with Apache License 2.0 4 votes vote down vote up
@Autowired
public void setCommandGateway(CommandGateway commandGateway) {
    this.commandGateway = commandGateway;
}
 
Example #17
Source File: BuyTradeManagerSaga.java    From ESarch with Apache License 2.0 4 votes vote down vote up
@Autowired
public void setCommandGateway(CommandGateway commandGateway) {
    this.commandGateway = commandGateway;
}
 
Example #18
Source File: CompanyOrderBookListener.java    From ESarch with Apache License 2.0 4 votes vote down vote up
public CompanyOrderBookListener(CommandGateway commandGateway) {
    this.commandGateway = commandGateway;
}
 
Example #19
Source File: PortfolioManagementUserListener.java    From ESarch with Apache License 2.0 4 votes vote down vote up
public PortfolioManagementUserListener(CommandGateway commandGateway) {
    this.commandGateway = commandGateway;
}
 
Example #20
Source File: ShoppingCartServlet.java    From cqrs-sample with MIT License 3 votes vote down vote up
@Override
public void init(ServletConfig config) throws ServletException {
   super.init(config);

   ac = new ClassPathXmlApplicationContext("/axon-db2-configuration.xml");
   
   logger.debug("sono nella init della servlet");
   
   commandGateway= ac.getBean(CommandGateway.class);
   
}