Skip to content

Commit 557ce65

Browse files
committed
BAEL-2435 Update main application
Update the MessagesRunner to be a spring boot application
1 parent d8ef050 commit 557ce65

1 file changed

Lines changed: 5 additions & 46 deletions

File tree

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,13 @@
11
package com.baeldung.axon;
22

3-
import com.baeldung.axon.aggregates.MessagesAggregate;
4-
import com.baeldung.axon.commands.CreateMessageCommand;
5-
import com.baeldung.axon.commands.MarkReadMessageCommand;
6-
import com.baeldung.axon.eventhandlers.MessagesEventHandler;
7-
import org.axonframework.commandhandling.AggregateAnnotationCommandHandler;
8-
import org.axonframework.commandhandling.CommandBus;
9-
import org.axonframework.commandhandling.SimpleCommandBus;
10-
import org.axonframework.commandhandling.gateway.CommandGateway;
11-
import org.axonframework.commandhandling.gateway.DefaultCommandGateway;
12-
import org.axonframework.eventhandling.AnnotationEventListenerAdapter;
13-
import org.axonframework.eventsourcing.EventSourcingRepository;
14-
import org.axonframework.eventsourcing.eventstore.EmbeddedEventStore;
15-
import org.axonframework.eventsourcing.eventstore.EventStore;
16-
import org.axonframework.eventsourcing.eventstore.inmemory.InMemoryEventStorageEngine;
17-
18-
import java.util.UUID;
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
195

6+
@SpringBootApplication
207
public class MessagesRunner {
218

229
public static void main(String[] args) {
23-
CommandBus commandBus = new SimpleCommandBus();
24-
25-
CommandGateway commandGateway = new DefaultCommandGateway(commandBus);
26-
27-
EventStore eventStore = new EmbeddedEventStore(new InMemoryEventStorageEngine());
28-
29-
EventSourcingRepository<MessagesAggregate> repository =
30-
new EventSourcingRepository<>(MessagesAggregate.class, eventStore);
31-
32-
33-
AggregateAnnotationCommandHandler<MessagesAggregate> messagesAggregateAggregateAnnotationCommandHandler =
34-
new AggregateAnnotationCommandHandler<MessagesAggregate>(MessagesAggregate.class, repository);
35-
messagesAggregateAggregateAnnotationCommandHandler.subscribe(commandBus);
36-
37-
final AnnotationEventListenerAdapter annotationEventListenerAdapter =
38-
new AnnotationEventListenerAdapter(new MessagesEventHandler());
39-
eventStore.subscribe(eventMessages -> eventMessages.forEach(e -> {
40-
try {
41-
annotationEventListenerAdapter.handle(e);
42-
} catch (Exception e1) {
43-
throw new RuntimeException(e1);
44-
45-
}
46-
}
47-
48-
));
49-
50-
final String itemId = UUID.randomUUID().toString();
51-
commandGateway.send(new CreateMessageCommand(itemId, "Hello, how is your day? :-)"));
52-
commandGateway.send(new MarkReadMessageCommand(itemId));
10+
SpringApplication.run(MessagesRunner.class, args);
5311
}
12+
5413
}

0 commit comments

Comments
 (0)