Could not lookup nil because it was not started or it does not exist
manhtranlinh opened this issue · comments
Hi all,
I am following this blog to create a bank_app application to learn CQRS/ES DDD. Because the versions of libraries are updated: Commanded, EventStore, Supervisor ... So that I follow the update guide from hexdocs and github to update the sources in blog.
I created a repository in github to share my program: https://github.com/manhtranlinh/bank_api
I can start program but when I create a POST to /api/accounts, there is bellowing error, and I am not sure this error is from Commanded library or my configuration, but I post here as issue to request your help to check.
[error] #PID<0.550.0> running BankAPIWeb.Endpoint (connection #PID<0.547.0>, stream id 2) terminated
Server: localhost:4000 (http)
Request: POST /api/accounts
** (exit) an exception was raised:
** (RuntimeError) could not lookup nil because it was not started or it does not exist
(commanded 1.2.0) lib/commanded/application/config.ex:45: Commanded.Application.Config.lookup/1
(commanded 1.2.0) lib/commanded/application/config.ex:15: Commanded.Application.Config.get/2
(commanded 1.2.0) lib/commanded/registration.ex:31: Commanded.Registration.start_child/4
(commanded 1.2.0) lib/commanded/aggregates/supervisor.ex:43: Commanded.Aggregates.Supervisor.open_aggregate/3
(commanded 1.2.0) lib/commanded/commands/dispatcher.ex:74: Commanded.Commands.Dispatcher.execute/3
(commanded 1.2.0) lib/commanded/commands/dispatcher.ex:56: Commanded.Commands.Dispatcher.dispatch/1
You need to either:
- Dispatch the command via the Commanded Application module:
BankAPI.Commanded.dispatch(command)
- Dispatch the command via the router and pass the application as an option:
BankAPI.Router.dispatch(command, application: BankAPI.Commanded)
Dispatching commands via the Commanded Application module is the preferred approach.
Hi Ben,
I try your 2 suggestions but with all there are errors:
Dispatch the command via the Commanded Application module: BankAPI.Commanded.dispatch(command)
lib/bank_api/commanded.ex:1: invalid call [application: nil, consistency: :eventual, returning: false, timeout: 5000, lifespan: Commanded.Aggregates.DefaultLifespan, metadata: %{}, retry_attempts: 10, identity: :account_uuid, function: :execute, to: BankAPI.Accounts.Aggregates.Account, aggregate: BankAPI.Accounts.Aggregates.Account].dispatch(command, opts)
Dispatch the command via the router and pass the application as an option: BankAPI.Router.dispatch(command, application: BankAPI.Commanded)
unexpected dispatch parameter "application" available params are: to, function, aggregate, identity, identity_prefix, timeout, lifespan, consistency
Hi Ben,
I have just updated project to make it clearer. But now still has the same issue:
iex> Accounts.open_account(account_params) [debug] Locating aggregate process for
BankAPI.Accounts.Aggregates.Accountwith UUID "0b300f22-f74f-40ca-8624-bc85b021c92e" ** (RuntimeError) could not lookup nil because it was not started or it does not exist (commanded 1.2.0) lib/commanded/application/config.ex:45: Commanded.Application.Config.lookup/1 (commanded 1.2.0) lib/commanded/application/config.ex:15: Commanded.Application.Config.get/2
Hi Ben,
Last time I don't understand your suggestion, now If in module BankAPI.CommandRouter, I call dispatch like this:
`
defmodule BankAPI.CommandRouter do
use Commanded.Commands.Router
alias BankAPI.Accounts.Aggregates.Account
alias BankAPI.Accounts.Commands.OpenAccount
dispatch([OpenAccount], to: Account, identity: :account_uuid)
end
`
And in Context I call to Router like this:
dispatch_result = %OpenAccount{ initial_balance: changeset.changes.initial_balance, account_uuid: account_uuid } |> Router.dispatch(application: CommandedApplication)
It works.
Thanks for your help.