Skip to content

Commit

Permalink
chore: rm actuators, refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
querwurzel committed Dec 15, 2024
1 parent 70a8aec commit c8e835e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 27 deletions.
4 changes: 0 additions & 4 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
<artifactId>frontend</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ private ClientSession session() throws ActiveMQException {
var session = sessions.get();

if (session == null) {
session = this.sessionFactory.createSession(true, true);
session = this.sessionFactory.createSession();
session.start();
sessions.set(session);
}

return session;
}

public record Message (
public record Message(
String pasteId,
Instant timeViewed
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

import java.util.concurrent.TimeUnit;

import static java.util.concurrent.TimeUnit.SECONDS;

@Configuration
class MessagingConfig {

Expand All @@ -37,52 +35,57 @@ public MessagingClient messagingClient(

@Bean(initMethod = "start", destroyMethod = "stop")
public EmbeddedActiveMQ activeMqServer() throws Exception {
org.apache.activemq.artemis.core.config.Configuration config = new ConfigurationImpl();
var config = new ConfigurationImpl();

config.addAddressConfiguration(new CoreAddressConfiguration()
.setName("binpastes")
.addQueueConfig(new QueueConfiguration()
.setName(new SimpleString("pasteTrackingQueue"))
.setAddress(new SimpleString("binpastes"))
.setMaxConsumers(1)
.setDelayBeforeDispatch(SECONDS.toMillis(3))
.setExclusive(true) // dispatch all messages to only one consumer at a time
.setConsumersBeforeDispatch(1)
.setDelayBeforeDispatch(TimeUnit.SECONDS.toMillis(5))
.setDurable(true)
)
.addRoutingType(RoutingType.ANYCAST));

config.addAddressSetting("binpastes", new AddressSettings()
.setDefaultAddressRoutingType(RoutingType.ANYCAST)
.setDefaultQueueRoutingType(RoutingType.ANYCAST)
.setEnableIngressTimestamp(false)
.setExpiryDelay(TimeUnit.DAYS.toMillis(7))
.setRedeliveryDelay(TimeUnit.SECONDS.toMillis(5))
.setRedeliveryMultiplier(1.5)
.setMaxDeliveryAttempts(5)
.setAutoCreateDeadLetterResources(true)
);

config.setMessageExpiryScanPeriod(SECONDS.toMillis(3));

config.setName("binpastesMQ");
config.addAcceptorConfiguration("in-vm", "vm://0");

config.setGracefulShutdownEnabled(true);
config.setGracefulShutdownTimeout(SECONDS.toMillis(1));
config.setGracefulShutdownTimeout(TimeUnit.SECONDS.toMillis(1));
config.setJournalPoolFiles(3);
config.setSecurityEnabled(false);
config.setJMXManagementEnabled(true);

config.setLargeMessageSync(false);

config.setPersistDeliveryCountBeforeDelivery(true);

config.setScheduledThreadPoolMaxSize(1);
config.setThreadPoolMaxSize(1);
config.setThreadPoolMaxSize(Runtime.getRuntime().availableProcessors());

config.setPersistenceEnabled(true);

config.setBindingsDirectory("./tracking/bindings");
config.setJournalDirectory("./tracking/journal");
config.setLargeMessagesDirectory("./tracking/large_messages");
config.setPagingDirectory("./tracking/paging");

var embeddedActiveMQ = new EmbeddedActiveMQ();
embeddedActiveMQ.setConfiguration(config);
var server = new EmbeddedActiveMQ()
.setConfiguration(config);

return embeddedActiveMQ;
return server;
}

@Bean(initMethod = "init", destroyMethod = "dispose")
Expand Down Expand Up @@ -110,12 +113,14 @@ public Scheduler producerThreadPool() {
@Bean(destroyMethod = "close")
@DependsOn("activeMqServer")
public ServerLocator serverLocator() throws Exception {
ServerLocator serverLocator = ActiveMQClient.createServerLocator("vm://0");
serverLocator.setReconnectAttempts(1);
serverLocator.setUseGlobalPools(false);
serverLocator.setAutoGroup(true);
serverLocator.setGroupID("binpastes-views");
serverLocator.setPreAcknowledge(true);
var serverLocator = ActiveMQClient.createServerLocator("vm://0")
.setReconnectAttempts(1)
.setFlowControlThreadPoolMaxSize(1)
.setScheduledThreadPoolMaxSize(1)
.setThreadPoolMaxSize(Runtime.getRuntime().availableProcessors())
.setUseGlobalPools(false)
.setAutoGroup(false)
.setPreAcknowledge(true); // tradeoff to lose views potentially
return serverLocator;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Objects;

import static com.github.binpastes.paste.domain.Paste.PasteExposure;

Expand Down Expand Up @@ -85,9 +86,13 @@ public Mono<Void> requestDeletion(String id, String remoteAddress) {
.map(Paste::markAsExpired)
.flatMap(pasteRepository::save)
.retryWhen(Retry
.backoff(5, Duration.ofMillis(500))
.backoff(3, Duration.ofMillis(100))
.filter(ex -> ex instanceof OptimisticLockingFailureException))
.doOnNext(paste -> log.info("Deleted paste {} on behalf of {}", paste.getId(), remoteAddress))
.doOnNext(paste -> log.atInfo()
.addArgument(paste.getId())
.addArgument(Objects.toString(remoteAddress, "anonymous"))
.log("Deleted paste {} on behalf of {}")
)
.then();
}
}
1 change: 1 addition & 0 deletions backend/src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#logging.level.org.apache.activemq.artemis.core.server=INFO
#logging.level.org.flywaydb.core.internal.license.VersionPrinter=INFO
logging.level.com.github.binpastes.paste.application.tracking=DEBUG
logging.level.com.github.binpastes.paste.domain.PasteService=DEBUG

spring.flyway.enabled=true
spring.flyway.driver-class-name=org.h2.Driver
Expand Down

0 comments on commit c8e835e

Please sign in to comment.