-
Notifications
You must be signed in to change notification settings - Fork 4
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
eb09a60
commit 1efccd9
Showing
24 changed files
with
451 additions
and
216 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
8 changes: 0 additions & 8 deletions
8
src/main/java/io/qiot/manufacturing/edge/machinery/domain/event/BootstrapCompletedEvent.java
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
...n/java/io/qiot/manufacturing/edge/machinery/domain/event/chain/ValidationFailedEvent.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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package io.qiot.manufacturing.edge.machinery.domain.event.chain; | ||
|
||
import io.qiot.manufacturing.commons.domain.productionvalidation.AbstractProductionChainEvent; | ||
import io.qiot.manufacturing.commons.domain.productionvalidation.AbstractProductionChainEventDTO; | ||
import io.quarkus.runtime.annotations.RegisterForReflection; | ||
|
||
@RegisterForReflection | ||
public class ValidationFailedEvent extends AbstractProductionChainEvent { | ||
public class ValidationFailedEvent extends AbstractProductionChainEventDTO { | ||
} |
4 changes: 2 additions & 2 deletions
4
...a/io/qiot/manufacturing/edge/machinery/domain/event/chain/ValidationSuccessfullEvent.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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package io.qiot.manufacturing.edge.machinery.domain.event.chain; | ||
|
||
import io.qiot.manufacturing.commons.domain.productionvalidation.AbstractProductionChainEvent; | ||
import io.qiot.manufacturing.commons.domain.productionvalidation.AbstractProductionChainEventDTO; | ||
import io.quarkus.runtime.annotations.RegisterForReflection; | ||
|
||
@RegisterForReflection | ||
public class ValidationSuccessfullEvent extends AbstractProductionChainEvent { | ||
public class ValidationSuccessfullEvent extends AbstractProductionChainEventDTO { | ||
} |
4 changes: 2 additions & 2 deletions
4
...domain/event/ProductLineChangedEvent.java → ...oductline/ProductLineChangedEventDTO.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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
package io.qiot.manufacturing.edge.machinery.domain.event; | ||
package io.qiot.manufacturing.edge.machinery.domain.event.productline; | ||
|
||
import io.qiot.manufacturing.commons.domain.productline.ProductLineDTO; | ||
import io.quarkus.runtime.annotations.RegisterForReflection; | ||
|
||
@RegisterForReflection | ||
public class ProductLineChangedEvent { | ||
public class ProductLineChangedEventDTO { | ||
public ProductLineDTO productLine; | ||
} |
11 changes: 11 additions & 0 deletions
11
...nufacturing/edge/machinery/domain/event/productline/RequestLatestProductLineEventDTO.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,11 @@ | ||
package io.qiot.manufacturing.edge.machinery.domain.event.productline; | ||
|
||
import java.util.UUID; | ||
|
||
/** | ||
* @author andreabattaglia | ||
* | ||
*/ | ||
public class RequestLatestProductLineEventDTO { | ||
public UUID productLineId; | ||
} |
1 change: 1 addition & 0 deletions
1
...main/java/io/qiot/manufacturing/edge/machinery/domain/event/productline/package-info.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 @@ | ||
package io.qiot.manufacturing.edge.machinery.domain.event.productline; |
1 change: 0 additions & 1 deletion
1
src/main/java/io/qiot/manufacturing/edge/machinery/rest/package-info.java
This file was deleted.
Oops, something went wrong.
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
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
120 changes: 120 additions & 0 deletions
120
...ot/manufacturing/edge/machinery/service/productline/LatestProductLineMessageConsumer.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,120 @@ | ||
package io.qiot.manufacturing.edge.machinery.service.productline; | ||
|
||
import java.util.Objects; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
import javax.annotation.PreDestroy; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.event.Event; | ||
import javax.enterprise.event.Observes; | ||
import javax.inject.Inject; | ||
import javax.jms.ConnectionFactory; | ||
import javax.jms.JMSConsumer; | ||
import javax.jms.JMSContext; | ||
import javax.jms.JMSException; | ||
import javax.jms.Message; | ||
import javax.jms.Queue; | ||
import javax.jms.Session; | ||
|
||
import org.slf4j.Logger; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import io.qiot.manufacturing.commons.domain.event.BootstrapCompletedEventDTO; | ||
import io.qiot.manufacturing.commons.domain.productionvalidation.ValidationResponseDTO; | ||
import io.qiot.manufacturing.commons.domain.productline.ProductLineDTO; | ||
import io.qiot.manufacturing.commons.util.producer.ProductLineReplyToQueueNameProducer; | ||
import io.qiot.manufacturing.commons.util.producer.ValidationReplyToQueueNameProducer; | ||
import io.qiot.manufacturing.edge.machinery.domain.event.chain.ValidationFailedEvent; | ||
import io.qiot.manufacturing.edge.machinery.domain.event.chain.ValidationSuccessfullEvent; | ||
import io.qiot.manufacturing.edge.machinery.domain.event.productline.ProductLineChangedEventDTO; | ||
import io.qiot.manufacturing.edge.machinery.service.machinery.MachineryService; | ||
|
||
@ApplicationScoped | ||
public class LatestProductLineMessageConsumer implements Runnable { | ||
|
||
@Inject | ||
Logger LOGGER; | ||
|
||
@Inject | ||
ObjectMapper MAPPER; | ||
|
||
@Inject | ||
ConnectionFactory connectionFactory; | ||
|
||
@Inject | ||
MachineryService machineryService; | ||
|
||
@Inject | ||
ProductLineReplyToQueueNameProducer productLineReplyToQueueNameProducer; | ||
|
||
@Inject | ||
Event<ProductLineChangedEventDTO> prodictLineChangedEvent; | ||
|
||
private JMSContext context; | ||
|
||
private JMSConsumer consumer; | ||
|
||
private String replyToQueueName; | ||
|
||
private Queue replyToQueue; | ||
|
||
private final ExecutorService scheduler = Executors | ||
.newSingleThreadExecutor(); | ||
|
||
void init(@Observes BootstrapCompletedEventDTO event) { | ||
LOGGER.info("Bootstrapping new product line durable subscriber..."); | ||
initSubscriber(); | ||
|
||
scheduler.submit(this); | ||
LOGGER.debug("Bootstrap completed"); | ||
} | ||
|
||
private void initSubscriber() { | ||
if (Objects.nonNull(context)) | ||
context.close(); | ||
context = connectionFactory.createContext(Session.AUTO_ACKNOWLEDGE); | ||
|
||
replyToQueueName = productLineReplyToQueueNameProducer | ||
.getReplyToQueueName(machineryService.getMachineryId()); | ||
|
||
replyToQueue = context.createQueue(replyToQueueName); | ||
|
||
consumer = context.createConsumer(replyToQueue); | ||
} | ||
|
||
@PreDestroy | ||
void destroy() { | ||
scheduler.shutdown(); | ||
context.close(); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
// while (true) { | ||
try { | ||
Message message = consumer.receive(); | ||
String messagePayload = message.getBody(String.class); | ||
ProductLineDTO productLine = MAPPER.readValue(messagePayload, | ||
ProductLineDTO.class); | ||
LOGGER.info("Received latest PRODUCTLINE available from the Factory Controller: \n {}", productLine); | ||
ProductLineChangedEventDTO eventDTO = new ProductLineChangedEventDTO(); | ||
eventDTO.productLine = productLine; | ||
prodictLineChangedEvent.fire(eventDTO); | ||
} catch (JMSException e) { | ||
LOGGER.error( | ||
"The messaging client returned an error: {} and will be restarted.", | ||
e); | ||
initSubscriber(); | ||
} catch (JsonProcessingException e) { | ||
LOGGER.error( | ||
"The message payload is malformed and the validation request will not be sent: {}", | ||
e); | ||
} catch (Exception e) { | ||
LOGGER.error("GENERIC ERROR", e); | ||
} | ||
// } | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
...facturing/edge/machinery/service/productline/LatestProductLineRequestMessageProducer.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,80 @@ | ||
/** | ||
* | ||
*/ | ||
package io.qiot.manufacturing.edge.machinery.service.productline; | ||
|
||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
import javax.jms.ConnectionFactory; | ||
import javax.jms.JMSContext; | ||
import javax.jms.JMSProducer; | ||
import javax.jms.Queue; | ||
import javax.jms.Session; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
import org.slf4j.Logger; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
/** | ||
* @author andreabattaglia | ||
* | ||
*/ | ||
@ApplicationScoped | ||
public class LatestProductLineRequestMessageProducer { | ||
|
||
@Inject | ||
Logger LOGGER; | ||
|
||
@Inject | ||
ConnectionFactory connectionFactory; | ||
|
||
@Inject | ||
ObjectMapper MAPPER; | ||
|
||
@ConfigProperty(name = "qiot.productline.request.queue-prefix") | ||
String latestProductLineRequestQueueName; | ||
|
||
private JMSContext context; | ||
|
||
private JMSProducer producer; | ||
|
||
private Queue queue; | ||
|
||
@PostConstruct | ||
void init() { | ||
LOGGER.info( | ||
"Bootstrapping latest product line request event producer..."); | ||
doInit(); | ||
|
||
LOGGER.info("Bootstrap completed"); | ||
|
||
} | ||
|
||
private void doInit() { | ||
if (Objects.nonNull(context)) | ||
context.close(); | ||
context = connectionFactory.createContext(Session.AUTO_ACKNOWLEDGE); | ||
|
||
producer = context.createProducer(); | ||
|
||
queue = context.createQueue(latestProductLineRequestQueueName); | ||
} | ||
|
||
void requestLatestProductLine(String machineryId) { | ||
LOGGER.info( | ||
"Sending out a request for the latest product line available"); | ||
try { | ||
String messagePayload = machineryId; | ||
|
||
producer.send(queue, messagePayload); | ||
} catch (Exception e) { | ||
LOGGER.error("GENERIC ERROR", e); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.