An overview of the behaviour of the C/C++ API interface adapters, including their functions and parameters.
As we mentioned earlier, a typical out-of-process adapter performs the following tasks:
Acquiring an address (URI) that will uniquely identify a specific stream and telling the communication layer (provided by ) how to find that stream.
Opening a connection to a tream.
Reading (or writing) the desired data. Typically the read (or write) operation is in a loop.
Closing the connection (if the adapter is not going to run indefinitely).
If the adapter is reading from the stream, then the adapter may need to wait until the next message arrives. There are three possible ways that the adapter can wait for the next message:
The adapter can "poll" until a message arrives.
The adapter can make a blocking call that will wait until a message arrives.
The adapter can register a callback function that will be called when a message arrives.
To poll, the adapter should call the C8SubscriberGetNextMessage() function and specify a maximum amount of time to wait. If a message does not arrive within the specified time, C8SubscriberGetNextMessage() will return control to the caller, which may do some work (or yield the processor) and then continue polling later by calling C8SubscriberGetNextMessage() again. Passing 0 as the wait time returns control immediately, without waiting.
To register a callback function, use the C8SubscriberSetCallback() function.
Below we describe all the functions in the API, including the functions that allow users to attach to streams, read or write streams, and detach from streams. (Acquiring a stream's address is done outside the API, and will be explained later.) The header file c8adapter.h describes the interface.
Remember to call C8ClientSDKInitialize() before calling any functions in an out-of-process adapter.
Parameters:
i_uri: The URI of the stream you want to publish to.
Returns: A pointer to a C8Publisher object (or NULL if error). Publishers returned by this function must be freed with C8PublisherDestroy().
Parameters:
i_uri: The URI of the stream you want to publish to.
i_credentials: A pointer to a structure containing your credentials (username and password).
Returns: A pointer to a C8Publisher object (or NULL if error). Publishers returned by this function must be freed with C8PublisherDestroy().
Parameters:
i_uri: The URI of the stream you want to publish to.
i_credentials: (Optional). A pointer to a structure containing your credentials (user name and password).
i_session_id: The unique session ID for Guaranteed Delivery. If you are reconnecting after a failure, be sure to use the same session ID.
i_timeout: How long to wait to establish a session before timing out.
Returns: A pointer to a C8Publisher object (or NULL if error). Publishers returned by this function must be freed with C8PublisherDestroy().
Parameters:
i_pub: A pointer to the publisher object to be destroyed (de-allocated).
Returns:
Parameters:
i_pub: The publisher.
Returns: C8_TRUE if connected, C8_FALSE otherwise.
Parameters:
i_pub: The publisher for which you want to get the schema.
Returns: A pointer to a schema. The returned schema remains valid while the publisher remains valid. you should not C8Free() the schema; the schema will be de-allocated when the publisher is de-allocated.
Once a message is published, modifying the message is not allowed. However, you may deallocate a message with C8MessageDestroy() at any time. If the publisher is a Guaranteed Publisher, the message is not actually sent to the stream until you call C8PublisherCommit.
Parameters:
i_pub: The publisher for which you want to get the schema.
i_msg: The message that you want to publish.
Returns: C8_OK if successful, C8_FAIL otherwise.
Parameters:
i_pub: The publisher that specifies which stream to publish to.
i_msg: A pointer to an array of messages to be sent.
i_cnt: The number of messages in the array.
Returns: C8_OK if successful, C8_FAIL otherwise.
Parameters:
i_pub: The Guaranteed Delivery publisher that specifies which stream to publish to.
i_batch_id: The ID of this batch. See Implementing Guaranteed Processing for information about Guaranteed Delivery.
Returns: C8_OK if successful, C8_FAIL otherwise.
Parameters:
i_pub: The Guaranteed Delivery publisher that specifies which stream to publish to.
i_msgs: An array of messages
i_cnt: The number of messages in i_msgs
i_batch_id: The unique ID of this batch. See Implementing Guaranteed Processing for information about Guaranteed Delivery.
Returns: C8_OK if successful, C8_FAIL otherwise.
Parameters:
i_pub: The Guaranteed Delivery publisher.
Returns: A constant pointer to the ID of the last batch processed by the server, or NULL if no batch has been processed since the last restart with clean slate.
Parameters:
i_uri: The URI of the stream to subscribe to.
Returns: Pointer to a subscriber object, or NULL if an error occurs. Subscribers should be freed with C8SubscriberDestroy().
Parameters:
i_uri: The URI of the stream to subscribe to.
i_credentials: A pointer to a structure containing your credentials (username and password).
Returns: A pointer to a subscriber object or NULL if an error occurs. Subscribers should be freed with C8SubscriberDestroy().
Parameters:
i_uri: The URI of the stream to subscribe to.
i_credentials: A pointer to a structure containing your credentials (username and password). (Optional.)
i_session_id : The unique session ID for Guaranteed Delivery. If you are reconnecting after a failure, be sure to use the same session ID.
i_last_batch_id: The ID of the last batch processed by this adapter. The server should begin sending messages with the batch following the one specified here.
i_timeout: How long to wait to establish a session before timing out.
See Implementing Guaranteed Processing for information about Guaranteed Delivery.
Returns: A pointer to a subscriber object or NULL if an error occurs. Subscribers should be freed with C8SubscriberDestroy().
Parameters:
i_sub: The subscriber object from which to get the next message.
i_to: Indicates the maximum amount of time (in microseconds) to wait for the next message.
Returns: The next pending message, or NULL if no messages are pending. In case of a timeout, the call to C8ErrorGetCode() returns C8_ERR_TIMEOUT; a different error code is returned if there was an actual error. The message must be deleted with C8MessageDestroy().
Note that whether or not the timeout was reached, this function may return NULL to indicate that there were no messages, so you must always check the return value from this function - do not assume that you will always get a message.
Parameters:
i_sub: The Guaranteed Delivery subscriber object from which to get the next batch of messages.
o_msgs: A pointer to an array to hold the returned messages.
io_cnt: The number of messages that will fit into 0_msgs (input) or the number of messages in o_msgs (output). If the entire batch of messages does not fit in the allocated array, subsequent calls to this method will retrieve the rest of the batch.
o_batch_id: The ID of this batch of messages.
i_to : Indicates the maximum amount of time (in microseconds) to wait for the batch.
Returns: C8_OK if successful, C8_FAIL otherwise. The messages must be deleted with C8MessageDestroy().
Parameters:
i_sub: The Guaranteed Delivery subscriber.
Returns: A constant pointer the ID of the last batch sent.
The callback function will be called by the adapter library code (which is linked into your out-of-process adapter) and therefore will be running in a thread that is running the library code. Thus, the callback function should be as short as possible and require minimum locking. The callback function should not itself process the newly-arrived message. In many cases, the callback function may simply set a flag and then return, leaving other parts of your code to check the flag, retrieve the message, and then process the message when their thread executes.
In some cases the callback routine may be called even if there is no message. When you call C8SubscriberGetNextMessage() (which you should NOT call inside the callback routine itself), be sure to check that C8SubscriberGetNextMessage() returned a valid C8Message pointer, not NULL.
Parameters:
i_sub: The subscription whose stream you want to be notified about.
i_cb : The new callback function for this subscriber.
i_db_prm: The parameter with which to call the callback.
Returns: Nothing.
Parameters:
i_sub: The subscriber that you want to free or de-allocate.
Returns: Nothing.
Parameters:
i_sub: The subscriber.
Returns: C8_TRUE if connected, C8_FALSE otherwise.
Parameters:
i_sub: The subscriber specifies which stream you want to know the schema of.
Returns: The schema of the stream you've subscribed to or NULL if an error occurs. The returned schema remains valid while the subscriber remains valid.
Parameters:
i_uri: The URI to resolve.
Returns: The HTTP URL or NULL if an error occurs. The pointer returned must be freed with C8Free().
Parameters:
i_uri: The URI to resolve.
i_credentials: A pointer to a structure containing your credentials (user name and password).
Parameters:
i_uri: The URI to resolve.
Returns: A pointer to a NULL-terminated array of string pointers, or NULL if an error occurs. The returned array pointer and all of it's contained pointers must be freed with C8Free().
Parameters:
i_uri: The URI to resolve.
i_credentials: A pointer to a structure containing your credentials (user name and password).
Returns: A pointer to a NULL-terminated array of string pointers, or NULL if an error occurs. The returned array pointer and all of it's contained pointers must be freed with C8Free().
Parameters:
i_base_uri: The URI to extend.
i_query_string: The URL-encoded string to append to i_base_uri.
Returns: The URI in the form base_uri?query_string. This returns NULL if an error occurs. The pointer returned must be freed with C8Free().
Parameters:
i_base_uri: The URI to extend.
i_key: The unencoded key.
i_value: The unencoded value.
Returns: The URL-encoded URI in the form base_uri?key=value. This returns NULL if an error occurs. The pointer returned must be freed with C8Free().