Skip to content

Commit

Permalink
Changed from HTTP to GRPC projection admin API
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-schnell committed Dec 31, 2023
1 parent 366a132 commit f964397
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 102 deletions.
5 changes: 0 additions & 5 deletions java-se-cdi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@
<artifactId>esc-esgrpc</artifactId>
</dependency>

<dependency>
<groupId>org.fuin.esc</groupId>
<artifactId>esc-http-admin</artifactId>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package org.fuin.cqrs4j.example.javasecdi.qry.app;

import com.eventstore.dbclient.EventStoreDBClientSettings;
import com.eventstore.dbclient.EventStoreDBProjectionManagementClient;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Disposes;
import jakarta.enterprise.inject.Produces;
import org.fuin.cqrs4j.example.javasecdi.shared.app.SharedConfig;
import org.fuin.esc.admin.HttpProjectionAdminEventStore;
import org.fuin.esc.api.ProjectionAdminEventStore;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.http.HttpClient;
import org.fuin.esc.esgrpc.GrpcProjectionAdminEventStore;

/**
* CDI factory that creates a {@link ProjectionAdminEventStore} instance.
Expand All @@ -19,15 +17,14 @@ public class QryProjectionAdminEventStoreFactory {

@Produces
@ApplicationScoped
public ProjectionAdminEventStore getProjectionAdminEventStore(final SharedConfig config, final HttpClient httpClient) {
final String url = "http://" + config.getEventStoreHost() + ":" + config.getEventStoreHttpPort();
try {
final ProjectionAdminEventStore es = new HttpProjectionAdminEventStore(httpClient, new URL(url));
es.open();
return es;
} catch (final MalformedURLException ex) {
throw new RuntimeException("Failed to create URL: " + url, ex);
}
public ProjectionAdminEventStore getProjectionAdminEventStore(final SharedConfig config) {
final EventStoreDBClientSettings settings = EventStoreDBClientSettings.builder()
.addHost(config.getEventStoreHost(), config.getEventStoreHttpPort())
.defaultCredentials(config.getEventStoreUser(), config.getEventStorePassword())
.tls(false)
.buildConnectionSettings();
final EventStoreDBProjectionManagementClient client = EventStoreDBProjectionManagementClient.create(settings);
return new GrpcProjectionAdminEventStore(client).open();
}

/**
Expand Down
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@
<version>${esc.version}</version>
</dependency>

<dependency>
<groupId>org.fuin.esc</groupId>
<artifactId>esc-http-admin</artifactId>
<version>${esc.version}</version>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
/**
* Copyright (C) 2015 Michael Schnell. All rights reserved. http://www.fuin.org/
*
* <p>
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
*
* <p>
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* <p>
* You should have received a copy of the GNU Lesser General Public License along with this library. If not, see
* http://www.gnu.org/licenses/.
*/
package org.fuin.cqrs4j.example.quarkus.command.api;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.fuin.objects4j.common.Nullable;
import jakarta.annotation.Nullable;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.ConstraintViolationException;
import jakarta.ws.rs.core.Context;
Expand All @@ -25,12 +21,15 @@
import jakarta.ws.rs.core.Response.Status;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;

import org.fuin.cqrs4j.SimpleResult;
import org.fuin.objects4j.common.Contract;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
* Maps the exceptions into a HTTP status.
*/
Expand Down
5 changes: 0 additions & 5 deletions quarkus/query/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@
<artifactId>esc-esgrpc</artifactId>
</dependency>

<dependency>
<groupId>org.fuin.esc</groupId>
<artifactId>esc-http-admin</artifactId>
</dependency>

<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>jakarta.mail</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions quarkus/shared/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@
<artifactId>esc-esgrpc</artifactId>
</dependency>

<dependency>
<groupId>org.fuin.esc</groupId>
<artifactId>esc-http-admin</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package org.fuin.cqrs4j.example.quarkus.shared;

import com.eventstore.dbclient.EventStoreDBClientSettings;
import com.eventstore.dbclient.EventStoreDBProjectionManagementClient;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Disposes;
import jakarta.enterprise.inject.Produces;
import org.fuin.esc.admin.HttpProjectionAdminEventStore;
import org.fuin.esc.api.ProjectionAdminEventStore;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.http.HttpClient;
import org.fuin.esc.esgrpc.GrpcProjectionAdminEventStore;

