Increasing the availability of the system

After removing the need to ask for additional data once the event has been retrieved, it's natural to assume that the availability of the system has increased as, no matter whether the other systems are available or not, the event will be processed. An indirect consequence of introducing this benefit is the eventual consistency that is now part of the system.

Eventual consistency is a model that is used to achieve high availability in the systems where, if no new updates are made to the given data, once a piece of information has been retrieved, all instances of accessing that data will eventually return the last updated value.

The following diagram shows how a system changes its data without propagating these changes to the downstream dependencies:

Data updates are not propagated

To change the preceding example so that it follows this approach, we only need to include additional information as part of the payload. Previously, we just sent a String with the clientId; now we are going to cover the complete TransactionMoneyDetails in the following way:

@RestController
public class TransferController
{
private final MessageChannel moneyTransferredChannel;
public TransferController(EventNotificationChannel channel)
{
this.moneyTransferredChannel = channel.moneyTransferredChannel();
}
@PostMapping("/transfer")
public void doTransfer(@RequestBody TransferMoneyDetails
transferMoneyDetails)
{
// Do something
Message<TransferMoneyDetails> moneyTransferredEvent =
MessageBuilder.withPayload(transferMoneyDetails).build();
this.moneyTransferredChannel.send(moneyTransferredEvent);
}
}

The Message class can support any kind of object that should be specified within <>since this class is implemented using the generic types feature from Java.

The downstream-dependent systems should also be modified to make them able to retrieve an object instead of a simple string. Since the Handler to process incoming messages also supports generics, we can implement this feature with a small change in the code, as follows:

@Bean
IntegrationFlow integrationFlow(EventNotificationChannel eventNotificationChannel)
{
return IntegrationFlows
.from(eventNotificationChannel
.subscriptionOnMoneyTransferredChannel())
.handle(TransferMoneyDetails.class, new GenericHandler
<TransferMoneyDetails>()

{
@Override
public Object handle(TransferMoneyDetails payload, Map<String,
Object> map)
{
// Do something with the payload
return null;
}
}).get();
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.34.197