charlessolar / Aggregates.NET

.NET event sourced domain driven design model via NServiceBus and GetEventStore

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when calling Apply method in the Domain app

AbdoDabbas opened this issue · comments

I've built an application project to listen to events triggered by the domain (via the Apply method) and update the read model.
The handler is receiving the event and handling it but in the domain project console I'm seeing the following exception:

  • OrderPlaced is the event I'm triggering.
No handlers could be found for message type: Messages.OrderPlaced
   at NServiceBus.LoadHandlersConnector.Invoke(IIncomingLogicalMessageContext context, Func`2 stage)
   at CurrentSessionBehavior.Invoke(IIncomingLogicalMessageContext context, Func`1 next) in /_/src/SqlPersistence/SynchronizedStorage/CurrentSessionBehavior.cs:line 19
   at Aggregates.Internal.LogContextProviderBehaviour.Invoke(IIncomingLogicalMessageContext context, Func`1 next) in C:\projects\aggregates-net\src\Aggregates.NET.NServiceBus\Internal\LogContextProviderBehaviour.cs:line 39
   at Aggregates.Internal.LocalMessageUnpack.Invoke(IIncomingLogicalMessageContext context, Func`1 next) in C:\projects\aggregates-net\src\Aggregates.NET.NServiceBus\Internal\LocalMessageUnpack.cs:line 110
   at Aggregates.Internal.UnitOfWorkExecutor.Invoke(IIncomingLogicalMessageContext context, Func`1 next) in C:\projects\aggregates-net\src\Aggregates.NET.NServiceBus\Internal\UnitOfWorkExecutor.cs:line 90
   at Aggregates.Internal.UnitOfWorkExecutor.Invoke(IIncomingLogicalMessageContext context, Func`1 next) in C:\projects\aggregates-net\src\Aggregates.NET.NServiceBus\Internal\UnitOfWorkExecutor.cs:line 129
   at Aggregates.Internal.CommandAcceptor.Invoke(IIncomingLogicalMessageContext context, Func`1 next) in C:\projects\aggregates-net\src\Aggregates.NET.NServiceBus\Internal\CommandAcceptor.cs:line 76
   at NServiceBus.ScheduledTaskHandlingBehavior.Invoke(IIncomingLogicalMessageContext context, Func`2 next)
   at Aggregates.Internal.ExceptionRejector.Invoke(IIncomingLogicalMessageContext context, Func`1 next) in C:\projects\aggregates-net\src\Aggregates.NET.NServiceBus\Internal\ExceptionRejector.cs:line 49

Any idea what could be the issue? I tried to replicate the code in the ToDo example, but with no luck, I'm missing something.

@AbdoDabbas

Do you have code on that endpoint to handle that message type?

Should look something like

public Task Handle(Messages.OrderPlaced message, IMessageContext context) {
}

Scratch that, no you shouldn't see this event in the domain endpoint. For some reason its being delivered to your endpoint and NSB is complaining that you have no handlers for it.

I can't say for certain why your domain endpoint is receiving this message without seeing the code. But thats where you should look. Find out why the domain is receiving that event.

In the eventstore UI - find a projection called "Domain" something and paste the definition and maybe I can help debug it

I couldn't see any projection with the name "domain", only found another one called "application" (which inside the "Source" contains "Domain"), here's the source of it:

function processEvent(s,e) {
    linkTo('application.1.0', e);
}
options({
  reorderEvents: false,
  processingLag: 0
})
fromCategories(['DOMAIN','OOB']).
when({
'Messages.OrderPlaced v1': processEvent
});

And here's a picture of the UI:
image

I have the following:
WebAPI project which sends the commands to "Domain" project (contains the PlaceOrder handler), then the latter uses Apply<OrderPlaced> to save in EventStore and trigger the event, another project I have called "application" which contains a handler to OrderPlaced event.

To be honest I tried a lot of things but I don't remember I changed the names, but anyway I deleted ES db and logs and RabbitMQ's data, and started clean, it's working now, in some cases (not sure in which case yet) the Application receives the event twice, but I'm not sure if it's because I'm doing something wrong or not, I'll keep testing.

Regarding the projections, It keeps creating only one and named after the Application endpoint as you can see in the previous screenshot I sent.

BTW, I don't know if this is important but when I'm configuring the EventStore client and set the name in the connection the same in both the Domain app and Application app (I use the string "domain")

Sure, makes sense a clean start would fix a lot of issues.
The Todo App uses a docker compose file - during development you should do docker-compose down and delete the previous images to be absolutely certain you are using your latest code.

Also do be sure to not name different endpoints the same name!

Theres several shell scripts in the eShop example to help with this process located here: https://github.com/charlessolar/eShopOnContainersDDD/tree/master/linux-cli