/**
* CDI factory that creates a {@link ProjectionAdminEventStore} instance.
Expand All @@ -18,15 +16,16 @@ public class ProjectionAdminEventStoreFactory {

@Produces
@ApplicationScoped
public ProjectionAdminEventStore getProjectionAdminEventStore(final Config config, final HttpClient httpClient) {
final String url = config.getEventStoreProtocol() + "://" + config.getEventStoreHost() + ":" + config.getEventStoreHttpPort();
try {
final ProjectionAdminEventStore es = new HttpProjectionAdminEventStore(httpClient, new URL(url));
es.open();
return es;
} catch (final MalformedURLException ex) {
throw new RuntimeException("Failed to create URL: " + url, ex);
}
public ProjectionAdminEventStore getProjectionAdminEventStore(final Config config) {

final EventStoreDBClientSettings settings = EventStoreDBClientSettings.builder()
.addHost(config.getEventStoreHost(), config.getEventStoreHttpPort())
.defaultCredentials(config.getEventStoreUser(), config.getEventStorePassword())
.tls(false)
.buildConnectionSettings();
final EventStoreDBProjectionManagementClient client = EventStoreDBProjectionManagementClient.create(settings);
return new GrpcProjectionAdminEventStore(client).open();

}

/**
Expand Down
6 changes: 0 additions & 6 deletions spring-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@
<version>${esc.version}</version>
</dependency>

<dependency>
<groupId>org.fuin.esc</groupId>
<artifactId>esc-http-admin</artifactId>
<version>${esc.version}</version>
</dependency>

<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.json</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions spring-boot/query/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@
<artifactId>esc-esgrpc</artifactId>
</dependency>

<dependency>
<groupId>org.fuin.esc</groupId>
<artifactId>esc-http-admin</artifactId>
</dependency>

<!-- runtime -->

<dependency>
Expand Down
5 changes: 0 additions & 5 deletions spring-boot/shared/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@
<artifactId>esc-esgrpc</artifactId>
</dependency>

<dependency>
<groupId>org.fuin.esc</groupId>
<artifactId>esc-http-admin</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import com.eventstore.dbclient.EventStoreDBClient;
import com.eventstore.dbclient.EventStoreDBClientSettings;
import com.eventstore.dbclient.EventStoreDBProjectionManagementClient;
import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;
import jakarta.json.bind.JsonbConfig;
import org.eclipse.yasson.FieldAccessStrategy;
import org.fuin.cqrs4j.example.shared.SharedUtils;
import org.fuin.esc.admin.HttpProjectionAdminEventStore;
import org.fuin.esc.api.ProjectionAdminEventStore;
import org.fuin.esc.esgrpc.ESGrpcEventStore;
import org.fuin.esc.esgrpc.GrpcProjectionAdminEventStore;
import org.fuin.esc.esgrpc.IESGrpcEventStore;
import org.fuin.esc.spi.EnhancedMimeType;
import org.fuin.esc.spi.SerDeserializerRegistry;
Expand All @@ -19,7 +20,6 @@
import java.net.Authenticator;
import java.net.MalformedURLException;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.net.http.HttpClient;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
Expand All @@ -40,30 +40,42 @@ public Jsonb createJsonb() {
return JsonbBuilder.create(config);
}


@Bean
public EventStoreDBClient createEventStoreDBClient(final Config config) {
final EventStoreDBClientSettings settings = EventStoreDBClientSettings.builder()
.addHost(config.getEventStoreHost(), config.getEventStoreHttpPort())
.defaultCredentials(config.getEventStoreUser(), config.getEventStorePassword())
.tls(false)
.buildConnectionSettings();
return EventStoreDBClient.create(settings);
}

@Bean
public EventStoreDBProjectionManagementClient createEventStoreDBProjectionManagementClient(final Config config) {
final EventStoreDBClientSettings settings = EventStoreDBClientSettings.builder()
.addHost(config.getEventStoreHost(), config.getEventStoreHttpPort())
.defaultCredentials(config.getEventStoreUser(), config.getEventStorePassword())
.tls(false)
.buildConnectionSettings();
return EventStoreDBProjectionManagementClient.create(settings);
}


/**
* Creates an event store connection.
*
* @param config Configuration to use.
* @param client Client to use.
* @return New event store instance.
*/
@Bean(destroyMethod = "close")
public IESGrpcEventStore getESJCEventStore(final Config config) {
public IESGrpcEventStore getESJCEventStore(final EventStoreDBClient client) {

final SerDeserializerRegistry registry = SharedUtils.createRegistry();

final EventStoreDBClientSettings setts = EventStoreDBClientSettings.builder()
.addHost(config.getEventStoreHost(), config.getEventStoreHttpPort())
.defaultCredentials(config.getEventStoreUser(), config.getEventStorePassword())
.tls(false)
.buildConnectionSettings();

final EventStoreDBClient client = EventStoreDBClient.create(setts);
final IESGrpcEventStore eventstore = new ESGrpcEventStore.Builder().eventStore(client).serDesRegistry(registry)
return new ESGrpcEventStore.Builder().eventStore(client).serDesRegistry(registry)
.targetContentType(EnhancedMimeType.create("application", "json", StandardCharsets.UTF_8))
.build();

eventstore.open();
return eventstore;
.build().open();

}

Expand All @@ -82,22 +94,14 @@ protected PasswordAuthentication getPasswordAuthentication() {


/**
* Creates an HTTP based projection admin event store.
* Creates an GRPC based projection admin event store.
*
* @param config Configuration to use.
* @param httpClient Client to use.
* @param client Client to use.
* @return New event store instance.
*/
@Bean(destroyMethod = "close")
public ProjectionAdminEventStore getProjectionAdminEventStore(final Config config, final HttpClient httpClient) {
final String url = config.getEventStoreProtocol() + "://" + config.getEventStoreHost() + ":" + config.getEventStoreHttpPort();
try {
final ProjectionAdminEventStore es = new HttpProjectionAdminEventStore(httpClient, new URL(url));
es.open();
return es;
} catch (final MalformedURLException ex) {
throw new RuntimeException("Failed to create URL: " + url, ex);
}
public ProjectionAdminEventStore getProjectionAdminEventStore(final EventStoreDBProjectionManagementClient client) {
return new GrpcProjectionAdminEventStore(client).open();
}

}

0 comments on commit f964397

Please sign in to comment.