Quick Start Guide
|
The C programs below contain the minimum code and supporting material. Their purpose is to verify that the user's build and run-time environments are set up correctly. They also give a basic introduction to the Ultra Messaging API.
We also have equivalent Java and C# programs available in source form. See MinSrc.java and MinRcv.java or MinSrc.cs and MinRcv.cs. We also have an example of how application callbacks are coded in C++ programs. See minrcv.cpp.
(Most browsers let you right-click on a link and use the "save link target" function, or some variation.)
Note that these programs do not allow the user to override any of the default configuration values. As a result, operation is fixed according to the normal LBM defaults; for example TCP is the transport protocol, topic resolution is performed using multicast, etc. See the Ultra Messaging Configuration Guide.
The Source Code Examples tab on the left panel provides a much richer set of source files that use a wide variety of features. However, those programs double as performance testing tools, so they tend to be more complex than just demonstrating the features. We recommend to first build and run these minimal examples.
This source code example is provided by Informatica for educational and evaluation purposes only.
Error handling in these programs is primitive. A production program would want to have better error handling, but for the purposes of a minimal example, it would just be a distraction. Also, a production program would want to support a configuration file to override default values on options.
When building on Windows, the following notes are applicable.
Make sure the preprocessor variable "WIN32" is defined.
Add the '...\include\lbm
' (under the package install directory) as an additional include directory.
Add lbm.lib and wsock32.lib as Object/library modules.
Add the '...\lib
' as an additional library path.
lbm.dll
can be found when a program is run.
When building on Linux, the following notes are applicable.
Sample build command:
gcc -I$HOME/UMS_6.17/Linux-glibc-2.17-x86_64/include -I$HOME/UMS_6.17/Linux-glibc-2.17-x86_64/include/lbm \ -L$HOME/UMS_6.17/Linux-glibc-2.17-x86_64/lib -llbm -pthread -lm -lrt -o minsrc minsrc.c
(For programs that use more features, additional UM libraries might be required. See the contents of your installed UM "lib/" directory.)
The appropriate library search path should be updated to include the installed UM "lib/" directory. For example:
export LD_LIBRARY_PATH="$HOME/lbm/UMS_6.17/Linux-glibc-2.17-x86_64/lib:$LD_LIBRARY_PATH"
Alternatively, the shared library can be copied from the LBM lib/
directory to a directory which is already in your library search path.
Using other flavors of Unix can introduce differences. For example, not all Unixes use "LD_LIBRARY_PATH". For a great resource for learning how Unix flavors differ, see: http://bhami.com/rosetta.html.
Starting in UM version 6.14, the necessary Java JAR files are included in the main package under "java".
See Using UM Java on Unix and Using UM Java on Windows.
For example: "UMP_6.17/java"
For .NET Core on Linux, the necessary .NET files are included in the main package under "bin/dotnet".
For example: "UMP_6.17/Linux-glibc-2.17-x86_64/bin/dotnet"
For .NET Framework on Windows, the necessary .NET files are included in the main package under "bin/dotnet".
For example: "UMP_6.17\Win2k-x86_64\bin\dotnet"
This is a source code listing of a minimal source (sender) program. Examples also include equivalent Java and C# programs available in source form. See MinSrc.java and MinSrc.cs. (There are build .NET instructions in the initial comment blocks of MinSrc.cs and MinRcv.cs which are oriented towards the Windows development environment. For information related to .NET on Linux, see UM .NET on Linux.)
Notes:
Create a context object. A context is an environment in which LBM functions. Note that the first parameter is a pointer to a pointer variable; lbm_context_create() writes the pointer to the context object into "ctx". Also, by passing NULL to the context attribute parameter, the default option values are used. For most applications only a single context is required regardless of how many sources and receivers are created.
Allocate a topic object. A topic object is little more than a string (the topic name). During operation, LBM keeps some state information in the topic object as well. The topic is bound to the containing context, and will also be bound to a source object. Note that the first parameter is a pointer to a pointer variable; lbm_src_topic_alloc() writes the pointer to the topic object into "topic". Also, by passing NULL to the source topic attribute, the default option values are used. The string "Greeting" is the topic string.
Create the source object. A source object is used to send messages. It must be bound to a topic. Note that the first parameter is a pointer to a pointer variable; lbm_src_create() writes the pointer to the source object to into "src". Use of the third and fourth parameters is optional but recommended in a production program - some source events can be important to the application. The last parameter is an optional event queue (not used in this example).
Need to wait for receivers to find us before first send. There are other ways to accomplish this, but sleep is easy. See Avoiding or Minimizing Delay Before Sending for details.
Send a message to the "Greeting" topic. The flags make sure the call to lbm_src_send() doesn't return until the message is sent. Note that while this ensures low latency, flushing every message carries a heavy efficiency cost. See Intelligent Batching for more information.
For some transport types (mostly UDP-based), a short delay before deleting the source is advisable. Even though the message is sent, there may have been packet loss, and some transports need a bit of time to request re-transmission. Also, if the above lbm_src_send() call didn't include the flush, some time might also be needed to empty the batching buffer.
This is a source code listing of a minimal receiver program. Examples also include equivalent Java, C#, and C++ programs available in source form. See MinRcv.java, MinRcv.cs, and minrcv.cpp. (There are build .NET instructions in the initial comment blocks of MinSrc.cs and MinRcv.cs which are oriented towards the Windows development environment. For information related to .NET on Linux, see UM .NET on Linux.)
Notes:
LBM passes received messages to the application by means of a callback. I.e. the LBM context thread reads the network socket, performs its higher-level protocol functions, and then calls an application-level function that was set up during initialization. This callback function has some severe limitations placed upon it. It must execute very quickly; any potentially blocking calls it might make will interfere with the proper execution of the LBM context thread. One common desire is for the receive function to send an LBM message (via lbm_src_send()), however this has the potential to produce a deadlock condition. If it is desired for the receive callback function to call LBM or other potentially blocking functions, it is strongly advised to make use of an event queue, which causes the callback to be executed from an application thread. See the example tool lbmrcvq.c for an example of using a receiver event queue.
Note - printf can block, which is normally a bad idea for a callback (unless an event queue is being used). However, for this minimal application, only one message is expected.
Create a context object. A context is an environment in which LBM functions. Note that the first parameter is a pointer to a pointer variable; lbm_context_create() writes the pointer to the context object into "ctx". Also, by passing NULL to the context attribute parameter, the default option values are used. For most applications only a single context is required regardless of how many sources and receivers are created.
Lookup a topic object. A topic object is little more than a string (the topic name). During operation, LBM keeps some state information in the topic object as well. The topic is bound to the containing context, and will also be bound to a receiver object. Note that the first parameter is a pointer to a pointer variable; lbm_rcv_topic_lookup() writes the pointer to the topic object into "topic". Also, by passing NULL to the source topic attribute, the default option values are used. The string "Greeting" is the topic string.