Subscribing to all messages

Being the center of our ecosystem, our microservice will be subscribing to all messages. So let's now take a look at what our Subscribe method looks like, in all its glory. You will notice that we first declare our exchange and then our queue, just in case they do not exist for some reason. After that, we bind each queue to an exchange. Finally, we subscribe to all our messages, and provide our handlers for the processing of each message, as shown in the highlighted code:

public void Subscribe()
{
Bus = RabbitHutch.CreateBus("host=localhost");
IExchange exchange = Bus.Advanced.ExchangeDeclare("EvolvedAI", ExchangeType.Topic);
IQueue queue = Bus.Advanced.QueueDeclare("HealthStatus");
Bus.Advanced.Bind(exchange, queue, "");
queue = Bus.Advanced.QueueDeclare("Memory");
Bus.Advanced.Bind(exchange, queue, "");
queue = Bus.Advanced.QueueDeclare("Deployments");
Bus.Advanced.Bind(exchange, queue, "");
queue = Bus.Advanced.QueueDeclare("FileSystem");
Bus.Advanced.Bind(exchange, queue, "");
Bus.Subscribe<HealthStatusMessage>("", msg => {
ProcessHealthMessage(msg); },
config => config?.WithTopic("HealthStatus"));
Bus.Subscribe<MemoryUpdateMessage>("", msg => {
ProcessMemoryMessage(msg); },
config => config?.WithTopic("MemoryStatus"));
Bus.Subscribe<DeploymentStartMessage>("", msg => { ProcessDeploymentStartMessage(msg); },
config => config?.WithTopic("Deployments.Start"));
Bus.Subscribe<DeploymentStopMessage>("", msg => { ProcessDeploymentStopMessage(msg); },
config => config?.WithTopic("Deployments.Stop"));
Bus.Subscribe<FileSystemChangeMessage>("", msg => { ProcessFileSystemMessage(msg); },
config => config?.WithTopic("FileSystemChanges"));
Bus.Subscribe<CreditDefaultSwapResponseMessage>("", msg => { ProcessCDSMessage(msg); },
config => config?.WithTopic("CDSResponse"));
Bus.Subscribe<BondsResponseMessage>("", msg => {
ProcessBondMessage(msg); },
config => config?.WithTopic("BondResponse"));
Bus?.Subscribe<MLMessage>(Environment.MachineName, msg => ProcessMachineLearningMessage(msg),
config => config?.WithTopic("MachineLearning"));
Bus?.Subscribe<BitcoinSpendReceipt>(Environment.MachineName, msg => ProcessBitcoinSpendReceiptMessage(msg),
config => config?.WithTopic("Bitcoin"));
}

What do our handlers look like? Since this is our manager, let's discuss each one.

Whether or not you decide to act on any message is up to you, but whatever decision you make, someone is always going to ask the question, Who's watching the watcher? This simply means that if there's one center piece to your puzzle, we must make sure that it is running and performing as desired. Otherwise, we have a single bottleneck and that's no good. You can accomplish this by making sure that the microservice-manager process is being watched by whatever corporate tools you have available for monitoring applications or processes, Orion is commonly found in corporate America. This way, if it goes down, an alert is triggered and you can take the appropriate action.
..................Content has been hidden....................

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