Skip to content

Commit

Permalink
Migrated to new GRPC eventstore connection
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-schnell committed Dec 30, 2023
1 parent 6d2049e commit 84c6e4a
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 230 deletions.
3 changes: 0 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ services:
EVENTSTORE_MEM_DB: "true"
EVENTSTORE_RUN_PROJECTIONS: "All"
EVENTSTORE_INSECURE: "true"
EVENTSTORE_ENABLE_EXTERNAL_TCP: "true"
EVENTSTORE_ENABLE_ATOM_PUB_OVER_HTTP: "true"
EVENTSTORE_LOG: "/tmp/log-eventstore"
ports:
- "1113:1113"
- "2113:2113"
networks:
- cqrs4j-quarkus-example-net
Expand Down
5 changes: 3 additions & 2 deletions java-se-cdi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Minimal standalone example application that uses the [ddd-4-java](https://github
## Starting the demo

1. Start an EventStore locally on your PC
* You can use the [EventStore Docker Image](https://hub.docker.com/r/eventstore/eventstore/): ```docker run --name eventstore-node -p 2113:2113 -p 1113:1113 --rm eventstore/eventstore:release-5.0.9```
* Use the [docker-compose.yml](../docker-compose.yml) script: `docker-compose up`
* Or simply start an instance (See [Install and run Event Store](https://eventstore.org/docs/server/index.html?tabs=tabid-1) for more information)
2. Run the [QryExampleApp](src/main/java/org/fuin/cqrs4j/example/javasecdi/qry/app/QryExampleApp.java) to make the view/read part listen to new events
* You should see something like this on the console: ```INFO o.f.d.qry.handler.QryProjector - Create projection 'qry-person-stream' with events: [PersonCreatedEvent]```
Expand All @@ -19,7 +19,8 @@ Minimal standalone example application that uses the [ddd-4-java](https://github
* If you open the [Event Store UI](http://localhost:2113/web/index.html#/projections) (User 'admin' / Password 'changeit') and open the projection details for 'qry-person-stream' it should show 'Events processed = 1'
* Look at the person's aggregate event stream: ```http://localhost:2113/web/index.html#/streams/PERSON-00000000-0000-0000-0000-000000000000`` - Replace the zero UUID with the one shown in the event handler message 'Person 'Peter Parker Inc.' (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) was created'
4. Kill the [QryExampleApp](src/main/java/org/fuin/cqrs4j/example/javasecdi/qry/app/QryExampleApp.java)
5. Stop the event store
5. Stop the event store (Pressing CTRL+C keys)
* Use the [docker-compose.yml](../docker-compose.yml) script: `docker-compose rm` to clean up the images if you used Docker Compose

## What is in the application?
The application is splitted into three packages: 'shared', 'cmd' and 'qry'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,126 +12,103 @@
*/
package org.fuin.cqrs4j.example.javasecdi.shared.app;

import org.eclipse.microprofile.config.inject.ConfigProperty;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

import org.eclipse.microprofile.config.inject.ConfigProperty;

/**
* Application configuration.
*/
@ApplicationScoped
public class SharedConfig {

private static final String EVENT_STORE_HOST = "127.0.0.1";

private static final int EVENT_STORE_HTTP_PORT = 2113;

private static final int EVENT_STORE_TCP_PORT = 1113;

private static final String EVENT_STORE_USER = "admin";

private static final String EVENT_STORE_PASSWORD = "changeit";

@Inject
@ConfigProperty(name = "EVENT_STORE_HOST", defaultValue = EVENT_STORE_HOST)
private String eventStoreHost;

@Inject
@ConfigProperty(name = "EVENT_STORE_HTTP_PORT", defaultValue = "" + EVENT_STORE_HTTP_PORT)
private int eventStoreHttpPort;

@Inject
@ConfigProperty(name = "EVENT_STORE_TCP_PORT", defaultValue = "" + EVENT_STORE_TCP_PORT)
private int eventStoreTcpPort;

@Inject
@ConfigProperty(name = "EVENT_STORE_USER", defaultValue = EVENT_STORE_USER)
private String eventStoreUser;

@Inject
@ConfigProperty(name = "EVENT_STORE_PASSWORD", defaultValue = EVENT_STORE_PASSWORD)
private String eventStorePassword;

/**
* Constructor using default values internally.
*/
public SharedConfig() {
super();
this.eventStoreHost = EVENT_STORE_HOST;
this.eventStoreHttpPort = EVENT_STORE_HTTP_PORT;
this.eventStoreTcpPort = EVENT_STORE_TCP_PORT;
this.eventStoreUser = EVENT_STORE_USER;
this.eventStorePassword = EVENT_STORE_PASSWORD;
}

/**
* Constructor with all data.
*
* @param eventStoreHost
* Host.
* @param eventStoreHttpPort
* HTTP port
* @param eventStoreTcpPort
* TCP port.
* @param eventStoreUser
* User.
* @param eventStorePassword
* Password.
*/
public SharedConfig(final String eventStoreHost, final int eventStoreHttpPort, final int eventStoreTcpPort, final String eventStoreUser,
final String eventStorePassword) {
super();
this.eventStoreHost = eventStoreHost;
this.eventStoreHttpPort = eventStoreHttpPort;
this.eventStoreTcpPort = eventStoreTcpPort;
this.eventStoreUser = eventStoreUser;
this.eventStorePassword = eventStorePassword;
}

/**
* Returns the host name of the event store.
*
* @return Name.
*/
public String getEventStoreHost() {
return eventStoreHost;
}

/**
* Returns the HTTP port of the event store.
*
* @return Port.
*/
public int getEventStoreHttpPort() {
return eventStoreHttpPort;
}

/**
* Returns the TCP port of the event store.
*
* @return Port.
*/
public int getEventStoreTcpPort() {
return eventStoreTcpPort;
}

/**
* Returns the username of the event store.
*
* @return Username.
*/
public String getEventStoreUser() {
return eventStoreUser;
}

/**
* Returns the password of the event store.
*
* @return Password.
*/
public String getEventStorePassword() {
return eventStorePassword;
}
private static final String EVENT_STORE_HOST = "127.0.0.1";

private static final int EVENT_STORE_HTTP_PORT = 2113;

private static final String EVENT_STORE_USER = "admin";

private static final String EVENT_STORE_PASSWORD = "changeit";

@Inject
@ConfigProperty(name = "EVENT_STORE_HOST", defaultValue = EVENT_STORE_HOST)
private String eventStoreHost;

@Inject
@ConfigProperty(name = "EVENT_STORE_HTTP_PORT", defaultValue = "" + EVENT_STORE_HTTP_PORT)
private int eventStoreHttpPort;

@Inject
@ConfigProperty(name = "EVENT_STORE_USER", defaultValue = EVENT_STORE_USER)
private String eventStoreUser;

@Inject
@ConfigProperty(name = "EVENT_STORE_PASSWORD", defaultValue = EVENT_STORE_PASSWORD)
private String eventStorePassword;

/**
* Constructor using default values internally.
*/
public SharedConfig() {
super();
this.eventStoreHost = EVENT_STORE_HOST;
this.eventStoreHttpPort = EVENT_STORE_HTTP_PORT;
this.eventStoreUser = EVENT_STORE_USER;
this.eventStorePassword = EVENT_STORE_PASSWORD;
}

/**
* Constructor with all data.
*
* @param eventStoreHost Host.
* @param eventStoreHttpPort HTTP port
* @param eventStoreUser User.
* @param eventStorePassword Password.
*/
public SharedConfig(final String eventStoreHost, final int eventStoreHttpPort, final String eventStoreUser,
final String eventStorePassword) {
super();
this.eventStoreHost = eventStoreHost;
this.eventStoreHttpPort = eventStoreHttpPort;
this.eventStoreUser = eventStoreUser;
this.eventStorePassword = eventStorePassword;
}

/**
* Returns the host name of the event store.
*
* @return Name.
*/
public String getEventStoreHost() {
return eventStoreHost;
}

/**
* Returns the HTTP port of the event store.
*
* @return Port.
*/
public int getEventStoreHttpPort() {
return eventStoreHttpPort;
}

/**
* Returns the username of the event store.
*
* @return Username.
*/
public String getEventStoreUser() {
return eventStoreUser;
}

/**
* Returns the password of the event store.
*
* @return Password.
*/
public String getEventStorePassword() {
return eventStorePassword;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class SharedEventStoreFactory {
public IESGrpcEventStore createEventStore(final SharedConfig config, final SerDeserializerRegistry registry) {

final EventStoreDBClientSettings setts = EventStoreDBClientSettings.builder()
.addHost(config.getEventStoreHost(), config.getEventStoreTcpPort())
.addHost(config.getEventStoreHost(), config.getEventStoreHttpPort())
.defaultCredentials(config.getEventStoreUser(), config.getEventStorePassword())
.tls(false)
.buildConnectionSettings();
Expand Down
3 changes: 0 additions & 3 deletions quarkus/command/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@
<mode>bridge</mode>
</network>
<ports>
<port>1113:1113</port>
<port>2113:2113</port>
</ports>
<log>
Expand All @@ -176,8 +175,6 @@
<EVENTSTORE_MEM_DB>TRUE</EVENTSTORE_MEM_DB>
<EVENTSTORE_RUN_PROJECTIONS>All</EVENTSTORE_RUN_PROJECTIONS>
<EVENTSTORE_INSECURE>true</EVENTSTORE_INSECURE>
<EVENTSTORE_ENABLE_EXTERNAL_TCP>true</EVENTSTORE_ENABLE_EXTERNAL_TCP>
<EVENTSTORE_ENABLE_ATOM_PUB_OVER_HTTP>true</EVENTSTORE_ENABLE_ATOM_PUB_OVER_HTTP>
<EVENTSTORE_LOG>/tmp/log-eventstore</EVENTSTORE_LOG>
</env>
<wait>
Expand Down
30 changes: 3 additions & 27 deletions quarkus/query/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,9 @@ Make sure you installed everything as described [here](../../../../).
## Running test in IDE
In case you want to run the integration test inside your IDE (Eclipse or other), you need to start the Eventstore and MariaDB before.

1. Start the Eventstore Docker container:

```
docker run -d --name eventstore-node \
-p 2113:2113 \
-p 1113:1113 \
--rm \
eventstore/eventstore:release-5.0.9
```

2. Start the MariaDB Docker container:

```
docker run -d --name mariadb \
-p 3306:3306 \
-e MYSQL_INITDB_SKIP_TZINFO=1 \
-e MYSQL_ROOT_PASSWORD=xyz \
-e MYSQL_DATABASE=querydb \
-e MYSQL_USER=mary \
-e MYSQL_PASSWORD=abc \
--rm \
mariadb:10.4
```

3. Run the test: [QryPersonResourceIT.java](src/test/java/org/fuin/cqrs4j/example/quarkus/query/api/QryPersonResourceIT.java)

4. Run `docker ps` to see the CONTAINER IDs and stop the Eventstore and MariaDB with `docker stop <CONTAINER_ID>`
1. Start the Eventstore and MariaDB Docker container using the [docker-compose.yml](../../docker-compose.yml) script: `docker-compose up`
2. Run the test: [QryPersonResourceIT.java](src/test/java/org/fuin/cqrs4j/example/quarkus/query/api/QryPersonResourceIT.java)
3. Stop the containers in the console using CTRL+C and then remove the containers using again Docker Compose: `docker-compose rm`

# TODO ... (Does currently not work)

Expand Down
3 changes: 0 additions & 3 deletions quarkus/query/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@
<mode>bridge</mode>
</network>
<ports>
<port>1113:1113</port>
<port>2113:2113</port>
</ports>
<log>
Expand All @@ -177,8 +176,6 @@
<EVENTSTORE_MEM_DB>TRUE</EVENTSTORE_MEM_DB>
<EVENTSTORE_RUN_PROJECTIONS>All</EVENTSTORE_RUN_PROJECTIONS>
<EVENTSTORE_INSECURE>true</EVENTSTORE_INSECURE>
<EVENTSTORE_ENABLE_EXTERNAL_TCP>true</EVENTSTORE_ENABLE_EXTERNAL_TCP>
<EVENTSTORE_ENABLE_ATOM_PUB_OVER_HTTP>true</EVENTSTORE_ENABLE_ATOM_PUB_OVER_HTTP>
<EVENTSTORE_LOG>/tmp/log-eventstore</EVENTSTORE_LOG>
</env>
<wait>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public class Config {

private static final int EVENT_STORE_HTTP_PORT = 2113;

private static final int EVENT_STORE_TCP_PORT = 1113;

private static final String EVENT_STORE_USER = "admin";

private static final String EVENT_STORE_PASSWORD = "changeit";
Expand All @@ -49,10 +47,6 @@ public class Config {
@ConfigProperty(name = "EVENT_STORE_HTTP_PORT", defaultValue = "" + EVENT_STORE_HTTP_PORT)
int eventStoreHttpPort;

@Inject
@ConfigProperty(name = "EVENT_STORE_TCP_PORT", defaultValue = "" + EVENT_STORE_TCP_PORT)
int eventStoreTcpPort;

@Inject
@ConfigProperty(name = "EVENT_STORE_USER", defaultValue = EVENT_STORE_USER)
String eventStoreUser;
Expand All @@ -69,7 +63,6 @@ public Config() {
this.eventStoreProtocol = EVENT_STORE_PROTOCOL;
this.eventStoreHost = EVENT_STORE_HOST;
this.eventStoreHttpPort = EVENT_STORE_HTTP_PORT;
this.eventStoreTcpPort = EVENT_STORE_TCP_PORT;
this.eventStoreUser = EVENT_STORE_USER;
this.eventStorePassword = EVENT_STORE_PASSWORD;
}
Expand All @@ -83,20 +76,17 @@ public Config() {
* Host.
* @param eventStoreHttpPort
* HTTP port
* @param eventStoreTcpPort
* TCP port.
* @param eventStoreUser
* User.
* @param eventStorePassword
* Password.
*/
public Config(final String eventStoreProtocol, final String eventStoreHost, final int eventStoreHttpPort, final int eventStoreTcpPort, final String eventStoreUser,
public Config(final String eventStoreProtocol, final String eventStoreHost, final int eventStoreHttpPort, final String eventStoreUser,
final String eventStorePassword) {
super();
this.eventStoreProtocol = eventStoreProtocol;
this.eventStoreHost = eventStoreHost;
this.eventStoreHttpPort = eventStoreHttpPort;
this.eventStoreTcpPort = eventStoreTcpPort;
this.eventStoreUser = eventStoreUser;
this.eventStorePassword = eventStorePassword;
}
Expand Down Expand Up @@ -128,15 +118,6 @@ public int getEventStoreHttpPort() {
return eventStoreHttpPort;
}

/**
* Returns the TCP port of the event store.
*
* @return Port.
*/
public int getEventStoreTcpPort() {
return eventStoreTcpPort;
}

/**
* Returns the username of the event store.
*
Expand Down
Loading

0 comments on commit 84c6e4a

Please sign in to comment.