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

Removed Guava dependency and switched to Spring events #2

Merged
merged 1 commit into from Jun 27, 2018
File filter...
Filter file types
Jump to file or symbol
Failed to load files and symbols.
+79 −95
Diff settings

Always

Just for now

Copy path View file
@@ -48,7 +48,6 @@ dependencies {
compile 'com.fasterxml.jackson.module:jackson-module-kotlin:2.9.2'
compile 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8'
compile 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
compile 'com.google.guava:guava:24.1.1-jre'
compile 'org.apache.commons:commons-lang3:3.7'

testCompile 'org.springframework.boot:spring-boot-starter-test'
@@ -1,16 +1,16 @@
package de.bringmeister.connect.product.application.cdn

import com.google.common.eventbus.Subscribe
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.context.event.EventListener
import org.springframework.stereotype.Service

@Service
class ImageCdnService() {

private val log: Logger = LoggerFactory.getLogger(this.javaClass)

@Subscribe
@EventListener
fun handle(command: UpdateCdnCommand) {
Thread.sleep(4000)
log.info("Image CDN has been updated. [productNumber={}]", command.productNumber)
@@ -1,12 +1,12 @@
package de.bringmeister.connect.product.application.mediadata

import com.google.common.eventbus.Subscribe
import org.springframework.context.event.EventListener
import org.springframework.stereotype.Service

@Service
class MediaDataService(private val mediaDataRegistry: MediaDataRegistry) {

@Subscribe
@EventListener
fun handle(command: RegisterForMediaDataUpdatesCommand) {
mediaDataRegistry.handle(command)
}
@@ -1,6 +1,5 @@
package de.bringmeister.connect.product.application.product

import com.google.common.eventbus.Subscribe
import de.bringmeister.connect.product.domain.DomainEventBus
import de.bringmeister.connect.product.domain.product.CreateNewProductCommand
import de.bringmeister.connect.product.domain.product.Product
@@ -10,6 +9,7 @@ import de.bringmeister.connect.product.domain.product.UpdateMasterDataCommand
import de.bringmeister.connect.product.domain.product.UpdateMediaDataCommand
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.context.event.EventListener
import org.springframework.stereotype.Service

@Service
@@ -18,14 +18,14 @@ class ProductService(private val productRepository: ProductRepository,

private val log: Logger = LoggerFactory.getLogger(this.javaClass)

@Subscribe
@EventListener
fun handle(command: CreateNewProductCommand) {
val product = Product(command)
productRepository.save(product)
domainEventBus.sendAll(product.occurredEvents())
}

@Subscribe
@EventListener
fun handle(command: UpdateMasterDataCommand) {
val productNumber = ProductNumber(command.productNumber)
val product = productRepository.find(productNumber)
@@ -34,7 +34,7 @@ class ProductService(private val productRepository: ProductRepository,
domainEventBus.sendAll(product.occurredEvents())
}

@Subscribe
@EventListener
fun handle(command: UpdateMediaDataCommand) {
val productNumber = ProductNumber(command.productNumber)
if (productRepository.exists(productNumber)) {
@@ -1,16 +1,16 @@
package de.bringmeister.connect.product.application.search

import com.google.common.eventbus.Subscribe
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.context.event.EventListener
import org.springframework.stereotype.Service

@Service
class SearchIndexService() {

private val log: Logger = LoggerFactory.getLogger(this.javaClass)

@Subscribe
@EventListener
fun handle(command: UpdateSearchIndexCommand) {
Thread.sleep(1000)
log.info("Search index has been updated. [productNumber={}]", command.productNumber)
@@ -1,16 +1,16 @@
package de.bringmeister.connect.product.application.shop

import com.google.common.eventbus.Subscribe
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.context.event.EventListener
import org.springframework.stereotype.Service

@Service
class ShopService() {

private val log: Logger = LoggerFactory.getLogger(this.javaClass)

@Subscribe
@EventListener
fun handle(command: UpdateShopCommand) {
Thread.sleep(2000)
log.info("Shop has been updated. [productNumber={}]", command.productNumber)

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,27 @@
package de.bringmeister.connect.product.infrastructure.spring

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.event.ApplicationEventMulticaster
import org.springframework.context.event.SimpleApplicationEventMulticaster
import org.springframework.core.task.SimpleAsyncTaskExecutor
import org.springframework.scheduling.support.TaskUtils.LOG_AND_SUPPRESS_ERROR_HANDLER

@Configuration
class SpringApplicationEventConfig {

/**
* We want our event/command handling to be asynchronous. By default,
* Spring will handle application events synchronous. The following
* bean will make the event/command handling asynchronous.
*
* See: http://zoltanaltfatter.com/2016/05/11/application-events-with-spring
*/
@Bean
fun applicationEventMulticaster(): ApplicationEventMulticaster {
return SimpleApplicationEventMulticaster().apply {
setTaskExecutor(SimpleAsyncTaskExecutor())
setErrorHandler(LOG_AND_SUPPRESS_ERROR_HANDLER)
}
}
}
@@ -0,0 +1,14 @@
package de.bringmeister.connect.product.infrastructure.spring

import de.bringmeister.connect.product.domain.Command
import de.bringmeister.connect.product.domain.CommandBus
import org.springframework.context.ApplicationEventPublisher
import org.springframework.stereotype.Component

@Component
class SpringCommandBus(private val publisher: ApplicationEventPublisher): CommandBus {

override fun send(command: Command) {
publisher.publishEvent(command)
}
}
@@ -0,0 +1,14 @@
package de.bringmeister.connect.product.infrastructure.spring

import de.bringmeister.connect.product.domain.DomainEvent
import de.bringmeister.connect.product.domain.DomainEventBus
import org.springframework.context.ApplicationEventPublisher
import org.springframework.stereotype.Component

@Component
class SpringEventBus(private val publisher: ApplicationEventPublisher): DomainEventBus {

override fun send(domainEvent: DomainEvent) {
publisher.publishEvent(domainEvent)
}
}
@@ -1,19 +1,19 @@
package de.bringmeister.connect.product.ports.messages

import com.google.common.eventbus.Subscribe
import de.bringmeister.connect.product.domain.CommandBus
import de.bringmeister.connect.product.domain.product.CreateNewProductCommand
import de.bringmeister.connect.product.domain.product.ProductNumber
import de.bringmeister.connect.product.domain.product.ProductRepository
import de.bringmeister.connect.product.domain.product.UpdateMasterDataCommand
import de.bringmeister.connect.product.ports.rest.MasterDataUpdateAvailableEvent
import org.springframework.context.event.EventListener
import org.springframework.stereotype.Component

@Component
class MasterDataUpdateAvailableEventListener(private val commandBus: CommandBus,
private val productRepository: ProductRepository) {

@Subscribe
@EventListener
fun handle(domainEvent: MasterDataUpdateAvailableEvent) {

Thread.sleep(5000)
@@ -1,16 +1,16 @@
package de.bringmeister.connect.product.ports.messages

import com.google.common.eventbus.Subscribe
import de.bringmeister.connect.product.application.search.UpdateSearchIndexCommand
import de.bringmeister.connect.product.application.shop.UpdateShopCommand
import de.bringmeister.connect.product.domain.CommandBus
import de.bringmeister.connect.product.domain.product.MasterDataUpdatedEvent
import org.springframework.context.event.EventListener
import org.springframework.stereotype.Component

@Component
class MasterDataUpdatedEventListener(private val commandBus: CommandBus) {

@Subscribe
@EventListener
fun handle(domainEvent: MasterDataUpdatedEvent) {

commandBus.send(UpdateShopCommand(
@@ -1,15 +1,15 @@
package de.bringmeister.connect.product.ports.messages

import com.google.common.eventbus.Subscribe
import de.bringmeister.connect.product.domain.CommandBus
import de.bringmeister.connect.product.domain.product.UpdateMediaDataCommand
import de.bringmeister.connect.product.ports.rest.MediaDataUpdateAvailableEvent
import org.springframework.context.event.EventListener
import org.springframework.stereotype.Component

@Component
class MediaDataUpdateAvailableEventListener(private val commandBus: CommandBus) {

@Subscribe
@EventListener
fun handle(domainEvent: MediaDataUpdateAvailableEvent) {

commandBus.send(UpdateMediaDataCommand(
@@ -1,15 +1,15 @@
package de.bringmeister.connect.product.ports.messages

import com.google.common.eventbus.Subscribe
import de.bringmeister.connect.product.application.cdn.UpdateCdnCommand
import de.bringmeister.connect.product.domain.CommandBus
import de.bringmeister.connect.product.application.mediadata.MediaDataUpdatedEvent
import de.bringmeister.connect.product.domain.CommandBus
import org.springframework.context.event.EventListener
import org.springframework.stereotype.Component

@Component
class MediaDataUpdatedEventListener(private val commandBus: CommandBus) {

@Subscribe
@EventListener
fun handle(domainEvent: MediaDataUpdatedEvent) {

val updateCdnCommand = UpdateCdnCommand(domainEvent.productNumber)
@@ -1,15 +1,15 @@
package de.bringmeister.connect.product.ports.messages

import com.google.common.eventbus.Subscribe
import de.bringmeister.connect.product.application.mediadata.RegisterForMediaDataUpdatesCommand
import de.bringmeister.connect.product.domain.CommandBus
import de.bringmeister.connect.product.domain.product.ProductCreatedEvent
import de.bringmeister.connect.product.application.mediadata.RegisterForMediaDataUpdatesCommand
import org.springframework.context.event.EventListener
import org.springframework.stereotype.Component

@Component
class ProductCreatedEventListener(private val commandBus: CommandBus) {

@Subscribe
@EventListener
fun handle(domainEvent: ProductCreatedEvent) {
val requestEnrichmentDataCommand = RegisterForMediaDataUpdatesCommand(domainEvent.productNumber)
commandBus.send(requestEnrichmentDataCommand)
ProTip! Use n and p to navigate between commits in a pull request.