Skip to content

Commit e2ed893

Browse files
HariRangarajan-SolaceHariRangarajan-SolaceTamimiGitHub
authored
Update Solace Masterclass for demonstrating FE consumer (#371)
* Updated masterclass Retail Domain for supporting config push and C-EMA * Implement review comments * Implement review comments * Updated masterclass codelab for Banking domain implementation using C-EMA on public trial accounts. * Updated masterclass codelab for Banking domain implementation using C-EMA on public trial accounts. * Updated masterclass codelab for demonstrating FE consumer in the Retail domain sample. --------- Co-authored-by: HariRangarajan-Solace <[email protected]> Co-authored-by: Tamimi Ahmad <[email protected]>
1 parent f9a03a8 commit e2ed893

File tree

1 file changed

+1
-75
lines changed

1 file changed

+1
-75
lines changed

markdown/solace-masterclass/solace-masterclass.md

Lines changed: 1 addition & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -448,81 +448,7 @@ This **Order-Confirmed** needs to be subscribed by the **Order Service**. Follow
448448
![order-service-all-order-updates-queue.png](img/retail-domain-usecase/order-service-all-order-updates-queue.png)
449449
> aside positive As we incorporate new features, we will update this queue's subscriptions with additional event topics.
450450
451-
* Once the consumer is created, navigate to the **Runtime** tab and push the updates to the event broker
452-
* Navigate to the **Order-Service** by simply selecting the folder at the location:
453-
**solace-masterclass/retail-domain/order-service**
454-
> aside negative If you need any assistance in this, please feel free to reach out to the Solace instructors nearby.
455-
456-
* Open the file: **com.solace.acme.store.orderservice.service.SolaceEventPublisher.java** and make the below updates to
457-
the file :
458-
* In the method **connectToBroker**, add in the code snippet before the return statement :
459-
```Java
460-
final PersistentMessageReceiver orderUpdatesEventReceiver = messagingService.createPersistentMessageReceiverBuilder().build(Queue.durableExclusiveQueue(configProperties.getOrderUpdatesQueueName()));
461-
orderUpdatesEventReceiver.setReceiveFailureListener(failedReceiveEvent -> System.out.println("### FAILED RECEIVE EVENT " + failedReceiveEvent));
462-
orderUpdatesEventReceiver.start();
463-
orderUpdatesEventReceiver.receiveAsync(buildOrdersUpdatesEventHandler(orderUpdatesEventReceiver));
464-
```
465-
466-
> aside positive This code snippet creates and configures a receiver for subscribing to the persistent messages
467-
> attracted in the **all-order-updates** queue.
468-
> The receiver links an asynchronous callback handler which processes the event
469-
470-
* Introduce the below two methods in the same class :
471-
```Java
472-
private MessageReceiver.MessageHandler buildOrdersUpdatesEventHandler(final PersistentMessageReceiver orderUpdatesEventReceiver) {
473-
return (inboundMessage -> {
474-
try {
475-
final String inboundTopic = inboundMessage.getDestinationName();
476-
log.info("Processing message on incoming topic :{} with payload:{}", inboundTopic, inboundMessage.getPayloadAsString());
477-
boolean eventProcessed = processOrderUpdate(inboundTopic, inboundMessage.getPayloadAsString());
478-
if (eventProcessed) {
479-
orderUpdatesEventReceiver.ack(inboundMessage);
480-
}
481-
} catch (RuntimeException runtimeException) {
482-
log.error("Runtime exception encountered while processing incoming event payload :{} on topic:{}. Error is :", inboundMessage.getPayloadAsString(), inboundMessage.getDestinationName(), runtimeException);
483-
}
484-
});
485-
}
486-
```
487-
488-
> aside positive This code snippet is the handler for the events which are being consumed by the above-configured
489-
> receiver.
490-
491-
```Java
492-
private boolean processOrderUpdate(final String eventTopic, final String eventJson) {
493-
try {
494-
if (eventTopic.contains("order")) {
495-
final Order order = objectMapper.readValue(eventJson, Order.class);
496-
final String incomingOrderId = order.getId();
497-
Order orderObjectFromCache = OrderCache.getInstance().getOrderMap().get(incomingOrderId);
498-
orderObjectFromCache.setState(Order.OrderState.VALIDATED);
499-
OrderCache.getInstance().getOrderMap().put(incomingOrderId, orderObjectFromCache);
500-
} else if (eventTopic.contains("payment")) {
501-
final Payment payment = objectMapper.readValue(eventJson, Payment.class);
502-
final String incomingOrderId = payment.getOrderId();
503-
Order orderObjectFromCache = OrderCache.getInstance().getOrderMap().get(incomingOrderId);
504-
orderObjectFromCache.setState(Order.OrderState.PAYMENT_PROCESSED);
505-
OrderCache.getInstance().getOrderMap().put(incomingOrderId, orderObjectFromCache);
506-
} else if (eventTopic.contains("shipment")) {
507-
final Shipping shipment = objectMapper.readValue(eventJson, Shipping.class);
508-
final String incomingOrderId = shipment.getOrderId();
509-
Order orderObjectFromCache = OrderCache.getInstance().getOrderMap().get(incomingOrderId);
510-
orderObjectFromCache.setState(Order.OrderState.SHIPPED);
511-
OrderCache.getInstance().getOrderMap().put(incomingOrderId, orderObjectFromCache);
512-
}
513-
return true;
514-
} catch (JsonProcessingException jsonProcessingException) {
515-
log.error("Error encountered while processing event:{}, exception:", eventJson, jsonProcessingException);
516-
return false;
517-
}
518-
}
519-
```
520-
521-
> aside positive This code snippet identifies the topic which the event from the queue was published on and depending on
522-
> the **object type (Order, Payment or Shipment)** implements an appropriate business logic
523-
524-
* In the terminal for the **Order Service**, stop the service if running and execute the command:
525-
**mvn clean spring-boot:run**
451+
* Once the consumer is created, navigate to the **Runtime** tab and push the updates to the event broker.
526452
* Publish a few more orders from the **Order-Service** and see it being processed in the console logs.
527453
* Go back to the **Order-Service,** and you will observe that the status of the newly created order is showing as
528454
VALIDATED as the orders are processed by the **Inventory-FraudCheck-Service**

0 commit comments

Comments
 (0)