RailsEventStore / ecommerce

Application with CQRS and Event Sourcing built on Rails and Rails Event Store
MIT License
421 stars 70 forks source link

Error raised : Arkency::CommandBus::UnregisteredHandler: Missing handler for Crm::RegisterCustomer #356

Closed Ariharan2002 closed 9 months ago

Ariharan2002 commented 11 months ago

Im Newbie to CQRS approach, for learning purpose, i'm building CQRS based approach while building the same ecommerce application i faced the issue when creating customer 'Arkency::CommandBus::UnregisteredHandler: Missing handler for Crm::RegisterCustomer', i got like this but i have required each and every file that is necessary for the approach, please help me

andrzejkrzywda commented 11 months ago

We have this file https://github.com/RailsEventStore/ecommerce/blob/master/ecommerce/crm/lib/crm.rb which registers the command handler for a command. Is it missing in your code?

Ariharan2002 commented 11 months ago

But i required that too, require "infra" require_relative "crm/commands/promote_customer_to_vip" require_relative "crm/commands/register_customer" require_relative "crm/commands/assign_customer_to_order"

require_relative "crm/events/customer_promoted_to_vip" require_relative "crm/events/customer_registered" require_relative "crm/events/customer_assigned_to_order.rb"

require_relative "crm/customer_service" require_relative "crm/customer" require_relative "crm/order_service" require_relative "crm/order"

module Crm class Configuration

def call(event_store, command_bus)
  command_bus.register(RegisterCustomer, OnRegistration.new(event_store))
end

end end Is there any requirement needed for command handler registration

andrzejkrzywda commented 11 months ago

Can you show the code where you call this Configuration class?

Ariharan2002 commented 11 months ago

lib/configuration.rb

frozen_string_literal: true

require_relative '../../bloggie/configuration' require_relative '../../infra/lib/infra' require_relative '../app/read_models/Topics/register_topic'

require_relative '../app/read_models/Topics/update_topic'

class Configuration def call(event_store, command_bus) enable_res_infra_event_linking(event_store)

enable_topic_read_model(event_store)
Bloggie::Configuration.new.call(event_store, command_bus)

end

private

def enable_res_infra_event_linking(event_store) [ RailsEventStore::LinkByEventType.new, RailsEventStore::LinkByCorrelationId.new, RailsEventStore::LinkByCausationId.new ].each { |h| event_store.subscribe_to_all_events(h) } end

def enable_topic_read_model(event_store) Topics::Configuration.new.call(event_store) end end

bloggie/configuration.rb

frozen_string_literal: true

require_relative 'TopicSupport/lib/topic_support' require_relative '../rails_application/app/read_models/Topics/register_topic' require_relative '../rails_application/app/read_models/Topics/update_topic' module Bloggie class Configuration

def initialize
  super
end

def call(event_store, command_bus)
  configure_bounded_contexts
end

def configure_bounded_contexts
  event_store = Rails.configuration.event_store
  command_bus = Rails.configuration.command_bus

  [TopicSupport::Configuration.new].each { |c| c.call(event_store, command_bus) }
end

end end

i made some mistakes in call then i fixed now its working, Thank you @andrzejkrzywda

andrzejkrzywda commented 11 months ago

Cool, I'm glad it works now.

Feel free to ask in case of other questions.