Ultra Messaging receivers have a feature where users can request a special message callback for when a specific number of topic resolution queries have been sent without seeing an advertisement in response. The callback is executed in the receivers message handler, where the no source information can be logged or other actions can be taken as a result. The notification is disabled by default, and is configurable using the receiver scoped option resolution_no_source_notification_threshold
This sample application will configure the callback to execute after 25 unasnwered queries, and will then set a global flag for the main thread to cleanup and exit after the notification is executed.
There is one program source file:
First there is a macro to define the number of queries threshold before the notification is executed
00046 #define NO_SOURCE_QUERIES "25"
Next there is the global flag variable which the main application thread will wait on.
00048 int no_source = 0;
The receiver option resolution_no_source_notification_threshold configures the notification to execute after the specified value for queries are published without an advertisement response. The attribute can be configured programatically like so:
00093 err = lbm_rcv_topic_attr_str_setopt(rattr, "resolution_no_source_notification_threshold", NO_SOURCE_QUERIES); 00094 EX_LBM_CHK(err);
This sample configures the query threshold to 25, which with the default topic resolution settings AND no active source for topic "test.topic", the notification callback should execute within a couple seconds of the receiver being created
Finally, the application should handle the notification callback inside the receivers message handler. For the purpose of this sample, we will simply print a message to stdout.
00055 case LBM_MSG_NO_SOURCE_NOTIFICATION: 00056 printf("[%s], no sources found for topic after %s queries\n", msg->topic_name, NO_SOURCE_QUERIES); 00057 no_source++; 00058 break;
Include files for this application. Notice the Windows specific include files - these are not necessary for Linux only applications
00022 #include <stdio.h> 00023 00024 #if defined(_MSC_VER) 00025 /* Windows-only includes */ 00026 #include <winsock2.h> 00027 #define SLEEP(s) Sleep((s)*1000) 00028 #else 00029 /* Unix-only includes */ 00030 #include <stdlib.h> 00031 #include <unistd.h> 00032 #define SLEEP(s) sleep(s) 00033 #endif 00034 00035 #include <lbm/lbm.h>
Windows applications must initialize the Winsock library to utilize sockets.
00075 #if defined(_WIN32) 00076 /* windows-specific code */ 00077 WSADATA wsadata; 00078 int wsStat = WSAStartup(MAKEWORD(2,2), &wsadata); 00079 if (wsStat != 0) 00080 { 00081 printf("line %d: wsStat=%d\n",__LINE__,wsStat); 00082 exit(1); 00083 } 00084 #endif
If this fails, the application should exit since sockets will not be operational.