-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathServerEventProcessorRestController.java
More file actions
50 lines (41 loc) · 2.27 KB
/
ServerEventProcessorRestController.java
File metadata and controls
50 lines (41 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package io.axoniq.server;
import org.axonframework.config.Configuration;
import org.axonframework.eventhandling.StreamingEventProcessor;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
@RestController
@RequestMapping("server")
public class ServerEventProcessorRestController {
private final EventProcessorService eventProcessorService;
private final Configuration configuration;
public ServerEventProcessorRestController(EventProcessorService eventProcessorService,
Configuration configuration) {
this.eventProcessorService = eventProcessorService;
this.configuration = configuration;
}
@GetMapping("start/{processorName}")
public Mono<Void> start(@PathVariable String processorName) {
return eventProcessorService.start(processorName);
}
@GetMapping("pause/{processorName}")
public Mono<Void> pause(@PathVariable String processorName) {
return eventProcessorService.pause(processorName);
}
@GetMapping("reset/{processorName}")
public Mono<Void> reset(@PathVariable String processorName) {
Assert.hasLength(processorName, "Processor Name is mandatory and can't be empty!");
StreamingEventProcessor eventProcessor = configuration.eventProcessingConfiguration()
.eventProcessorByProcessingGroup(
processorName,
StreamingEventProcessor.class)
.orElseThrow(IllegalArgumentException::new);
return eventProcessorService.pause(processorName)
.then(eventProcessorService.awaitTermination(processorName))
.then(Mono.<Void>fromRunnable(eventProcessor::resetTokens))
.then(eventProcessorService.start(processorName));
}
}