-
Notifications
You must be signed in to change notification settings - Fork 792
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94bce9a
commit 4f54b97
Showing
4 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/guru/springframework/msscbeerservice/config/TaskConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package guru.springframework.msscbeerservice.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.task.SimpleAsyncTaskExecutor; | ||
import org.springframework.core.task.TaskExecutor; | ||
import org.springframework.scheduling.annotation.EnableAsync; | ||
import org.springframework.scheduling.annotation.EnableScheduling; | ||
|
||
/** | ||
* Created by jt on 2019-07-21. | ||
*/ | ||
@EnableAsync | ||
@EnableScheduling | ||
@Configuration | ||
public class TaskConfig { | ||
|
||
@Bean | ||
TaskExecutor taskExecutor(){ | ||
return new SimpleAsyncTaskExecutor(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/guru/springframework/msscbeerservice/services/BrewingService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package guru.springframework.msscbeerservice.services; | ||
|
||
import guru.springframework.msscbeerservice.config.JmsConfig; | ||
import guru.springframework.msscbeerservice.domain.Beer; | ||
import guru.springframework.msscbeerservice.events.BrewBeerEvent; | ||
import guru.springframework.msscbeerservice.repositories.BeerRepository; | ||
import guru.springframework.msscbeerservice.services.inventory.BeerInventoryService; | ||
import guru.springframework.msscbeerservice.web.mappers.BeerMapper; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.jms.core.JmsTemplate; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Created by jt on 2019-07-21. | ||
*/ | ||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class BrewingService { | ||
private final BeerRepository beerRepository; | ||
private final BeerInventoryService beerInventoryService; | ||
private final JmsTemplate jmsTemplate; | ||
private final BeerMapper beerMapper; | ||
|
||
@Scheduled(fixedRate = 5000) //every 5 seconds | ||
public void checkForLowInventory(){ | ||
List<Beer> beers = beerRepository.findAll(); | ||
|
||
beers.forEach(beer -> { | ||
Integer invQOH = beerInventoryService.getOnhandInventory(beer.getId()); | ||
|
||
log.debug("Min Onhand is: " + beer.getMinOnHand()); | ||
log.debug("Inventory is: " + invQOH); | ||
|
||
if(beer.getMinOnHand() >= invQOH){ | ||
jmsTemplate.convertAndSend(JmsConfig.BREWING_REQUEST_QUEUE, new BrewBeerEvent(beerMapper.beerToBeerDto(beer))); | ||
} | ||
}); | ||
|
||
} | ||
} |