DBReader Module
Database Reader Module
Database Reader module can be used in any application hosted in the ProconTEL 4 environment which is using components pipeline builder. DB Reader allows the application to read information from the database and produce data for the pipeline. Currently, DB Reader works only in polling mode.
Table of Contents
Definition
Namespace: ProconTel.Components.Communication.DBReader
Assembly: ProconTel.Components.Communication.DBReader.dll
Module Installation
To install a DBReader module into project, Nuget Package Manager Console can be used:
Install-Package ProconTel.Components.Communication.DBReader -ProjectName <ProjectName>
Nuget package can be found in the repository: https://nexus.macrix.eu/repository/pct2022/
Available Pipeline extensions and configuration methods
The module provides one extensions method that allows inject DBReader module support to application.
public static TcpConnectionSyntax AddDatabaseReader(new DbReaderConfiguration()
{
ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SID=XE)));User Id=<USER>;Password=<PASSWORD>>;",
Provider = DbProvider.Oracle,
RetryPolicy = new RetryPolicyConfiguration() { MaxDelayInSeconds = 30, RetryCount = 10 }
});
ConnectionString is used to define details about the database connection.
DbProvider allows you to specify which database the DbReader should connect to. The following databases are currently supported:
| Database | Active |
|---|---|
| Oracle | [x] |
| MSSQl | [x] |
| PostgreSQL | [x] |
| MySQL | [] |
AddDatabaseReader contains a number of optional parameters that can be passed when needed:
| ParameterName | Default | Description |
|---|---|---|
| ReaderName | Reader | The name of the current module, necessary when more than one reader reads data from the database. |
| TelegramTableName | TCP_TEL_HIST | The name of the Table from which messages should be read. |
| ReadTelegramTableName | TCP_TEL_HIST_READ_ROWS | The name of the table in which the reader saves the telegrams it has already read. |
| DataColumn | DATA | The name of the column that contains the data. |
| PollingActivated | true | Flag whether polling is active. |
| PollingInterval | 15000 | Polling reread time. |
| PollingComparisonDateColumn | Modif_Last | Column name that is compared when reading telegrams in polling mode. |
| ReaderIdColumn | READER_ID | The name of the column where the name of the reader is stored. |
| TelegramTableIdColumn | ID_SEQ | The name of the column where the telegram ID is stored in Telegram Table. |
| ReadTelegramTableIdColumn | ROW_ID | The name of the column where the telegram ID is stored in Read Telegram Table. |
Example of usage in code
This example shows use of the DBReader module in conjunction with Oracle Database. Module opens a connection to the database and reads new messages from Telegram Table. After the message is processed correctly, Reader updates the data in the Read Telegram Table to avoid duplication.
Read messages are sent to the pipeline.
flow.AddDatabaseReader(new DbReaderConfiguration()
{
ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SID=XE)));User Id=<USER>;Password=<PASSWORD>>;",
Provider = DbProvider.Oracle,
RetryPolicy = new RetryPolicyConfiguration() { MaxDelayInSeconds = 30, RetryCount = 10 }
})
.MapXmlToBinary().UseXsbtRules(opts => opts.XsbtFolderPath = builder.Configuration["Xsbt:XsbtsFolderPath"])
.StartTcpServer(55401).UseXsbtHeaderDefinition(opts => {
opts.XsbtHeaderDefinitionPath = builder.Configuration["Xsbt:HeaderDefinitionPath"];
opts.LenghtFieldName = builder.Configuration["Xsbt:HeaderLenghtFieldName"];
opts.IdFieldName = builder.Configuration["Xsbt:HeaderIdFieldName"];
}).AsCustomerOnly();