|
|
# Example of code
|
|
|
We present a sample of code where two Cameo applications interact with a publisher/subscriber pattern. We define:
|
|
|
# Introduction
|
|
|
We present a complete simple example where two Cameo applications interact with a publisher/subscriber pattern.
|
|
|
|
|
|
# Code
|
|
|
We define:
|
|
|
* a C++ publisher application that publishes to a single subscriber.
|
|
|
* a Java subscriber application which starts the publisher application on the local Cameo server and subscribes to it.
|
|
|
|
... | ... | @@ -108,11 +111,13 @@ public class SubscriberApplication { |
|
|
}
|
|
|
```
|
|
|
|
|
|
Define the code is not enough to run Cameo applications. We need to configure a Cameo server with the following configuration file:
|
|
|
```xml
|
|
|
<?xml version="1.0" encoding="UTF-8">
|
|
|
|
|
|
<config port="7000" polling_time="100">
|
|
|
Define the code is not enough to run Cameo applications. We need to configure a Cameo server.
|
|
|
|
|
|
# Configuration
|
|
|
Here is a possible configuration file *config.xml*:
|
|
|
```xml
|
|
|
<config port="7000">
|
|
|
|
|
|
<applications>
|
|
|
|
... | ... | @@ -131,10 +136,29 @@ Define the code is not enough to run Cameo applications. We need to configure a |
|
|
|
|
|
</config>
|
|
|
```
|
|
|
A Cameo server configuration file contains the list of applications that can be started with their name, executable and other attributes. For example we can specify that the application will stream its standard and error outputs.
|
|
|
Now we have to execute the *subpubjava* application. That can be realized manually by using the Cameo console:
|
|
|
<pre>
|
|
|
$ cmo -e tcp://machine:7000 exec subpubjava
|
|
|
</pre>
|
|
|
A Cameo server configuration file contains:
|
|
|
* The base port from which it is accessed i.e. 7000.
|
|
|
* The list of applications that can be started with their name, executable and other attributes. Each application is a mapping between a name and a command including the executable and the fixed arguments. This configuration file supposes:
|
|
|
* The *pubcppapp* program is in the *PATH*.
|
|
|
* The jar *tests.jar* contains the code of the Java application.
|
|
|
|
|
|
# Execution
|
|
|
First we must start the Cameo server. This can be done directly in a shell:
|
|
|
|
|
|
```
|
|
|
java -jar java/server/target/cameo-server-1.1.0-full.jar config.xml --log-console
|
|
|
```
|
|
|
|
|
|
Now we have to execute the *subpubjava* application as it is the entry point. That can be done by using the Cameo console on the machine that runs the Cameo server:
|
|
|
|
|
|
```
|
|
|
$ cmo exec subpubjava
|
|
|
```
|
|
|
|
|
|
If *serverhost* is the hostname of the machine running the Cameo server, you can go n another machine and run *subpubjava* remotely:
|
|
|
|
|
|
```
|
|
|
$ cmo -e tcp://serverhost:7000 exec subpubjava
|
|
|
```
|
|
|
|
|
|
The server running with the endpoint *tcp://machine:7000* starts *subpubjava*. |
|
|
You have the first running example. |