|
REQUIREMENT client.c.queue |
| Type | NEW |
| Priority | MEDIUM |
| Status | CLOSED |
| Topic | XmlBlaster provides a persistent queue implementation for ANSI C | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Des cription |
We use the relational database SQLite3 for our queue implementation. Persistent Queue Features
C-API
The programming interface from C is struct I_QueueStruct declared in the file
Here is a usage code sample:
ExceptionStruct exception;
QueueEntryArr *entries = 0;
QueueProperties queueProperties;
I_Queue *queueP = 0;
const char *dbName = "xmlBlasterClient-C.db"
const *dummy = "something";
...
/* Configure the queue */
memset(&queueProperties, 0, sizeof QueueProperties);
strncpy(queueProperties.dbName, dbName, QUEUE_DBNAME_MAX);
strncpy(queueProperties.queueName = "connection_clientJoe", QUEUE_ID_MAX);
strncpy(queueProperties.tablePrefix="XB_", QUEUE_PREFIX_MAX);
queueProperties.maxNumOfEntries = 10000000L;
queueProperties.maxNumOfBytes = 1000000000LL;
queueProperties.logFp = loggingFp;
queueProperties.logLevel = XMLBLASTER_LOG_TRACE;
queueProperties.userObject = (void *)dummy;
/* Create the queue */
queueP = createQueue(&queueProperties, &exception);
/* Create an entry */
QueueEntry queueEntry;
memset(&queueEntry, 0, sizeof (QueueEntry));
queueEntry.priority = 5;
queueEntry.isPersistent = true;
queueEntry.uniqueId = 1081492136826000000ll;
strncpy(queueEntry.embeddedType = "MSG_RAW|publish", QUEUE_ENTRY_EMBEDDEDTYPE_LEN);
queueEntry.embeddedType[QUEUE_ENTRY_EMBEDDEDTYPE_LEN-1] = 0;
queueEntry.embeddedBlob.data = (char *)"some blob";
queueEntry.embeddedBlob.dataLen = strlen(queueEntry.embeddedBlob.data);
/* Fill the queue */
queueP->put(queueP, &queueEntry, &exception);
/* Access the entry */
entries = queueP->peekWithSamePriority(queueP, -1, -1, &exception);
/* close the queue */
queueP->shutdown(&queueP, &exception);
For a more complete usage example please see the test cases in
Setup
To use the persistent queue you need to download SQLite3 and compile it for
your platform, our C compilation needs Compilation with ant
First add those lines to your
# UNIX example:
XMLBLASTER_PERSISTENT_QUEUE_SQLITE3=1
sqlite.include.dir=/opt/sqlite3-bin/include
sqlite.lib.dir=/opt/sqlite3-bin/lib
This expects NOTE: For Windows you can download the ready compiled sqlite library (see http://sqlite.org/download.html). Creation of an import library from the zip file for MS Visual C++ is achieved by the following command:
LIB /DEF:sqlite3.def
This creates the files sqlite3.lib and sqlite3.exp files. The sqlite3.lib can then be used to link your programs against the SQLite3 DLL.
# Windows example:
XMLBLASTER_PERSISTENT_QUEUE_SQLITE3=1
sqlite.include.dir=C:/sqlite3
sqlite.lib.dir=C:/sqlite3
and compile it:
build c-delete c
or similiar (with verbose switched on):
build -verbose -DXMLBLASTER_PERSISTENT_QUEUE_SQLITE3=1 -Dsqlite.include.dir= ... c
Compilation manually Here are some complete examples how to compile a simple C client 'manually':
cd xmlBlaster/src/c/util/queue
Linux C:
export LD_LIBRARY_PATH=/opt/sqlite3-bin/lib
gcc -g -Wall -DQUEUE_MAIN=1 -I../../ -o SQLite3Queue SQLite3Queue.c
../helper.c -I/opt/sqlite3-bin/include -L/opt/sqlite3-bin/lib -lsqlite3
Linux C++:
Mac OSX:
export DYLD_LIBRARY_PATH=/opt/sqlite3-bin/lib
Windows:
Solaris:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Example C |
C usage examples
See the test file
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Example any |
sqlite3 command line example From time to time you may want to look into the C client queue, here are some command line examples:
sqlite xmlBlasterClientCpp.db
sqlite> .schema XB_ENTRIES
CREATE TABLE XB_ENTRIES (dataId bigint , queueName text , prio integer, flag text,
durable char(1), byteSize bigint, blob bytea, PRIMARY KEY (dataId, queueName));
CREATE INDEX XB_ENTRIES_IDX ON XB_ENTRIES (prio);
sqlite> .mode lines
sqlite> select * from xb_entries;
dataId = 1097512282290000000
queueName = connection_clientPublisher1
prio = 5
flag = MSG_RAW|publish
durable = T
byteSize = 302
blob = ? ?;pnr= ??;rs`sd?hcNJ.= ...
sqlite> select dataId, queueName, prio, flag, durable, byteSize from xb_entries;
dataId = 1097512282290000000
queueName = connection_clientPublisher1
prio = 5
flag = MSG_RAW|publish
durable = T
byteSize = 302
dataId = 1097512331701000000
queueName = connection_clientPublisher1
prio = 5
flag = MSG_RAW|publish
durable = T
byteSize = 257
sqlite> .quit
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Configure |
These configurations are tested:
These parameters allow to configure the C-client on command line or over the environment (with lower priority):
TestingThe testsuite resides in xmlBlaster/testsuite/src/c to compile it use ant:
cd xmlBlaster
build -DXMLBLASTER_PERSISTENT_QUEUE_SQLITE3=1 c-test
To run the tests invoke
TestQueue
NOTE: Configuration parameters are specified on command line (-someValue 17) or in the
xmlBlaster.properties file (someValue=17). See requirement "util.property" for details. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Todo |
The persistent queue implementation is finished and tested, but we need to:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| See CODE | util/queue/QueueInterface.h | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| See | TestQueue.c | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| See | http://www.sqlite.org/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| See | SQLite performance | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| See | SQLite compile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| See REQ | Queue dump formating identical to SOCKET serialization | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| See REQ | client.cpp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| See REQ | client.cpp.queue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| See TEST | TestQueue |
This page is generated from the requirement XML file xmlBlaster/doc/requirements/client.c.queue.xml