PubSub+ Messaging API For C  7.29.0.6
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Intro/HelloWorldQueueSub.c
/*
* Copyright 2012-2024 Solace Corporation. All rights reserved.
*
* http://www.solace.com
*
* This source is distributed under the terms and conditions
* of any contract or contracts between Solace and you or
* your company. If there are no contracts in place use of
* this source is not authorized. No support is provided and
* no distribution, sharing with others or re-use of this
* source is authorized unless specifically stated in the
* contracts referred to above.
*
* HelloWorldQueueSub
*
* This sample shows the basics of creating session, connecting a session,
* and receiving a guaranteed message from a queue. This is meant to be a very
* basic example for demonstration purposes.
*/
#include "os.h"
/* Message Count */
static int msgCount = 0;
/*****************************************************************************
* sessionMessageReceiveCallback
*
* The message receive callback is mandatory for session creation.
*****************************************************************************/
sessionMessageReceiveCallback ( solClient_opaqueSession_pt opaqueSession_p, solClient_opaqueMsg_pt msg_p, void *user_p )
{
}
/*****************************************************************************
* sessionEventCallback
*
* The event callback function is mandatory for session creation.
*****************************************************************************/
void
sessionEventCallback ( solClient_opaqueSession_pt opaqueSession_p,
solClient_session_eventCallbackInfo_pt eventInfo_p, void *user_p )
{
}
/*****************************************************************************
* flowEventCallback
*
* The event callback function is mandatory for flow creation.
*****************************************************************************/
static void
flowEventCallback ( solClient_opaqueFlow_pt opaqueFlow_p, solClient_flow_eventCallbackInfo_pt eventInfo_p, void *user_p )
{
}
/*****************************************************************************
* flowMessageReceiveCallback
*
* The message receive callback is mandatory for session creation.
*****************************************************************************/
flowMessageReceiveCallback ( solClient_opaqueFlow_pt opaqueFlow_p, solClient_opaqueMsg_pt msg_p, void *user_p )
{
/* Process the message. */
printf ( "Received message:\n" );
solClient_msg_dump ( msg_p, NULL, 0 );
printf ( "\n" );
msgCount++;
/* Acknowledge the message after processing it. */
if ( solClient_msg_getMsgId ( msg_p, &msgId ) == SOLCLIENT_OK ) {
printf ( "Acknowledging message Id: %lld.\n", msgId );
solClient_flow_sendAck ( opaqueFlow_p, msgId );
}
}
/*****************************************************************************
* main
*
* The entry point to the application.
*****************************************************************************/
int
main ( int argc, char *argv[] )
{
/* Context */
/* Session */
/* Flow */
/* Session Properties */
const char *sessionProps[20];
int propIndex;
/* Flow Properties */
const char *flowProps[20];
/* Provision Properties */
const char *provProps[20];
int provIndex;
/* Queue Network Name to be used with "solClient_session_endpointProvision()" */
char qNN[80];
if ( argc < 5 ) {
printf ( "Usage: HelloWorldQueueSub <msg_backbone_ip:port> <vpn> <client-username> <queue>\n" );
return -1;
}
/*************************************************************************
* Initialize the API and setup logging level
*************************************************************************/
/* solClient needs to be initialized before any other API calls. */
/*************************************************************************
* CREATE A CONTEXT
*************************************************************************/
/*
* Create a Context, and specify that the Context thread be created
* automatically instead of having the application create its own
* Context thread.
*/
&context_p, &contextFuncInfo, sizeof ( contextFuncInfo ) );
/*************************************************************************
* Create and connect a Session
*************************************************************************/
/* Configure the Session function information. */
sessionFuncInfo.rxMsgInfo.callback_p = sessionMessageReceiveCallback;
sessionFuncInfo.eventInfo.callback_p = sessionEventCallback;
/* Configure the Session properties. */
propIndex = 0;
sessionProps[propIndex++] = SOLCLIENT_SESSION_PROP_HOST;
sessionProps[propIndex++] = argv[1];
sessionProps[propIndex++] = SOLCLIENT_SESSION_PROP_VPN_NAME;
sessionProps[propIndex++] = argv[2];
sessionProps[propIndex++] = SOLCLIENT_SESSION_PROP_USERNAME;
sessionProps[propIndex++] = argv[3];
sessionProps[propIndex++] = NULL;
/* Create the Session. */
solClient_session_create ( ( char ** ) sessionProps,
context_p,
&session_p, &sessionFuncInfo, sizeof ( sessionFuncInfo ) );
/* Connect the Session. */
printf ( "Connected.\n" );
/*************************************************************************
* Provision a Queue
*************************************************************************/
/* Configure the Provision properties */
provIndex = 0;
provProps[provIndex++] = SOLCLIENT_ENDPOINT_PROP_ID;
provProps[provIndex++] = SOLCLIENT_ENDPOINT_PROP_QUEUE;
provProps[provIndex++] = SOLCLIENT_ENDPOINT_PROP_NAME;
provProps[provIndex++] = argv[4];
provProps[provIndex++] = SOLCLIENT_ENDPOINT_PROP_PERMISSION;
provProps[provIndex++] = SOLCLIENT_ENDPOINT_PERM_DELETE;
provProps[provIndex++] = SOLCLIENT_ENDPOINT_PROP_QUOTA_MB;
provProps[provIndex++] = "100";
provProps[provIndex++] = NULL;
/* Check if the endpoint provisioning is support */
printf ( "Endpoint management not supported on this appliance.\n" );
return -1;
}
/* Try to provision the Queue. Ignore if already exists */
solClient_session_endpointProvision ( ( char ** ) provProps,
session_p,
NULL, qNN, sizeof ( qNN ) );
/*************************************************************************
* Create a Flow
*************************************************************************/
/* Congigure the Flow function information */
flowFuncInfo.rxMsgInfo.callback_p = flowMessageReceiveCallback;
flowFuncInfo.eventInfo.callback_p = flowEventCallback;
/* Configure the Flow properties */
propIndex = 0;
flowProps[propIndex++] = SOLCLIENT_FLOW_PROP_BIND_BLOCKING;
flowProps[propIndex++] = SOLCLIENT_PROP_DISABLE_VAL;
flowProps[propIndex++] = SOLCLIENT_FLOW_PROP_BIND_ENTITY_ID;
flowProps[propIndex++] = SOLCLIENT_FLOW_PROP_BIND_ENTITY_QUEUE;
flowProps[propIndex++] = SOLCLIENT_FLOW_PROP_ACKMODE;
flowProps[propIndex++] = SOLCLIENT_FLOW_PROP_ACKMODE_CLIENT;
flowProps[propIndex++] = SOLCLIENT_FLOW_PROP_BIND_NAME;
flowProps[propIndex++] = argv[4];
flowProps[propIndex++] = NULL;
solClient_session_createFlow ( ( char ** ) flowProps,
session_p,
&flow_p, &flowFuncInfo, sizeof ( flowFuncInfo ) );
/*************************************************************************
* Wait for messages
*************************************************************************/
printf ( "Waiting for messages......\n" );
fflush ( stdout );
while ( msgCount < 1 ) {
SLEEP ( 1 );
}
printf ( "Exiting.\n" );
/*************************************************************************
* Cleanup
*************************************************************************/
/* Destroy the Flow */
/* Disconnect the Session */
/* Cleanup solClient. */
return 0;
}