Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature : Quarkus integration #320

Merged
merged 6 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ jobs:
sed -i "s_\(<version>\)[^<]*_\1${revision}_g" transactionoutbox-guice/README.md
sed -i "s_\(<version>\)[^<]*_\1${revision}_g" transactionoutbox-jooq/README.md
sed -i "s_\(<version>\)[^<]*_\1${revision}_g" transactionoutbox-spring/README.md
sed -i "s_\(<version>\)[^<]*_\1${revision}_g" transactionoutbox-cdi/README.md
RomainWilbert marked this conversation as resolved.
Show resolved Hide resolved
sed -i "s_\(implementation 'com.gruelbox:transactionoutbox-core:\)[^']*_\1${revision}_g" README.md
sed -i "s_\(implementation 'com.gruelbox:transactionoutbox-guice:\)[^']*_\1${revision}_g" transactionoutbox-guice/README.md
sed -i "s_\(implementation 'com.gruelbox:transactionoutbox-jooq:\)[^']*_\1${revision}_g" transactionoutbox-jooq/README.md
sed -i "s_\(implementation 'com.gruelbox:transactionoutbox-spring:\)[^']*_\1${revision}_g" transactionoutbox-spring/README.md
sed -i "s_\(implementation 'com.gruelbox:transactionoutbox-cdi:\)[^']*_\1${revision}_g" transactionoutbox-cdi/README.md
env:
GITHUB_TOKEN: ${{ github.token }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
Expand All @@ -55,10 +57,12 @@ jobs:
sed -i "s_\(<version>\)[^<]*_\1${revision}_g" transactionoutbox-guice/README.md
sed -i "s_\(<version>\)[^<]*_\1${revision}_g" transactionoutbox-jooq/README.md
sed -i "s_\(<version>\)[^<]*_\1${revision}_g" transactionoutbox-spring/README.md
sed -i "s_\(<version>\)[^<]*_\1${revision}_g" transactionoutbox-cdi/README.md
sed -i "s_\(implementation 'com.gruelbox:transactionoutbox-core:\)[^']*_\1${revision}_g" README.md
sed -i "s_\(implementation 'com.gruelbox:transactionoutbox-guice:\)[^']*_\1${revision}_g" transactionoutbox-guice/README.md
sed -i "s_\(implementation 'com.gruelbox:transactionoutbox-jooq:\)[^']*_\1${revision}_g" transactionoutbox-jooq/README.md
sed -i "s_\(implementation 'com.gruelbox:transactionoutbox-spring:\)[^']*_\1${revision}_g" transactionoutbox-spring/README.md
sed -i "s_\(implementation 'com.gruelbox:transactionoutbox-cdi:\)[^']*_\1${revision}_g" transactionoutbox-cdi/README.md

- name: Create version update pull request
uses: gruelbox/create-pull-request@v2
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
**/.classpath
**/.project
**/.settings
**/.factorypath
/.idea
/*.iml
**/target/**
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<module>transactionoutbox-spring</module>
<module>transactionoutbox-guice</module>
<module>transactionoutbox-jooq</module>
<module>transactionoutbox-cdi</module>
RomainWilbert marked this conversation as resolved.
Show resolved Hide resolved
</modules>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Connection obtainConnection() {
public void validate(Validator validator) {
validator.notBlank("driverClassName", driverClassName);
validator.notBlank("url", url);
validator.notBlank("user",user);
validator.notBlank("user", user);
validator.notBlank("password", password);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public void valid(String propertyName, Object object) {
if (!(object instanceof Validatable)) {
return;
}
((Validatable)object).validate(new Validator(path.isEmpty() ? propertyName : (path + "." + propertyName), this));
((Validatable) object)
.validate(new Validator(path.isEmpty() ? propertyName : (path + "." + propertyName), this));
}

public void notNull(String propertyName, Object object) {
Expand Down Expand Up @@ -68,6 +69,7 @@ public void min(String propertyName, int object, int minimumValue) {
}

private void error(String propertyName, String message) {
throw new IllegalArgumentException((path.isEmpty() ? "" : path + ".") + propertyName + " " + message);
throw new IllegalArgumentException(
(path.isEmpty() ? "" : path + ".") + propertyName + " " + message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import lombok.extern.slf4j.Slf4j;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.MatcherAssert;
import org.junit.Assume;
import org.junit.jupiter.api.Assertions;
Expand Down
88 changes: 88 additions & 0 deletions transactionoutbox-quarkus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# transactionoutbox-quarkus


Extension for [transaction-outbox-core](../README.md) which integrates CDI's DI and Quarkus transaction management.

Tested with Quarkus implementation (Arc/Agroal)

## Installation

### Stable releases

The latest stable release is available from Maven Central.

#### Maven

```xml
<dependency>
<groupId>com.gruelbox</groupId>
<artifactId>transactionoutbox-quarkus</artifactId>
<version>4.3.281</version>
</dependency>
```

#### Gradle

```groovy
implementation 'com.gruelbox:transactionoutbox-quarkus:4.3.281'
```

### Development snapshots

Maven Central is updated regularly. Alternatively, if you want to stay at the bleeding edge, you can use continuously-delivered releases from [Github Package Repository](https://github.com/gruelbox/transaction-outbox/packages). These can be used from production builds since they will never be deleted.

#### Maven

```xml
<repositories>
<repository>
<id>github-transaction-outbox</id>
<name>Gruelbox Github Repository</name>
<url>https://maven.pkg.github.com/gruelbox/transaction-outbox</url>
</repository>
</repositories>
```

You will need to authenticate with Github to use Github Package Repository. Create a personal access token in [your GitHub settings](https://github.com/settings/tokens). It only needs **read:package** permissions. Then add something like the following in your Maven `settings.xml`:

```xml
<servers>
<server>
<id>github-transaction-outbox</id>
<username>${env.GITHUB_USERNAME}</username>
<password>${env.GITHUB_TOKEN}</password>
</server>
</servers>
```

The above example uses environment variables, allowing you to keep the credentials out of source control, but you can hard-code them if you know what you're doing.

## Configuration

Create your `TransactionOutbox` as a bean:

```java

@Produces
public TransactionOutbox transactionOutbox(QuarkusTransactionManager transactionManager)
{
return TransactionOutbox.builder().instantiator(CdiInstantiator.create()).transactionManager(transactionManager).persistor(Persistor.forDialect(Dialect.H2)).build();
}
```

## Usage

```java
@Transactional
public void doStuff() {
customerRepository.save(new Customer(1L, "Martin", "Carthy"));
customerRepository.save(new Customer(2L, "Dave", "Pegg"));
outbox.get().schedule(getClass()).publishCustomerCreatedEvent(1L);
outbox.get().schedule(getClass()).publishCustomerCreatedEvent(2L);
}

void publishCustomerCreatedEvent(long id) {
// Remote call here
}
```

88 changes: 88 additions & 0 deletions transactionoutbox-quarkus/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>transactionoutbox-parent</artifactId>
<groupId>com.gruelbox</groupId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<name>Transaction Outbox CDI</name>
RomainWilbert marked this conversation as resolved.
Show resolved Hide resolved
<packaging>jar</packaging>
<artifactId>transactionoutbox-quarkus</artifactId>
<description>A safe implementation of the transactional outbox pattern for Java (CDI extension library)
</description>

<properties>
<quarkus.version>2.11.1.Final</quarkus.version>
</properties>

<dependencies>

<!-- Runtime -->
<dependency>
<groupId>com.gruelbox</groupId>
<artifactId>transactionoutbox-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.transaction</groupId>
<artifactId>jakarta.transaction-api</artifactId>
</dependency>

<!-- Test -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-agroal</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-undertow</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus.platform</groupId>
<artifactId>quarkus-bom</artifactId>
<version>${quarkus.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.gruelbox.transactionoutbox;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.spi.CDI;

@ApplicationScoped
public class CdiInstantiator extends AbstractFullyQualifiedNameInstantiator {

public static CdiInstantiator create() {
return new CdiInstantiator();
}

private CdiInstantiator() {}

@Override
protected Object createInstance(Class<?> clazz) {
return CDI.current().select(clazz).get();
}
}
Loading