Skip to content

Commit

Permalink
Added EventPublishingService that represents AxonFramework EventGateway
Browse files Browse the repository at this point in the history
  • Loading branch information
JohT committed Dec 28, 2021
1 parent 7f184cf commit 942328b
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@
import io.github.joht.showcase.quarkuseventsourcing.messaging.infrastructure.axon.serializer.jsonb.axon.JsonbSerializer;
import io.github.joht.showcase.quarkuseventsourcing.messaging.infrastructure.axon.transaction.jta.JtaTransactionManager;
import io.github.joht.showcase.quarkuseventsourcing.messaging.infrastructure.axon.upcaster.AnnotationEventRevisionResolver;
import io.github.joht.showcase.quarkuseventsourcing.messaging.query.axon.EventPublishingAdapter;
import io.github.joht.showcase.quarkuseventsourcing.messaging.query.axon.QueryReplayAdapter;
import io.github.joht.showcase.quarkuseventsourcing.messaging.query.axon.QuerySubmitterAdapter;
import io.github.joht.showcase.quarkuseventsourcing.messaging.query.axon.QueryUpdateEmitterAdapter;
import io.github.joht.showcase.quarkuseventsourcing.messaging.query.boundary.EventPublishingService;
import io.github.joht.showcase.quarkuseventsourcing.messaging.query.boundary.QueryModelProjection;
import io.github.joht.showcase.quarkuseventsourcing.messaging.query.boundary.QueryProcessor;
import io.github.joht.showcase.quarkuseventsourcing.messaging.query.boundary.QueryProjectionManagementService;
Expand Down Expand Up @@ -177,6 +179,12 @@ public QueryProjectionManagementService getQueryReplayService() {
return new QueryReplayAdapter(configuration.eventProcessingConfiguration());
}

@Produces
@ApplicationScoped
public EventPublishingService getEventPublishingService() {
return new EventPublishingAdapter(configuration.eventGateway());
}

private Connection getConnection() throws SQLException {
return dataSource.getConnection();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.github.joht.showcase.quarkuseventsourcing.messaging.query.axon;

import static javax.transaction.Transactional.TxType.REQUIRED;

import javax.transaction.Transactional;

import org.axonframework.eventhandling.gateway.EventGateway;

import io.github.joht.showcase.quarkuseventsourcing.messaging.query.boundary.EventPublishingService;

public class EventPublishingAdapter implements EventPublishingService {

private final EventGateway eventGateway;

public EventPublishingAdapter(EventGateway eventGateway) {
this.eventGateway = eventGateway;
}

/**
* {@inheritDoc}
*/
@Override
@Transactional(REQUIRED)
public void publish(Object... events) {
eventGateway.publish(events);
}

@Override
public String toString() {
return "EventPublishingAdapter [eventGateway=" + eventGateway + "]";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.github.joht.showcase.quarkuseventsourcing.messaging.query.boundary;

/**
* Provides methods to publish events.
* Based on the "EventGateway" in "AxonFramework".
*/
public interface EventPublishingService {

/**
* Publishes events that will be dispatched to all subscribed listeners.
*
* @param events The collection of events to publish
*/
void publish(Object... events);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.github.joht.showcase.quarkuseventsourcing.messaging.query.axon;

import static org.mockito.Mockito.verify;

import org.axonframework.eventhandling.gateway.EventGateway;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
class EventPublishingAdapterTest {

@Mock
EventGateway eventGateway;

@InjectMocks
EventPublishingAdapter adapterUnderTest;

@Test
void eventPublishDelegatedToEventGateway() {
TestEvent testEvent = new TestEvent();
adapterUnderTest.publish(testEvent);
verify(eventGateway).publish(testEvent);
}

private static class TestEvent {

}
}

0 comments on commit 942328b

Please sign in to comment.