0

What I am doing is that i am trying to get the aggregate from repository and then process that particular event and mark it as a new event...so that query recognizes that it is a update event. But the problem is that I am not able to get that particular aggregate.

What I have done is here:

LockAwareAggregate<CustomerAggregate, EventSourcedAggregate<CustomerAggregate>> lockCustomerAggregate = 
    customerEventSourcingRepository.load(command.getId().toString());

EventSourcedAggregate<CustomerAggregate> eventSourcedCustomerAggregate = 
    lockCustomerAggregate.getWrappedAggregate();

CustomerAggregate customerAggregate = eventSourcedCustomerAggregate.getAggregateRoot();

customerAggregate.updateAddress(command.getAddress());

I used this code in 2.4.3 and it was returning a CustomerAggregate but right now it's returning a LockAwareAggregate. Can you please suggest where I am getting wrong.

can you please also share whats message in
UnitOfWork work = DefaultUnitOfWork.startAndGet(message??);

Thanks in advance.

A S
  • 75
  • 8
  • Your phrasing seems a bit off at the start, as it seems you intent to adjust your events in the event store which is highly discouraged. – Steven Jan 19 '18 at 09:26

1 Answers1

2

Although I'm not completely sure what you're trying to do, what it sounds like is that you're retrieving events from your EventStore and you say you're updating them. I'd highly encourage not to do that.

You've EventStore should be append only. The events stored in it have happened, so that's history. In real life you cannot adjust history, and that's how you should regard your events in the EventStore as well.

So, that's a warning. Your code snippet luckily suggests you're just trying to call a function on your aggregate to perform a certain 'action'. Action is the keyword here, as it signals you're doing a 'command'. Thus, you could call that function just as easily through a @CommandHandler annotated field on your aggregate to adjust it. In doing that you will not have to load your aggregate manually.

Added, I can't really see which Repository implementation you're using to load your aggregate manually (I guess the LockingRepository), but I'd suggest to use the Repository interface rather than a specific implementation. That interface should return you an Aggregate<T>, were T is the CustomerAggregate in your example. That should give you the possibility to call the updateAddresss() function as desired.

Probable answers

  1. In short, I think you're thus wiring the wrong Repository implementation in that snippet to load your aggregate. Just using the Repository i.o. the EventSourcingRepository directly should do fine.
  2. The message in the UnitOfWork your asking about can be any implementation of the Message interface. So that can be a Command, Event or a Query.

Suggestion 1. I regularly suggest to not use the Repository directly though. Axon Framework can do the heavy lifting there, by letting you publish command on the CommandBus/CommandGateway. That, together with the @CommandHandler annotation on your command handling functions, makes it so that the framework will automatically load the right aggregate from the Repository and call that annotated function.

Steven
  • 6,936
  • 1
  • 16
  • 31
  • I'll Quote your answer from Added part...that's what exactly I am trying to do but I didn't get one thing, how you thought that I am trying to change EventStore, I am new to this but one thing is for sure I am not trying to change eventStore. And the repository you asked for is EventSourcingRepository. Can you please suggest is there anything wrong in code that you got an overview that I am changing anything in evet store. Also please share what change I need to make. – A S Jan 19 '18 at 10:24
  • can you please answer my comment.I really need to know if I am getting wrong anywhere. – A S Jan 20 '18 at 11:39
  • I just edited the question, which may make it a bit more clearer what I'm explaining. It is quite basic though, so if this might end up to difficult, I definitely suggest watching some of the Webinars available on YouTube around starting an Axon Framework project. And just as with your last questions I answered, if this solves your issue, could you please tick this question as the correct one? That makes it so other people are certain that the answer was answered sufficiently, so nicer bookkeeping in general. – Steven Jan 22 '18 at 08:04
  • I assume it solved your issue as you've marked it, great to hear that @AS! – Steven Jan 23 '18 at 08:08