package
0.14.0
Repository: https://github.com/absmach/magistrala.git
Documentation: pkg.go.dev

# README

Postgres reader

Postgres reader provides message repository implementation for Postgres.

Configuration

The service is configured using the environment variables presented in the following table. Note that any unset variables will be replaced with their default values.

VariableDescriptionDefault
MG_POSTGRES_READER_LOG_LEVELService log levelinfo
MG_POSTGRES_READER_HTTP_HOSTService HTTP hostlocalhost
MG_POSTGRES_READER_HTTP_PORTService HTTP port9009
MG_POSTGRES_READER_HTTP_SERVER_CERTService HTTP server cert""
MG_POSTGRES_READER_HTTP_SERVER_KEYService HTTP server key""
MG_POSTGRES_HOSTPostgres DB hostlocalhost
MG_POSTGRES_PORTPostgres DB port5432
MG_POSTGRES_USERPostgres usermagistrala
MG_POSTGRES_PASSPostgres passwordmagistrala
MG_POSTGRES_NAMEPostgres database namemessages
MG_POSTGRES_SSL_MODEPostgres SSL modedisabled
MG_POSTGRES_SSL_CERTPostgres SSL certificate path""
MG_POSTGRES_SSL_KEYPostgres SSL key""
MG_POSTGRES_SSL_ROOT_CERTPostgres SSL root certificate path""
MG_THINGS_AUTH_GRPC_URLThings service Auth gRPC URLlocalhost:7000
MG_THINGS_AUTH_GRPC_TIMEOUTThings service Auth gRPC timeout in seconds1s
MG_THINGS_AUTH_GRPC_CLIENT_TLSThings service Auth gRPC TLS mode flagfalse
MG_THINGS_AUTH_GRPC_CA_CERTSThings service Auth gRPC CA certificates""
MG_AUTH_GRPC_URLAuth service gRPC URLlocalhost:7001
MG_AUTH_GRPC_TIMEOUTAuth service gRPC request timeout in seconds1s
MG_AUTH_GRPC_CLIENT_TLSAuth service gRPC TLS mode flagfalse
MG_AUTH_GRPC_CA_CERTSAuth service gRPC CA certificates""
MG_JAEGER_URLJaeger server URLhttp://jaeger:14268/api/traces
MG_SEND_TELEMETRYSend telemetry to magistrala call home servertrue
MG_POSTGRES_READER_INSTANCE_IDPostgres reader instance ID

Deployment

The service itself is distributed as Docker container. Check the postgres-reader service section in docker-compose to see how service is deployed.

To start the service, execute the following shell script:

# download the latest version of the service
git clone https://github.com/absmach/magistrala

cd magistrala

# compile the postgres writer
make postgres-writer

# copy binary to bin
make install

# Set the environment variables and run the service
MG_POSTGRES_READER_LOG_LEVEL=[Service log level] \
MG_POSTGRES_READER_HTTP_HOST=[Service HTTP host] \
MG_POSTGRES_READER_HTTP_PORT=[Service HTTP port] \
MG_POSTGRES_READER_HTTP_SERVER_CERT=[Service HTTPS server certificate path] \
MG_POSTGRES_READER_HTTP_SERVER_KEY=[Service HTTPS server key path] \
MG_POSTGRES_HOST=[Postgres host] \
MG_POSTGRES_PORT=[Postgres port] \
MG_POSTGRES_USER=[Postgres user] \
MG_POSTGRES_PASS=[Postgres password] \
MG_POSTGRES_NAME=[Postgres database name] \
MG_POSTGRES_SSL_MODE=[Postgres SSL mode] \
MG_POSTGRES_SSL_CERT=[Postgres SSL cert] \
MG_POSTGRES_SSL_KEY=[Postgres SSL key] \
MG_POSTGRES_SSL_ROOT_CERT=[Postgres SSL Root cert] \
MG_THINGS_AUTH_GRPC_URL=[Things service Auth GRPC URL] \
MG_THINGS_AUTH_GRPC_TIMEOUT=[Things service Auth gRPC request timeout in seconds] \
MG_THINGS_AUTH_GRPC_CLIENT_TLS=[Things service Auth gRPC TLS mode flag] \
MG_THINGS_AUTH_GRPC_CA_CERTS=[Things service Auth gRPC CA certificates] \
MG_AUTH_GRPC_URL=[Auth service gRPC URL] \
MG_AUTH_GRPC_TIMEOUT=[Auth service gRPC request timeout in seconds] \
MG_AUTH_GRPC_CLIENT_TLS=[Auth service gRPC TLS mode flag] \
MG_AUTH_GRPC_CA_CERTS=[Auth service gRPC CA certificates] \
MG_JAEGER_URL=[Jaeger server URL] \
MG_SEND_TELEMETRY=[Send telemetry to magistrala call home server] \
MG_POSTGRES_READER_INSTANCE_ID=[Postgres reader instance ID] \
$GOBIN/magistrala-postgres-reader

Usage

Starting service will start consuming normalized messages in SenML format.

Comparator Usage Guide:

ComparatorUsageExample
eqReturn values that are equal to the queryeq["active"] -> "active"
geReturn values that are substrings of the queryge["tiv"] -> "active" and "tiv"
gtReturn values that are substrings of the query and not equal to the querygt["tiv"] -> "active"
leReturn values that are superstrings of the queryle["active"] -> "tiv"
ltReturn values that are superstrings of the query and not equal to the querylt["active"] -> "active" and "tiv"

Official docs can be found here.

# Functions

Connect creates a connection to the PostgreSQL instance and applies any unapplied database migrations.
New returns new PostgreSQL writer.

# Structs

Config defines the options that are used when connecting to a PostgreSQL instance.