The ways to communicate between Operon-instances are:
- By using Operon-component, which sends the information via TCP-socket
- By using Http-component, which sends the information via HTTP-protocol
- By using File-component, which allows sending information through sharing file
Let's first create an Operon that creates a timer which sends a message "Hello!" every 10 seconds to another Operon. The other Operon will process the message and send the response.
Now let's create a service which listens port 8081 and selects the value from the "body"-field, which will be "Hello!". This will be replied back to the Operon that called this service.
That wasn't much code. We can see that is easy to call other Operons when needed by using the Operon-component.
When to call other Operons?
- If we consider the modular architecture, then it is possible to divide the application into smaller Operon-services. This makes sense when we have tasks that can be divided between different virtual machines. This is the case when the problem can be divided into sub-problems and tasks can be computed in parallel in multiple instances. Within one virtual machine it is better to modularize the application by using the Import-statements.
- Other times we want to asynchronize tasks. Within one Operon instance the tasks can be parallelized, but not asynchronized in a way that one task was sent to background-thread. If we need to process tasks in the background, then we will just start new Operon-instance which will receive the data and handle it in the background.
Let's dig deeper and see what operon-component can do for us regarding to the second scenario where we want to process some task in the background. This can be achieved trivially by using the "outOnly" option, which means that the operon-component won't wait for the reply. The example below shows a little bit more complex sequence, showing how to use "replyHost" and "replyPort" -feature in the Operon-component:
NOTE: all the Operons above should be placed into own file, or started separately.