Introduction to the Qorus Client Library
The Qorus Client Library is designed to facilitate communication with Qorus servers and the manipulation of Qorus data without the use of the server. In addition, services are provided to parse the options and to acquire Datasources based on named datasource in the system database as well as other connections and integration objects.
For the Python-based remote client, allowing users to work with remote Qorus instances over HTTP and WebSocket connections, which can be installed on any platform supporting a recent version of Python 3; see https://github.com/qoretechnologies/qorus-remote.
The Python client can be installed from pip
with:
pip install qorus-remote
Note that this documentation documents the Qorus client library delivered with the Qorus server. The Qorus client library is written in Qore and requires read access to the server configuration files (System Options File, as well as to the network encryption key file and the sensitive data key file, etc).
All Qorus client scripts depend on the client library, such as the following:
- See also
-
Using the Qorus Client from Python
Python integration with Qore is implemented using the qoreloader module, which is the Python module provided in Qore's python module, providing tight integration with both languages, including bi-directional dynamic and transparent imports of code and data between Python and Qore as well as Python and Java with the assistance of the jni module.
The Python qoreloader module is located in $OMQ_DIR/python
; this directory must appear in the PYTHONPATH
environment variable to be imported by Python.
Python examples in this guide assume that the qoreloader module is available from the PYTHONPATH
environment variable.
- PYTHONPATH Unix / Linux Example
export PYTHONPATH=$OMQ_DIR/python/qoreloader.so
The qoreloader module will initialize the Qore library when imported and will generate Python classes dynamically from Qore and Java classes with supported import
statements; additionally, the qoreloader module will convert data automatically to and from Qore and Java at runtime when Python code calls Qore or Java code and vice-versa.
- Python Example:
import qoreloader
import qore.QorusClientBase
from qore.__root__.OMQ.UserApi import UserApi
print('Qorus session ID: {}'.format(UserApi.getSessionId()))
- See also
-
Using the Qorus Client from Java
Java integration with Qore is implemented through the qore-jni.jar
JAR file, which provides a Java compiler based on the standard javax.tools
package in the java.compiler
module, as well as a a class loader, both supporting dynamic bytecode generation of wrapper classes for Qore and Python declarations and symbols on demand during complation and at runtime.
The qore-jni.jar
JAR file will automatically initialize Qore's jni module as well as Qore's python module as needed to introspect Qore and Python definitions, generate Java bytecode dynamically, and import the generated bytecode directly into the requesting Java program.
This allows Java programs to use the full Qorus API set as well as dynamically import Python APIs and modules into Java and use them as if they were Java APIs.
Qorus provides qjavac
as a front end to the Qore Java compiler for convenience; qjavac
takes the same arguments as the standard javac
compiler.
To compile Java code using dynamic imports, make sure and include $OMQ_DIR/jar/qore-jni
.jar in the classpath.
- Java Compilation Example
qjavac -cp ${OMQ_DIR}/jar/qore-jni.jar MyClass.java
To run Java code that uses dynamic imports, you need to use the same classpath as above, plus Qore's org.qore.jni.QoreURLClassLoader as the system class loader.
- Java Execution Example
java -cp ${OMQ_DIR}/jar/qore-jni.jar:. -Djava.system.class.loader=org.qore.jni.QoreURLClassLoader MyClass
- See also
-
Initializing the Qorus Client Library
Use the QorusClientBase
module to ensure that a minimum set of Qorus client APIs are available to your script or program.
The first step in using the client library is to initialize it with a call to OMQ::QorusClient::initFast() (or OMQ::QorusClient::init() or OMQ::QorusClient::init2()):
- Python Example:
import qoreloader
from qore.QorusClientBase import QorusClient
QorusClient.initFast()
- Java Example:
import qoremod.QorusClientBase.*;
class MyClass {
static {
try {
QorusClient.initFast();
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
public static void main(String[] args) throws Throwable {
}
}
- Qore Example
%requires QorusClientBase
%new-style
%require-our
%require-types
%enable-all-warnings
%exec-class client
class client {
constructor() {
QorusClient::initFast();
}
}
Using Datasources
Database driver modules will be loaded on-demand when Datasource or DatasourcePool objects are acquired; if you want to use other definitions provided by the database modules, then load them explicitly with a %requires
directive, as follows:
Use the UserApi::getDatasourceDedicated() method (or UserApi::getDatasourcePool()) to acquire Datasource and DatasourcePool objects.
- Python Example:
import qoreloader
from qore.QorusClientBase import QorusClient
from qore.__root__.OMQ.UserApi import UserApi
from qore.__root__.Qore.SQL import Datasource, DatasourcePool
QorusClient.initFast()
ds: Datasource = UserApi.getDatasourceDedicated('omquser')
dsp: DatasourcePool = UserApi.getDatasourcePool('omquser')
- Java Example:
import qoremod.QorusClientBase.*;
import qoremod.QorusClientBase.OMQ.UserApi.UserApi;
import qore.Qore.SQL.Datasource;
import qore.Qore.SQL.DatasourcePool;
class MyClass {
static {
try {
QorusClient.initFast();
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
public static void main(String[] args) throws Throwable {
Datasource ds = UserApi.getDatasourceDedicated("omquser");
DatasourcePool dsp = UserApi.getDatasourcePool("omquser");
}
}
- Qore Example
%requires QorusClientBase
%new-style
%require-our
%require-types
%enable-all-warnings
QorusClient::initFast();
Datasource ds = UserApi::getDatasourceDedicated("omquser");
DatasourcePool dsp = UserApi::getDatasourcePool("omquser");
Using SQL Tables
Use the UserApi::getSqlTable() method to acquire AbstractTable objects.
- Python Example:
import qoreloader
from qore.QorusClientBase import QorusClient
from qore.__root__.OMQ.UserApi import UserApi
from qore.SqlUtil.SqlUtil import AbstractTable
QorusClient.initFast()
gl_import: AbstractTable = UserApi.getSqlTable('erp1', 'gl_import')
- Java Example:
import qoremod.QorusClientBase.*;
import qoremod.QorusClientBase.OMQ.UserApi.UserApi;
import qoremod.SqlUtil.SqlUtil.AbstractTable;
class MyClass {
static {
try {
QorusClient.initFast();
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
public static void main(String[] args) throws Throwable {
AbstractTable erp1 = UserApi.getSqlTable("erp1", "gl_import");
}
}
- Qore Example
%requires QorusClientBase
%new-style
%require-our
%require-types
%enable-all-warnings
QorusClient::initFast();
SqlUtil::AbstractTable gl_import = UserApi::getSqlTable("erp1", "gl_import");
Using Data Providers
Use the UserApi::getDataProvider() method to acquire AbstractDataProvider objects.
- Python Example:
import qoreloader
from qore.QorusClientBase import QorusClient
from qore.__root__.OMQ.UserApi import UserApi
from qore.DataProvider.DataProvider import AbstractDataProvider
provider: AbstractDataProvider = UserApi.getDataProvider("connection/rest-billing-1/rest-billing-demo/accounts/POST")
- Java Example:
import qoremod.QorusClientBase.*;
import qoremod.QorusClientBase.OMQ.UserApi.UserApi;
import qoremod.DataProvider.DataProvider.AbstractDataProvider;
class MyClass {
public static void main(String[] args) throws Throwable {
AbstractDataProvider provider =
UserApi.getDataProvider("connection/rest-billing-1/rest-billing-demo/accounts/POST");
}
}
- Qore Example
%requires QorusClientBase
%new-style
%require-our
%require-types
%enable-all-warnings
DataProvider::AbstractDataProvider provider =
UserApi::getDataProvider("connection/rest-billing-1/rest-billing-demo/accounts/POST");
Communicating with Qorus Servers
Communicating with Qorus Servers with the REST API
Communication with the Qorus server using the REST API is performed through the global variable qrest (see OMQ::QorusSystemRestHelperBase for the API reference for this object), available in Qore. In Python and Java, this object should be declared and initialized explicitly as in the following examples.
This object can then be used to make REST or DataStream calls to the Qorus server's REST API as in the following example:
- Python Example:
import qoreloader
from qore.QorusClientBase import QorusClient
from qore.__root__.OMQ.Client import QorusSystemRestHelper
QorusClient.initFast()
qrest: QorusSystemRestHelper = QorusSystemRestHelper()
info: dict = qrest.get("system")
print('Qorus {} {} sessiond {}.format(info['omq-version'], info['instance-key'], info['session-id']))
- Java Example:
import qoremod.QorusClientBase.*;
import qoremod.QorusClientBase.OMQ.Client.QorusSystemRestHelper;
class MyClass {
public static QorusSystemRestHelper qrest;
static {
try {
QorusClient.initFast();
qrest = new QorusSystemRestHelper();
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
public static void main(String[] args) throws Throwable {
System.out.printf("Qorus %s %s sessiond %s\n", info.getString("omq-version"), info.getString("instance-key"),
info.getString("session-id"));
}
}
auto get(*hash< auto > opt, string path, auto args, *hash< auto > hdr, *reference< hash< auto > > info)
issues an HTTP GET REST request against the server and returns the deserialized response
public OMQ::Client::QorusSystemRestHelper qrest
global object for accessing the Qorus REST API; initialized in QorusClient::initFast()
- Qore Example
# Qorus client base module
%requires QorusClientBase
%new-style
%require-our
%require-types
%enable-all-warnings
%exec-class client
class client {
constructor() {
QorusClient::initFast();
hash<auto> info = qrest.get("system");
printf("Qorus %s %s sessiond %s\n", info."omq-version", info."instance-key", info."session-id");
}
}
To get a REST or DataStream connection to a remote server, the API in the following example can be used.
- Python Example:
import qoreloader
from qore.QorusClientBase import QorusClient
from qore.__root__.OMQ.Client import QorusSystemRestHelper
QorusClient.initFast()
qrest: QorusSystemRestHelper = QorusSystemRestHelper('nodea')
info: dict = qrest.get("system")
print('Qorus {} {} sessiond {}.format(info['omq-version'], info['instance-key'], info['session-id']))
- Java Example:
import qoremod.QorusClientBase.*;
import qoremod.QorusClientBase.OMQ.Client.QorusSystemRestHelper;
class MyClass {
public static QorusSystemRestHelper qrest;
static {
try {
QorusClient.initFast();
qrest = new QorusSystemRestHelper("nodea");
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
public static void main(String[] args) throws Throwable {
System.out.printf("Qorus %s %s sessiond %s\n", info.getString("omq-version"), info.getString("instance-key"),
info.getString("session-id"));
}
}
- Qore Example
# Qorus client base module
%requires QorusClientBase
%new-style
%require-our
%require-types
%enable-all-warnings
QorusClient::initFast();
OMQ::Client::QorusSystemRestHelper rest = UserApi::getRemoteRestConnection("nodea");
printf("Qorus %s %s sessiond %s\n", info."omq-version", info."instance-key", info."session-id");
Calling Service Methods from Qore
From Qore, use the omqservice variable to easily call service methods. Internally, this object uses the global omqapi variable to perform the communication with the server.
For example (assuming the client library has been initialized as in the previous examples):
*hash<auto> rh = omqservice.system.info.searchReleases({"name": "qorus-user-rel1"});
The above example will return a hash of information about the "qorus-user-rel1"
release, if it exists/
- See also
- Communicating with Qorus Servers with the REST API to get a REST connection to a remote server.
Note that the Qorus client programs are delivered in source form and can be used as examples of how to communicate with the server; see the source for:
The above programs show how to use the client API with command-line processing, error handling, etc.
UNIX Socket Support in URLs
URLs with UNIX sockets are generally supported in Qore with the following syntax:
scheme://socket=
<url_encoded_path>/path
<url_encoded_path> is a path with URL-encoding as performed by encode_url(); for example, given the following URL:
"http://socket=%2ftmp%2fqorus-sock-qorus-instance-1/api/latest/system/starttime"
This URL allows a filesystem path to be used in the host portion of the URL and for the URL to include a URL path as well.
Using User Connections in the Qorus Client Library
User connections are user-defined connections to external sytems or facilities that are delivered as a part of Qorus releases.
Qorus client programs can use the UserApi::getUserConnection() method to access connections defined in the Qorus system schema (Note that this method works equally in server and client code).
For example, the following code will retrieve user connection object named "my_connection"
:
- Python Example:
import qoreloader
from qore.QorusClientBase import QorusClient
from qore.__root__.OMQ.UserApi import UserApi
obj = UserApi.getUserConnection("my_connection")
- Java Example:
import qoremod.QorusClientBase.*;
import qoremod.QorusClientBase.OMQ.UserApi.UserApi;
class MyClass {
public static void main(String[] args) throws Throwable {
Object o = UserApi.getUserConnection("my_connection");
}
}
- Qore Example
%new-style
%require-types
%strict-args
%requires QorusClientBase
object o = UserApi::getUserConnection("my_connection");
- Note
- The class of the object returned by the UserApi::getUserConnection() method depends on the connection type.